import Control.Monad
import Control.Applicative
import Data.List

taka :: [Int] -> Int
taka xs = sum $ map (\x -> ponya (permutation $ [1..(length xs)]) x 1)  (p5 ( length xs ) xs (kuwa xs 1)) 

ponya :: [[Int]] -> [Int] -> Int -> Int
ponya (x:xs) y n
    | x == y = n
    | x /= y = ponya xs y (n+1)

p5 :: Int -> [Int] -> [Int] -> [[Int]]
p5 _ [] _ = [[]]
p5 n (x:xs) ys
    | x == 0 = do
        x <- ys
        map (x:) (p5 n xs ( delete x ys ))
    | x /= 0 = do
        map (x:) (p5 n xs ys)

kuwa :: [Int] -> Int -> [Int]
kuwa [] _ = []
kuwa (x:xs) n
    | x == 0 = (n:) (kuwa xs (n+1))
    | x /= 0 = kuwa xs (n+1)

permutation :: Eq a => [a] -> [[a]]
permutation [] = [[]]
permutation xs = do
    x <- xs
    map (x:) (permutation $ delete x xs)

main = do
    n' <- getLine
    p' <- getLine
    print $ taka $ map (\x -> (read x :: Int)) (words p')