import Data.List (sortBy,group)
import Control.Arrow ((&&&))

main :: IO ()
main = do
  _ <- read <$> getLine :: IO Int
  as <- map (fromIntegral.length&&&head).group.sortBy (flip compare).map read.words <$> getLine :: IO [(Integer,Integer)]
  let ls = filter ((>1).fst) as
  if length ls > 1
    then
      if (fst.head) ls > 4
        then print ((snd.head) ls*(snd.head) ls)
        else print ((snd.head) ls*(snd.head.tail) ls)
    else print 0
