import Prelude hiding (lookup) import Data.Map hiding (map,partition) import Data.Maybe (fromJust) type Table = Map (Int,Int) Bool main = do n <- read <$> getLine ws <- map read . words <$> getLine let sumOfWs = sum ws putStrLn $ if even sumOfWs && snd (partition empty (n,div sumOfWs 2) ws) then "possible" else "impossible" partition :: Table -> (Int,Int) -> [Int] -> (Table,Bool) partition table (n,m) [] | m == 0 = (table,True) | otherwise = (table,False) partition table (n,m) (w:ws) | m < 0 = (table,False) | m == 0 = (table,True) | otherwise = case lookup (n,m) table of Just b -> (table,b) Nothing -> (insert (n,m) result table2,result) where (table1,r1) = partition table (n-1,m) ws (table2,r2) = partition table1 (n-1,m-w) ws result = r1 || r2