import Data.List
import qualified Data.IntMap.Lazy as IM
 
main = do
  getLine
  as <- map read . words <$> getLine
  print . h . sortBy (flip compare) $ f IM.empty as
 
f im [] = j $ IM.toList im
f im (y:ys) = f (IM.insertWith (const succ) y 1 im) ys
 
h (x:y:_) = x * y
h _ = 0
 
j [] = []
j ((k, v):xs)
  | v >= 4 = [k, k] ++ j xs
  | v >= 2 = k : j xs
  | otherwise = j xs