Thematic Contests

版权声明:来自星空计算机团队——申屠志刚 https://blog.csdn.net/weixin_43272781/article/details/84179345

https://codeforces.com/contest/1077/problem/E

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.

扫描二维码关注公众号,回复: 4115316 查看本文章

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 i-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: 2 problems of the topic 1, 4 problems of the topic 2, 8 problems of the topic 10.

In the second example the optimal sequence of contests is: 3 problems of the topic 3, 6 problems of the topic 6.

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

C++版本一

二分

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>

using namespace std;
typedef long long ll;
const int N=200000+100;
int t,n,k;
int a[N],X[N];
bool BS(int x){
    int l=1;
    int r=n;
    int mid;
    while(l<=r){
        mid=(l+r)>>1;
        if(X[mid]<x)
            l=mid+1;
        else{
            r=mid-1;
            return 1;
        }
    }
    return 0;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    X[1]=1;
    int cnt=1;
    for(int i=2;i<=n;i++){
        if(a[i-1]!=a[i])
            X[++cnt]=1;
        else
            X[cnt]++;
    }
    sort(X+1,X+cnt+1);
    int ans=1,flag=1,d=X[1];
    for(int i=1;i<=cnt;i++){
        //cout << "X="<<X[i] << endl;
        for(int j=1;j<=X[i];j++){
            flag=1;
            int tmp=j;
            int find=lower_bound(X+i+1,X+cnt+1,2*tmp)-X;;
            while(find<=cnt){
                flag++;
                //cout << "find"<<find<<"tmp"<<tmp << endl;
                tmp*=2;
                find=lower_bound(X+find+1,X+cnt+1,2*tmp)-X;

            }
            int temp=j*(pow(2,flag)-1);
            ans=max(ans,temp);
        }
    }
    cout << ans << endl;
    //cout << "Hello world!" << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43272781/article/details/84179345
今日推荐