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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>

int main(int argc, char **argv)
{
	unsigned long long int *tab = new unsigned long long int[3156];
int pom;
	int n, i=0;
	n = 3156;
	while ( n-- )
	{
		tab[n] = 0;
	}

//pom = 0; while(pom < 4) {printf("%d ", tab[pom]); pom++;} printf("\n");

	scanf("%d", &n);

	while ( n-- )
	{
		scanf("%d", &i);
//printf("\ni = %d:\t",i);pom = 0; while(pom < 4) {printf("%d ", tab[pom]); pom++;} printf("\n");
		if ( tab[i/64] & (1 << i%64) )
		{
			tab[i/64] &= ~(1 << i%64);
			i++;
			while ( tab[i/64] & (1 << i%64) )
			{
				tab[i/64] &= ~(1 << i%64);
				i++;
			}
		}

		tab[i/64] |= 1 << i%64;

//printf("\ni = %d:\t",i);pom = 0; while(pom < 4) {printf("%d ", tab[pom]); pom++;} printf("\n");
	}
	
	n = 3156;
	while ( n-- )
	{
		if(tab[n]!=0)
			break;
	}
	i=0;
	while(tab[n]!=0)
	{
		i++;
		tab[n] = tab[n] >> 1;
	}
	printf("%d", n*64 + i - 1);

	return 0;
}