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
#include <stdio.h>
#include <map>
#include <iterator>
using namespace std;

int main() {
    int n;
    int a;
    map<int, int> powers;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        powers[a]++;
    }
	
	map<int, int>::iterator it;
    for ( it = powers.begin(); it != powers.end(); it++ ) {
        int k = it->second / 2;
        if (k > 0) {
            powers[(it->first) + 1] += k;
        }
        
    }
	
	printf("%d", powers.rbegin()->first);
	return 0;
}