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

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 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 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

Copy
18
2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10
output

Copy
14
input

Copy
10
6 6 6 3 6 1000000000 3 3 6 6
output

Copy
9
input

Copy
3
1337 1337 1337
output

Copy
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.

代码:

    #include <bits/stdc++.h>
using namespace std; const int maxn = 2e5 + 10;
const int N = 1e6 + 5;
int n;
int a[N]; int main() {
scanf("%d", &n);
int cnt = 0;
map<int, int> mp;
for(int i = 1; i <= n; i ++) {
int x;
scanf("%d", &x);
if(!mp[x]) {
cnt ++;
mp[x] = cnt;
}
a[mp[x]] ++;
}
sort(a + 1, a + 1 + cnt);
int ans = 0; for(int i = 1; i <= n; i ++) {
int st = 1;
int m = 0;
for(int k = i; k <= n; k *= 2) {
int pos = lower_bound(a + st, a + 1 + cnt, k) - a;
if(pos == cnt + 1) break;
m += k;
st = pos + 1;
}
ans = max(ans, m);
}
printf("%d\n", ans);
return 0;
}

  

CodeForces Round #521 (Div.3) E. Thematic Contests的更多相关文章

  1. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

  2. Codeforces Round #521 (Div. 3) E. Thematic Contests (离散化,二分)

    题意:有\(n\)个话题,每次都必须选取不同的话题,且话题数必须是上次的两倍,第一次的话题数可以任意,问最多能选取多少话题数. 题解:我们首先用桶来记录不同话题的数量,因为只要求话题的数量,与话题是多 ...

  3. Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】

    任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory ...

  4. CodeForces Round #521 (Div.3) D. Cutting Out

    http://codeforces.com/contest/1077/problem/D You are given an array ss consisting of nn integers. Yo ...

  5. Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)

    F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...

  6. CodeForces Round #521 (Div.3) B. Disturbed People

    http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...

  7. CodeForces Round #521 (Div.3) A. Frog Jumping

    http://codeforces.com/contest/1077/problem/A A frog is currently at the point 00 on a coordinate axi ...

  8. Codeforces Round #521 (Div. 3)

    B 题过的有些牵强,浪费了很多时间,这种题一定想好思路和边界条件再打,争取一发过.  D 题最开始读错题,后面最后发现可以重复感觉就没法做了,现在想来,数据量大,但是数据范围小枚举不行,二分还是可以的 ...

  9. Codeforces Round #521 Div. 3 玩耍记

    A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

随机推荐

  1. Sass学习日志

    一.什么是SASS SASS是一中CSS的开发工具,提供了许多便利的写法,大大节约了设计者们的时间,使得CSS的开发,变得简单和可维护.本文总结了SASS的主要方法.我们的目标是,有了这篇文章,日常的 ...

  2. Redis安装与简单配置

    一.Redis介绍 1.redis是什么? remote dIctionary server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统.Redis提 ...

  3. 详解Linux运维工程师

    运维工程师是从一个呆逼进化为苦逼再成长为牛逼的过程,前提在于你要能忍能干能拼,还要具有敏锐的嗅觉感知前方潮流变化.如:今年大数据,人工智能比较火……(相对表示就是 Python 比较火) 之前写过运维 ...

  4. C#在textBox中输出一个数组

    //将数组输出到文本框测试 for(i=0;i<arr.Length-1;i++){ this.textBox1.Text=this.textBox1.Text+arr[i]; }

  5. [转]win7下修改C盘USERS文件下的名称

    Win7下C:\Users\Cortana以账户名称命名的系统文件夹用户名的修改   Win7下C:\Users\Cortana以账户名称命名的系统文件夹用户名的修改 Win7下C:\Users\Co ...

  6. mysql 常用函数,基本使用

    1:选中排除表1 连接表2 表3 获取选中表1中部分选中表3 的部分 并且设置选中状态select t1.*,if(t2中t3id=t1.id,1,0)as checked from t1 lefet ...

  7. FastDFS轻量级分布式文件系统部署

    FastDFS介绍 FastDFS 是一个由 C 语言实现的开源轻量级分布式文件系统,作者余庆,支持 Linux.FreeBSD.AID 等 Unix 系统,解决了大数据存储和读写负载均衡等问题,适合 ...

  8. 数据分析处理库Pandas——时间

    时间戳 向后推的时间戳 备注:五天后的时间. 指定日期和时间 时间的Series结构 按要求显示时间(开始时间,时间间隔,时间个数) 转换为时间格式,并设置时间列为索引列 方法一 方法二 筛选显示 方 ...

  9. go学习笔记-运算符

    运算符 运算符 内置运算符 算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 其他运算符 算术运算符 假定 A 值为 10,B 值为 20. 运算符 描述 实例 + 相加 A + B 输出结果 ...

  10. linux io 学习笔记(03)---共享内存,信号灯,消息队列

    system V IPC 1)消息队列 2)共享内存 3)信号灯(信号量集) 1.消息队列. ipcs -q 查看系统中使用消息队列的情况 ipcrm -q +msqid 删除消息队列 消息队列工作原 ...