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
//Pawel Wroblewski
#include <cstdio>
int nominaly[1000001];
int main()
{
    int n,moneta, max_n=0;
    scanf("%d", &n);
    while (n--)
    {
        bool repeat=true;
        scanf("%d", &moneta);
        if(moneta>max_n)
                max_n=moneta;
            nominaly[moneta]++;
        while(repeat==true)
        {
            if(nominaly[moneta]==2)
            {
                nominaly[moneta]=0;
                nominaly[moneta+1]++;
                if(moneta+1>max_n)
                max_n=moneta+1;
                moneta++;
            }
            else
                repeat=false;
        }
    }
    printf("%d", max_n);
    return 0;
}