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
54
55
56
57
58
59
#include <algorithm>
#include <iostream>

#define DEBUG if (0)
#define COUT cout << "\e[36m"
#define VAR(v) " [\e[32m" << #v << "\e[36m=\e[91m" << v << "\e[36m] "
#define ENDL "\e[39m" << endl

using namespace std;

int tab[1000005];



int main()
{
    ios_base::sync_with_stdio(false);
    int n;

    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        cin >> tab[i];
    }

    sort(tab, tab+n);

    int i = 0, numpow = 0, accpow = 0; ///ktora potega, ile wystopien

    for (;accpow < 202005; ++accpow)
    {
        while(i < n)
        {
            if(tab[i] == accpow)
            {
                numpow++;
                i++;
            }
            else
            {
                break;
            }
        }
        if(i==n && numpow < 2)
        {
            break;
        }
        DEBUG COUT << "|" << accpow << "." << numpow << "| ";
        numpow /=2;
    }

    DEBUG COUT << ENDL;

    cout << accpow << endl;


    return 0;
}