import Data.List
import Data.Ord

main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  let m = map (\g -> (head g, length g)) $ group $ sortBy (comparing Down) as --reverse $ sort as
  print $ solve m 0

solve :: [(Int,Int)] -> Int -> Int
solve [] _ = 0
solve ((v,i):xs) n
  | i >= 4 = v*2
  | i >= 2 && n /= 0 = v*n
  | i >= 2 = solve xs v
  | otherwise = solve xs v