import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Data.Array
main = do
[n] <- bsGetLnInts
as <- bsGetLnInts
s <- BS.getLine
let ans = abc308e n as s
print ans
bsGetLnInts :: IO [Int]
bsGetLnInts = BS.getLine >>= return . unfoldr (BS.readInt . BS.dropWhile isSpace)
abc308e :: Int -> [Int] -> BS.ByteString -> Int
abc308e n as s = sum ps
where
(_,ps) = mapAccumL step ([0,0,0],x012) $ zip as $ BS.unpack s
x012 = elems $ accumArray (+) 0 (0,2)
[(ai, 1) | (ai, 'X') <- zip as $ BS.unpack s]
step (m012,x012) (ai,'M') = ((triple ai succ m012, x012), 0)
step (m012,x012) (ak,'X') = ((m012, triple ak pred x012), 0)
step tt@(m012,x012) (aj,'E') = (tt, p)
where
p = sum [ ci * ck * pa ! (ai,aj,ak)
| (ci,ai) <- zip m012 [0..]
, (ck,ak) <- zip x012 [0..]
]
-- point array
pa = listArray ((0,0,0),(2,2,2))
[head $ [x | x <- [0..2], x /= ai, x /= aj, x /= ak] ++ [3]
| ai <- [0..2], aj <- [0..2], ak <- [0..2]]
triple 0 f [a,b,c] = [f a, b, c]
triple 1 f [a,b,c] = [a, f b, c]
triple 2 f [a,b,c] = [a, b, f c]