import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] b = new int[n];

    Map<Integer, Integer> freq = new HashMap<>();

    for (int i = 0; i < n; i++) {
        b[i] = sc.nextInt();
        freq.put(b[i], freq.getOrDefault(b[i], 0) + 1);
    }

    List<Integer> heights = new ArrayList<>(freq.keySet());
    heights.sort(Collections.reverseOrder());

    long step = 0;
    int cumulativeFreq = 0;

    for (int i = 0; i < heights.size() - 1; i++) {
        cumulativeFreq += freq.get(heights.get(i));
        step += cumulativeFreq;
    }

    System.out.println(step);
}

}