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

int ilosci[201751];

int main()
{
    int n,a;
    scanf("%d",&n);
    for (int i=0;i<=201750;i++) ilosci[i]=0;
    while (n--)
    {
        scanf("%d",&a);
        ilosci[a]++;
    }
    for (int i=0;i<=201749;i++)
        ilosci[i+1]+=ilosci[i]/2;
    int wynik=0;
    for (int i=201750;i>=0;i--)
        if (ilosci[i]>0)
        {
            wynik=i;
            break;
        }
    printf("%d\n",wynik);
    return 0;
}