1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <bits/stdc++.h>
#define PROC int main(){ios;
#pragma GCC optimize ("-O3")
#define I(x) ({x t;cin>>t;t;})
using namespace std;typedef long long ll;
typedef pair<int,int>pii;typedef vector<int>vi;
#define ios        ios::sync_with_stdio(0),cin.tie(0)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;--i)
#define VEC(i,v)   for(auto&i:v)
#define REP(i,n)   FOR(i,0,n-1)
#define pf         printf

unordered_map<int,int> X;

PROC { /*==========================================*/

int n = I(int), L = 0, R = 0;

REP(i, n) X[I(int)]++;
REP(i, 201718 + 100) {
	X[i] += L; L = (X[i] - (X[i] & 1)) >> 1;
	if (X[i] != 0) R = i;
}

pf("%d", R);

}} /*PROC==========================================*/

/*
5
3 4 1 3 3
*/