import Data.List (nub)

type Forest = [Int]
initForest = [17, 55, 6] -- goats, wolves, lions

-- functions
result :: [Forest] -> Int
result aa = let aa2 = carnage aa in
            if aa == aa2 -- no more killing possibles
              then maximum $ map sum aa2
              else result $ carnage aa2

carnage :: [Forest] -> [Forest]
carnage aa = let wodup = nub aa in -- if I omit this line
                                   -- things become very , /very/,
                                   -- *very* slow
             wodup >>= kills -- same as: concatMap kills wodup

-- all possible kills
kills :: Forest -> [Forest]
kills a | canKill a == False = [a]
        | otherwise          =
            filter soulCheck
              [lionEatsWolf a, lionEatsGoat a, wolfEatsGoat a]
    where soulCheck :: Forest -> Bool
          soulCheck a | all (>= 0) a = True
                      | otherwise    = False
          canKill :: Forest -> Bool
          canKill a | length (filter (> 0) a) >= 2 = True
                    | otherwise                    = False

lionEatsWolf (g:w:l:[]) = [g+1, w-1, l-1]
lionEatsGoat (g:w:l:[]) = [g-1, w+1, l-1]
wolfEatsGoat (g:w:l:[]) = [g-1, w-1, l+1]

main = print $ result [initForest]