#K58737. Minimum Operations to Equalize a Sequence

    ID: 30709 Type: Default 1000ms 256MiB

Minimum Operations to Equalize a Sequence

Minimum Operations to Equalize a Sequence

You are given a sequence of N integers. In one operation, you can change the integer value of any element to any other integer. Your task is to determine the minimum number of operations needed to make all elements of the sequence equal.

The key observation is that if you choose to change all the numbers to the most frequently occurring value, the number of required operations will be minimized. Formally, let \(N\) be the total number of elements in the sequence and let \(f(x)\) denote the frequency of an integer \(x\). Then the answer is:

[ \text{operations} = N - \max_{x} f(x) ]

You need to read the input from standard input (stdin) and write the answer to standard output (stdout).

inputFormat

The first line contains a single integer N (the number of elements in the sequence). The second line contains N space-separated integers representing the sequence.

outputFormat

Print a single integer representing the minimum number of operations required to make all the elements in the sequence equal.

## sample
5
3 3 1 1 1
2