#K13366. Minimum Difference of Problem Counts Among Difficulty Levels

    ID: 23897 Type: Default 1000ms 256MiB

Minimum Difference of Problem Counts Among Difficulty Levels

Minimum Difference of Problem Counts Among Difficulty Levels

You are given a set of problems each with a primary difficulty level and an associated score. Although the scores are provided, they are not used in the computation. Your task is to compute the minimum possible value of the maximum difference between the number of problems in any two distinct primary difficulty levels.

Formally, let there be n problems, an array d of n integers representing the difficulty level for each problem, and an array s of n integers representing the score of each problem (s is ignored in the calculation). For each distinct difficulty value in d, count how many times it occurs. If there is only one unique difficulty level, the answer is 0. Otherwise, let min be the minimum frequency and max be the maximum frequency among the distinct difficulty levels. The answer is given by:

[ answer = max - min, ]

Write a program that reads the input from standard input and writes the output to standard output.

inputFormat

The first line contains an integer n (1 ≤ n ≤ 105) — the number of problems.

The second line contains n space-separated integers representing the array d (the difficulty levels).

The third line contains n space-separated integers representing the array s (the scores, which should be ignored in calculations).

outputFormat

Output a single integer — the minimum possible value of the difference between the maximum and minimum number of problems over all distinct difficulty levels. If there is only one distinct difficulty level, output 0.

## sample
5
1 2 2 3 3
5 5 4 6 7
1