import Control.Monad (replicateM)

main = do
    n <- readLn
    if n == 0 then return () else do
        xs <- replicateM n (readLn) :: IO [Int]
        print $ solve xs
        main

solve :: [Int] -> Int
solve (x:xs) = solve' xs 0 [(x,1)]
    where
    -- end
    solve' [] _ ps = sum $ map snd $ filter ((==0) . fst) $ ps
    -- even turn
    solve' (x:xs) 0 ((y,n):[]) 
        | x == y = solve' xs 1 ((x,n+1):[])
        | x /= y = solve' xs 1 ((x,n+1):[])
    solve' (x:xs) 0 ((y,n):(z,m):ps) 
        | x == y = solve' xs 1 ((x,n+1):(z,m):ps)
        | x /= y = solve' xs 1 ((x,m+n+1):ps)
    -- odd turn
    solve' (x:xs) 1 ((y,n):ps) 
        | x == y = solve' xs 0 ((x,n+1):ps)
        | x /= y = solve' xs 0 ((x,1):(y,n):ps)