#K3486. Minimum Moves to Form Towers

    ID: 25403 Type: Default 1000ms 256MiB

Minimum Moves to Form Towers

Minimum Moves to Form Towers

You are given n blocks, where each block has an integer height. Your task is to determine the minimum number of moves required to rearrange the blocks into towers so that all towers have the same height.

In one move, you can take a block and move it to another tower. The optimal strategy is to choose the height which appears most frequently and change the blocks with different heights.

Formally, if the frequency of the most common height is \( f_{max} \), then the answer is \( n - f_{max} \).

Example:
For n = 4 and heights = [1, 2, 3, 3], the most frequent height is 3 (appearing twice), so the minimum number of moves required is 4 - 2 = 2.

inputFormat

The first line contains an integer n denoting the number of blocks.
The second line contains n space-separated integers representing the heights of the blocks.

outputFormat

Output a single integer which is the minimum number of moves required to rearrange the blocks into towers of equal height.

## sample
4
1 2 3 3
2