import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad

main :: IO ()
main = readLn >>= main'
    where
        main' n = breads >>= print . solve n

solve :: Int -> [Int] -> Int
solve n xs = 3 ^ n - foldl' ff 1 xs
    where
        ff acc x
            | odd x = acc
            | otherwise = acc * 2



breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)
