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
#include <iostream>

using namespace std;

const int tabSIZE = 3200;
unsigned long* tab = new unsigned long[tabSIZE];

int maxKomorka = 0;
int maxBit = 0;

void aktualizujBit(int komorka, int bit) {
	if ((komorka > maxKomorka) || (komorka == maxKomorka && bit > maxBit)) {
		maxKomorka = komorka;
		maxBit = bit;
	}
	unsigned long mask = 1 << bit;
	if ((tab[komorka] & mask) == mask) {
		tab[komorka] &= ~(mask);
		bit++;
		if(bit >= 64){
			komorka++;
			bit = 0;
		}
		aktualizujBit(komorka, bit);
	} else {
		tab[komorka] |= mask;
	}
}

int main () {
	for (int i = 0; i < tabSIZE; i++)
		tab[i] = 0;
	int n, a;
	cin >> n;
	while (n--) {
		cin >> a;
		aktualizujBit(a / 64, a % 64);
	}
	cout << (maxKomorka * 64 + maxBit) << endl;
	system("pause");
	return 0;
}