CodeForces-1077E Thematic Contests

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 nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of problems Polycarp has prepared.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) where aiaiis 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.

题解:统计 不同数字的出现个数 的不同 次数,因为每次选的数量后一个是前一个的2倍,所以我们可以枚举每一个数

复杂度 nlog(n)

每次找一个数的时候先找第一个大于等于它的,然后这个数减一,然后判断这个数时候还有或者是否还可以继续操作,

若数量不够 我们选下一个数即可,若数的太小了,我们找第一个大于等于当前的数的数

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
const int N=2e5+100;
int n,a[N],x,id[N],len;
map<int,int> mp,p;
struct node{
	int num;
	int sum;
}b[N];
int c[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&id[i]);
		mp[id[i]]++;
	}
	
	sort(id+1,id+1+n);
	int len=unique(id+1,id+1+n)-(id+1);
	
	for(int i=1;i<=len;i++)
		a[mp[id[i]]]++;
	mp.clear();
	len=0;
	for(int i=1;i<=2e5;i++)
	{
		if(a[i]==0) continue;
		c[++len]=i;
		b[len].num=i;
		b[len].sum=a[i];
	}
	ll ans=0,cnt;
	for(int i=1;i<=c[len];i++)
	{
		int x=i;
		int j=lower_bound(c+1,c+1+len,i)-c;
		cnt=0;
		while(j<=len)
		{
			int t=b[j].sum;
			while(c[j]>=x&&b[j].sum)
			{
				cnt+=x,b[j].sum--;
				x=x*2;
			}
			b[j].sum=t;
			if(c[j]<x)
				j=lower_bound(c+1,c+1+len,x)-c;
			else
				j++;	
		}
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值