E. Thematic Contests【dp】

题目链接

E. Thematic Contests

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp has prepared nn competitive programming problems. The topic of the ii-th problem is aiai, and some problems' topics may coincide.

Polycarp has to host several thematic contests. All problems in each contest should have the same topic, and all contests should have pairwise distinct topics. He may not use all the problems. It is possible that there are no contests for some topics.

Polycarp wants to host competitions on consecutive days, one contest per day. Polycarp wants to host a set of contests in such a way that:

  • number of problems in each contest is exactly twice as much as in the previous contest (one day ago), the first contest can contain arbitrary number of problems;
  • the total number of problems in all the contests should be maximized.

Your task is to calculate the maximum number of problems in the set of thematic contests. Note, that you should not maximize the number of contests.

Input

The first line of the input contains one integer n (1≤n≤2⋅105) — the number of problems Polycarp has prepared.

The second line of the input contains nn integers a1,a2,…,an (1≤ai≤109) where aiai is the topic of the ii-th problem.

Output

Print one integer — the maximum number of problems in the set of thematic contests.

Examples

input

18
2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10

output

14

input

10
6 6 6 3 6 1000000000 3 3 6 6

output

9

input

3
1337 1337 1337

output

3

Note

In the first example the optimal sequence of contests is: 22 problems of the topic 11, 44 problems of the topic 22, 88 problems of the topic 1010.

In the second example the optimal sequence of contests is: 33 problems of the topic 33, 66 problems of the topic 66.

In the third example you can take all the problems with the topic 13371337 (the number of such problems is 33 so the answer is 33) and host a single contest.

题意:

Ñ个问题,每个问题对应一个主题,每一天的问题的主题要保证全部一样,每一天的问题数量是前一天的两倍,要求任何两天的

主题是一样的,求最大的问题数目。

分析:

先按数目排序,dp [i]代表满足最后一天的问题数量是i,所能满足条件的最大问题数量。

例如DP [I] = DP [I / 2] + I; DP [i]于可能是4 + 8 + 16 + I组成的,

类似多重背包

代码:

#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int a[210005],dp[210005],b[2100005],n;
int main()
{
    int i,j,maxn,num;
    maxn=1;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    sort(a,a+n);
    int str=0;
    num=0;
    for(i=1;i<n;i++)
    {
        if(a[i]!=a[i-1])
        {
            b[num++]=i-str;
            str=i;
        }
    }
    b[num++]=i-str;
    sort(b,b+num);
    for(i=0;i<num;i++)
    {
        for(j=b[i];j;j--)
        {
            if(j%2==0)
                dp[j]=max(dp[j],dp[j/2]+j);
            else
                dp[j]=j;
            maxn=max(maxn,dp[j]);
        }
    }
    printf("%d\n",maxn);
}

猜你喜欢

转载自blog.csdn.net/lml11111/article/details/84196760