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
34
35
36
37
#include<stdio.h>

#define MAX_N 1000000
#define MAX_A_PLUS 201750

int counter[MAX_A_PLUS];

int main() {
	int n,a,j,result;
	result = 0;
	scanf("%d\n", &n); 
	for (int i=0; i < n; ++i) {
		scanf("%d", &a);
		++(counter[a]);	
	}
	for (int i=0; i < MAX_A_PLUS; ++i) {
		a = counter[i];
		j = 0;
//		printf("%d::%d\n", i, counter[i]);
		while (a > 1) {
			++j;	
			a -= 2;
//			printf("%d\n", i);
		}
		if (j>0) {
			++(counter[i+j]);
		}
	}
	for (int i=0; i < MAX_A_PLUS; ++i) {
//		printf("%d::%d\n", i, counter[i]);
		if (counter[i]) {
			result = i;
		}
	}
	printf("%d\n", result);
return 0;
}