#d2925. 频率相同的最长子序列

频率相同的最长子序列

Longest Subsequence with Equal Frequencies

Problem Description

You are given an array AA of length nn. Choose a subsequence of AA such that every element that appears in the subsequence appears the same number of times. Find the length of the longest such subsequence.

Input Format

The input consists of two lines. The first line contains an integer nn, the size of the array.

The next line contains nn space-separated integers A1,A2,…,AnA_1, A_2, \dots, A_n.

Output Format

Output a single integer, the answer.

Sample Input 1

6
1 3 2 1 4 2

Sample Output 1

4

Sample Explanation

The subsequence $\underline{1},\ 3,\ \underline{2},\ \underline{1},\ 4,\ \underline{2}$ (taking the underlined elements, i.e. 1,2,1,21, 2, 1, 2) satisfies the condition, and it is the longest possible.

Sample Input 2

4
100 100 4 100

Sample Output 2

3

Sample Input 3

8
1 2 3 3 3 2 6 6

Sample Output 3

6

Constraints

  • 1≤n≤2×1051 \le n \le 2 \times 10^5
  • 1≤Ai≤1091 \le A_i \le 10^9