import Data.List
f _ _ _ [] _ = 0
f x y (a:as) bs@(b:_) cs | a < b = f (x+1) y as bs cs
f x y as bs@(b:_) (c:cs) | c <= b = f x (y-1) as bs cs
f x y as (b:bs) cs = x * y + f x y as bs cs
main = do
  n <- readLn :: IO Int
  let s = sort . map read . words <$> getLine :: IO [Integer]
  print =<< f 0 n <$> s <*> s <*> s