Polycarp has prepared $n$ competitive programming problems. The topic of the $i$-th problem is $a_i$, 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 \le n \le 2 \cdot 10^5$) — the number of problems Polycarp has prepared.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) where $a_i$ 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.

Difficulty: introductory

Starter code:

Solutions:
#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N  = getIntList()
za  = getIntList()

cc = collections.Counter(za)
zt = []
for x in cc:
    zt.append( cc[x] )

zt.sort( )

re = zt[-1] 

def findmid(l,r, e):
    if l>= len(zt):
        return -1
    if e<=zt[l]: return l;
    if e>zt[r]: return -1
    while l+1 <r:
        mid = (l+r)//2
        if zt[mid] < e:
            l = mid
        else:
            r = mid
    return r
for first in range(1, re//2 + 1):
    nowr = 0
    t = first
    ind = -1
    while 1:
        ind = findmid(ind+1,len(zt)-1, t)
        if ind<0:
            break
        nowr += t
        t*=2
    re = max(re, nowr)
print(re)










import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

n = mints()
a = list(mints())
a.sort()
p = -1
c = -1
b = []
for i in range(len(a)):
	if a[i] != p:
		if c != -1:
			b.append((c, p))
		c = 1
		p = a[i]
	else:
		c += 1
if c != -1:
	b.append((c, p))
b.sort(reverse=True)
p = -1
r = 0
for i in range(len(b)):
	if p == -1:
		p = b[i][0]
	else:
		p = min(p//2,b[i][0])
	if p != 0:
		r = max(r, p*((2**(i+1))-1))
print(r)


def main():
    buf = input()
    n = int(buf)
    buf = input()
    buflist = buf.split()
    a = list(map(int, buflist))
    appearance = {}
    for i in a:
        if not i in appearance:
            appearance.update({i : 1})
        else:
            appearance[i] += 1
    appearance = [[k, v] for k ,v in list(dict(sorted(list(appearance.items()), key=lambda x:x[1])).items())]
    max_num = appearance[-1][1]
    pos = 0
    for i in range(1, max_num + 1):
        num = 0
        prob = i
        for j in range(pos, len(appearance)):
            if appearance[j][1] >= prob:
                num += prob
                prob *= 2
        if num > max_num:
            max_num = num
        while appearance[pos][1] == i and pos < len(appearance) - 1:
            pos += 1
    print(max_num)

def __starting_point():
    main()

__starting_point()

# from collections import Counter as C
# n, k_ = map(int, input().split())
# l = [*map(int, input().split())]

# c = C(l)
# d = {}
# for k, v in c.items():
#     d[v] = d.get(v, []) + [str(k)]

# ld = sorted([(k, v) for k, v in d.items()], reverse = True)

# res = []
# # print(ld)
# for e in ld:
#     res += [e[1]]
#     if e[0] * len(res) >= k_:
#         i = 0
#         while k_ > e[0] * len(res[i]):
#             print((' '.join(res[i]) + ' ') * e[0])
#             i += 1
#             k_ -= e[0] * len(res[i])
#         # if k_:
#         #     print((res[i] + ' ') * k_)
#         return


from bisect import bisect_left, bisect_right
from collections import Counter as C

n_ = int(input())
l = sorted(C(map(int, input().split())).values())
n = len(l)
i = res = 0

# print(l)

def f(x):
    i = 0
    for m in range(33):
        t = x << m
        i = bisect_left(l, t, i)
        if i == n:
            return t - x
        i += 1


res = 0
for x in range(1, n_ + 1):
    res = max(res, f(x))

print(res)

n = int(input())
a = [int(x) for x in input().split()]
dtt = dict()
for t in a:
    if t in dtt:
        dtt[t] += 1
    else:
        dtt[t] = 1
lts = [dtt[x] for x in dtt]
lts.sort(reverse=True)
mt = [lts[0]]
pl = lts[0]
for d in range(1, len(lts)):
    cl = min(pl // 2, lts[d])
    if cl == 0:
        break
    cs = cl * (2**(d+1) - 1)
    mt.append(cs)
    pl = cl
print(max(mt))


# -*- coding: utf-8 -*-

import math
import collections
import bisect
import heapq
import time
import itertools
import sys

"""
created by shhuan at 2018/11/16 23:49

"""
N = int(input())
A = [int(x) for x in input().split()]

wc = collections.Counter(A)

counts = [c for w, c in wc.items()]
counts.sort()
lencounts = len(counts)

vals = {v:v for v in range(1, counts[0]+1)}
for i in range(1, lencounts):
    new_vals = {}
    for v in range(1, counts[i] + 1):
        if v % 2 == 0:
            new_vals[v] = (vals[v//2] + v) if v//2 in vals else v
        else:
            new_vals[v] = v

    for k, v in new_vals.items():
        if k in vals:
            vals[k] = max(vals[k], v)
        else:
            vals[k] = v

print(max(vals.values()))

import sys
n=int(sys.stdin.readline())
A=list(map(int,sys.stdin.readline().split()))

from collections import Counter
c=Counter(A)

LIST=list(c.values())
LIST.sort(reverse=True)

if len(LIST)==1:
    print(LIST[0])
    return

LL=len(LIST)
y=LIST[0]
ANS=y
if y%2==1:
    y=y-1

#count2=0
#while y%2==0:
#    y=y//2
#    count2+=1

for x in range(y,0,-2):
    an=0
    for j in range(LL):
        if x%(2**j)==0 and LIST[j]>=x//(2**j):
            an+=x//(2**j)
        else:
            break
    if an>ANS:
        ANS=an

print(ANS)


n = list(map(int, input().split()))
a = list(map(int, input().strip().split()))
alla = {}
for x in a:
	if(alla.get(x) == None):
		alla.update({x: 0})
	alla.update({x: alla[x] + 1})
als = set(a)
res = []
for x in als:
	res.append(alla[x])
res.sort()

n = len(res)
ans = 0
for i in range(1, res[n-1]+1):
	curs = i
	cur = i 
	ans = max(ans, curs)
	j = n-2
	if(cur % 2 == 1):          
		continue
	cur = cur // 2
	while(j >= 0 and res[j] >= cur):
		curs += cur
		ans = max(ans, curs)
		j -= 1
		if(cur % 2 != 0):	
			break
		cur = cur // 2

print(ans)
		


n = int(input())
a = [int(x) for x in input().split()]
dtt = dict()
for t in a:
    if t in dtt:
        dtt[t] += 1
    else:
        dtt[t] = 1
lts = [dtt[x] for x in dtt]
lts.sort(reverse=True)
mt = [lts[0]]
pl = lts[0]
for d in range(1, len(lts)):
    cl = min(pl // 2, lts[d])
    if cl == 0:
        break
    cs = cl * (2**(d+1) - 1)
    mt.append(cs)
    pl = cl
print(max(mt))


n=int(input())
arr=list(map(int,input().split()))
d={}
powers=[]
for i in range(32):
    powers.append(2**i)
for i in arr:
    if i in list(d.keys()):
        d[i]+=1
    else:
        d[i]=1 
arr1=[]
for i in list(d.keys()):
    arr1.append(d[i])
arr1.sort(reverse=True)
maxx=arr1[0]
curr=arr1[0] 
for i in range(1,len(arr1)):
    if curr>2*arr1[i]:
        maxx=max(maxx,arr1[i]*(powers[i+1]-1))
        curr=arr1[i]
    else:
        maxx=max(maxx,(curr//2)*(powers[i+1]-1))
        curr=curr//2
    if curr==0:
        break
print(maxx)



def fun(l,r,bound):
	nonlocal val;
	ind = -1;
	while(l<=r):
		mid = (l+r)//2;
		if (val[mid]>=bound):
			r = mid-1;
			ind = mid;
		else:
			l = mid+1;
	return ind;

n = int(input());
a = list(map(int,input().split()))
d = {};
for i in range(n):
	try:
		d[a[i]]+=1;
	except:
		d[a[i]]=1;
val = list(d.values());
val.sort();
ans = 0;
for i in range(1,200100):
	temp = 0;
	add = i;
	ind = fun(0,len(val)-1,add);
	while(ind!=-1):
		temp += add;
		add = add*2;
		ind = fun(ind+1,len(val)-1,add);
	ans = max(ans,temp);
print(ans)



n = int(input())
a = [int(x) for x in input().split()]
dtt = dict()
for t in a:
    if t in dtt:
        dtt[t] += 1
    else:
        dtt[t] = 1
lts = [dtt[x] for x in dtt]
lts.sort(reverse=True)
mt = [lts[0]]
pl = lts[0]
for d in range(1, len(lts)):
    cl = min(pl // 2, lts[d])
    if cl == 0:
        break
    cs = cl * (2**(d+1) - 1)
    mt.append(cs)
    pl = cl
print(max(mt))


from collections import Counter


def main():
    from sys import stdin, stdout

    # stdin = open("in.txt", "r")
    it = iter(map(int, stdin.read().split()))

    n = next(it)
    topic_list = [next(it) for _ in range(n)]

    cnt_list = sorted(Counter(topic_list).values())
    mx_val = cnt_list[-1]
    res = 0

    for curr_val in range(1, mx_val+1):
        curr_res = curr_val
        idx = len(cnt_list) - 1

        while curr_val % 2 == 0 and idx > 0:
            curr_val //= 2
            idx -= 1
            if cnt_list[idx] < curr_val:
                break
            curr_res += curr_val

        res = max(res, curr_res)

    stdout.write(str(res))


def __starting_point():
    main()

__starting_point()

p_line = [int(x) for x in input().strip().split(' ')]
size = p_line[0]
		
a = [int(x) for x in input().strip().split(' ')]
num_to_occ = {}
for x in a:
	if x not in num_to_occ:
		num_to_occ[x] = 0
	num_to_occ[x] += 1

topics = []
for _, occ in num_to_occ.items():
	topics.append(occ)
topics.sort(reverse = True)

ba = 0
for start in range(1, topics[0] + 1):	
	my_a = start
	
	act = start
	for i in range(1, len(topics)):
		if act % 2 == 1:
			break
		
		act = act / 2
		if act > 0 and topics[i] >= act:
			my_a += act
		else:
			break
	ba = max(ba, my_a)

print(int(ba))

n = int(input())
a = [int(i) for i in input().split()]

dtt = dict()

for v in a:
    if v not in dtt:
        dtt[v] = 0
    dtt[v] += 1

lts = [dtt[i] for i in dtt]
lts.sort(reverse=True)

mt = [lts[0]]
pl = lts[0]

for i in range(1,len(lts)):
    cl = min(pl//2,lts[i])
    if cl == 0:
        break
    cs = cl*(2**(i+1)-1)
    mt.append(cs)
    pl = cl

print(max(mt))


from collections import defaultdict
from sys import stdin


class Solver:

    @staticmethod
    def build_dict(l):
        mp = defaultdict(int)
        for val in l:
            mp[val] = mp[val] + 1
        return mp

    @staticmethod
    def build_cnt_list(mp):
        lst = [v for (k, v) in list(mp.items())]
        return lst

    def __init__(self, l):
        self.__L = l

    @staticmethod
    def get_largest_power_of_2(n):
        # for p in reversed(range(31)):
        for p in range(30, -1, -1):
            if 1 << p <= n:
                return 1 << p
        return 1

    def solve(self):
        mp = Solver.build_dict(self.__L)
        cnt_lst = Solver.build_cnt_list(mp)
        cnt_lst.sort()
        cnt_lst.reverse()

        ans = cnt_lst[0]

        for start_cand in range(cnt_lst[0], 0, -1):
            if start_cand % 2 == 0 :
                ans2 = 0
                nxt = start_cand
                for cnt in cnt_lst:
                    if cnt >= nxt:
                        ans2 += nxt
                        if nxt % 2 != 0:
                            break
                        nxt //= 2
                    else:
                        break
                ans = max(ans, ans2)

        return ans


def main():
    n = int(stdin.readline())
    inp = list(map(int, stdin.readline().split()))

    # print(n)
    # print(inp)
    solver = Solver(inp)
    # print(Solver.build_dict(inp))
    print(solver.solve())


main()


import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    data_stat = {}
    for i in range(n):
        t = data_stat.get(a[i], 0) + 1
        data_stat[a[i]] = t
    current = sorted(list(data_stat.items()), key = lambda x: x[1])
    answer = 0
    for i in range(1, current[-1][1] + 1):
        pos = len(current) - 1
        cur = i
        res = cur
        while cur % 2 == 0 and pos > 0:
            cur //= 2
            pos -= 1
            if current[pos][1] < cur:
                break
            res += cur
        answer = max(answer, res)
    print(answer)
    return
    
def __starting_point():
    main()

__starting_point()

def calc(am, con):
    ans = am
    for i in range(len(con)):
        if am % 2 != 0:
            if con[i] >= am and i != 0:
                ans += am
            return ans
        if i == 0:
            am //=2
            continue
        if con[i] >= am:
            ans += am
            am //=2
        else:
            return ans
    return ans


def main():
    n = int(input())
    l = list(map(int, input().split()))
    dic = dict()
    for i in range(n):
        dic[l[i]] = 0
    for i in range(n):
        dic[l[i]] += 1
    l = list(dic.values())
    l.sort(reverse=True)
    ans = [0] * (l[0] + 1)

    for i in range(1, l[0] + 1):
        ans[i] = calc(i, l)
    print(max(ans))
main()

n=int(input())
pro=[int(i) for i in input().split()]
book={}
for i in pro:
    if i in book:
        book[i]+=1
    else:
        book[i]=1
book=[book[i] for i in book]
book=sorted(book,reverse=True)
book.insert(0,0)
ans=0
l=len(book)
for i in range(1,book[1]+1):
    pos,cur,tem=2,i,i
    while cur&1 == 0 and pos <l:
        cur>>=1
        if book[pos]<cur :
            break
        tem+=cur
        pos+=1
    ans=max(ans,tem)
print(ans)

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
l = sorted(c.values())
size = len(l)
ans = 0
for i in range(1, l[-1] + 1):
    temp_ans = 0
    cur = i
    pos = size - 1  # pointer of the l array
    while cur <= l[pos] and pos >= 0:  # no index overflow
        temp_ans += cur
        pos -= 1
        if cur & 1:
            break
        cur >>= 1
    ans = max(ans, temp_ans)
print(ans)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
l = sorted(c.values())
size = len(l)
ans = 0
for i in range(1, l[-1] + 1):
    temp_ans = 0
    cur = i
    pos = size - 1  # pointer of the l array
    while cur <= l[pos] and pos >= 0:  # no index overflow
        temp_ans += cur
        pos -= 1
        if cur & 1:
            break
        cur >>= 1
    ans = max(ans, temp_ans)
print(ans)

# -*- coding: utf-8 -*-
"""
@author: zzf
@file: main.py
@time: 2018/11/13
"""
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))

m = defaultdict(int)

for i in range(n):
    m[a[i]] += 1

count = []
for k in m:
    count.append(m[k])
count.sort()

k = len(count)-1
ans = 0

if k == 0:
    print(count[k])
    return

for i in range(count[-1], 0, -1):
    tmp = i
    res = i
    pos = k
    while tmp %2 == 0 and pos > 0:
        tmp = tmp //2
        pos -= 1
        if count[pos] < tmp:
            break
        res += tmp
    ans = max(res, ans)

print(ans)





def nono(nu, a, b, c):
	if c == len(nu):
		return a
	if nu[c] >= b:
		silo = b * (2**(c+1) - 1)
		return nono(nu, max(a, silo), b//2, c+1)
	else:
		silo = nu[c] * (2**(c+1) - 1)
		return nono(nu, max(a, silo), nu[c]//2, c+1)

n = int(input())
nums = list(map(int, input().split()))
mapa = {}
li = []
for nu in nums:
	mapa[nu] = mapa.get(nu, 0) + 1
for ma, c in list(mapa.items()):
	li.append(c)
li.sort(reverse=True)
# print(li)
res = li[0]
# print(nono(li, res, li[0]//2, 1))
nu = li
a = li[0]
b = li[0]//2
c = 1
while len(nu) > c:
	if nu[c] >= b:
		silo = b * (2**(c+1) - 1)
		a = max(a, silo)
		b = b//2
		c += 1
	else:
		silo = nu[c] * (2**(c+1) - 1)
		a = max(a, silo)
		b = nu[c]//2
		c += 1
print(a)




n = int(input())
nums = list(map(int, input().split()))
mapa = {}

for nu in nums:
	mapa[nu] = mapa.get(nu, 0) + 1
li = [mapa[x] for x in mapa]

li.sort(reverse=True)

a = li[0]
b = li[0]//2
c = 1
while len(li) > c:
	if b == 0:
		break
	if li[c] >= b:
		silo = b * (2**(c+1) - 1)
		a = max(a, silo)
		b = b//2
		c += 1
	else:
		silo = li[c] * (2**(c+1) - 1)
		a = max(a, silo)
		b = li[c]//2
		c += 1
print(a)