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
#include <bits/stdc++.h>
typedef long long ll;
#define F(i,a,b) for(ll i=a;i<=b;i++)
using namespace std;
const int N=500005;

int num[N];

 int main()
 {
	F(i,0,N-5) num[i]=0;
	int n,a;

	scanf("%d",&n);
	F(i,1,n) scanf("%d",&a), num[a]++;

	int mx=0;
	F(i,0,N-5)
	{
		if(num[i]!=0) mx=i;
		num[i+1]+=(num[i]/2);
	}

	printf("%d\n",mx);
 }