solve :: String -> String
solve = show . solve' . map read . tail . words

solve' :: [Int] -> Int 
solve' xs = 3 ^ n - f xs
    where
        n = length xs

f :: [Int] -> Int 
f [] = 1 
f (x:xs)
    | odd x = f xs
    | even x = 2 * f xs

main :: IO ()
main = interact solve