#C7026. Minimum Operations to Equalize Array Elements

    ID: 50852 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Array Elements

Minimum Operations to Equalize Array Elements

You are given an array of n integers. In one operation, you can change any element of the array to any other integer. Your task is to determine the minimum number of operations required to make all the array elements equal.

The idea is simple: identify the element which occurs most frequently (the mode), and then change every other element to this value. Thus, the minimum number of operations required is:

\( n - \max(frequency) \)

where \( \max(frequency) \) is the maximum frequency among all elements in the array.

inputFormat

The input is provided via stdin in the following format:

  1. The first line contains a single integer \( n \) representing the number of elements in the array.
  2. The second line contains \( n \) space-separated integers representing the elements of the array.

outputFormat

Output a single integer to stdout: the minimum number of operations required to make all elements in the array equal.

## sample
3
2 2 2
0