using System;
using System.Linq;
using System.Collections.Generic;
class Solution {
  public static void Main(string[] args) {
            string[] data = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(data[0]);
            data = Console.ReadLine().Split(' ');
            int[] spheres = data.ToList().ConvertAll(x => Convert.ToInt32(x)).ToArray();
            List<int> spheresByDistance = new List<int>(spheres);
            spheresByDistance.Sort();
            //solution
            int length = spheresByDistance[spheresByDistance.Count - 1]; //length - number of boxes
            int[] numberOfSpheresInEachBox = new int[length];
            foreach(int distance in spheresByDistance)
            {
                numberOfSpheresInEachBox[distance - 1]++;
            }
            long currentLength = length;
            long result = 0;
            //everything before is fine
            int i = 1;
            while (currentLength > 0)
            {
                result += currentLength * numberOfSpheresInEachBox[numberOfSpheresInEachBox.Length - i];
                currentLength -= numberOfSpheresInEachBox[numberOfSpheresInEachBox.Length - i];
                i++;
                currentLength--;
            }
            Console.WriteLine(result);
  }
}
