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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,n) for (decltype(a) i = (a), i##__ = (n); i <= i##__; ++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define FORD(i,a,n) for (decltype(n) i = (a), i##__ = (n); i >= i##__; --i)
#define REPD(i,n) FORD(i,(n)-1,0)
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define EB emplace_back
#define ST first
#define ND second
#define OS ostream
#define OO(A) template<class... T> OS& operator<<(OS& os, const A<T...>& x) { return __o(os, ALL(x)); }
#define OD(...) OS& operator<<(OS &os, const __VA_ARGS__ &x)
#define SZ(x) ((int)x.size())
#define MP make_pair
#define RS resize
#define V vector
#define nl '\n'

typedef long long LL;
typedef pair<int, int> PII;
typedef V<int> VI;
typedef V<VI> VVI;
typedef V<PII> VPII;
typedef V<VPII> VVPII;
typedef V<bool> VB;
typedef V<VB> VVB;

template<class I> OS& __o(OS&, I, I);
template<class T, size_t N> OD(array<T, N>) { return __o(os, ALL(x)); }
OO(vector) OO(deque) OO(set) OO(multiset) OO(map) OO(multimap)
template<class A, class B> OD(pair<A, B>) {
    return os << "(" << x.ST << ", " << x.ND << ")";
}
template<class I> OS& __o(OS& os, I a, I b) {
    os << "{ ";
    for (; a != b;)
        os << *a++, os << " ";
    return os << "}";
}
template<class I> OS& __d(OS& os, I a, I b) {
    os << "{\n";
    for (I c = a; a != b; ++a)
        os << "  " << distance(c, a) << ": " << *a << endl;
    return os << "}";
}
template<class... T> void __e(T&&... a) {
    int t[] = {(cerr << forward<T>(a), 0)...}; (void)t;
    cerr << endl;
}

template<class A, class B> inline void mini(A& a, B&& b) { if (b < a) a = b; }
template<class A, class B> inline void maxi(A& a, B&& b) { if (b > a) a = b; }

inline int pow2(int n) { return sizeof(int) * 8 - __builtin_clz(n); }

#ifdef DEBUG
# define D(...) __VA_ARGS__
#else
# define D(...)
#endif

#define LOG(x) D(cerr << #x ": " << x << "  ")
#define LOGN(x) D(LOG(x) << endl)
#define DUMP(x) D(cerr << #x ": ", __d(cerr, ALL(x)) << endl)
#define E(...) D(__e(__VA_ARGS__))


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;
    VI liczba(250000, 0);

    REP(i, N)
    {
        int x;
        cin >> x;
        liczba[x]++;
    }

    int ans = 0;
    REP(i, 249999)
    {
        if(liczba[i])
            ans = i;
        liczba[i + 1] += (liczba[i] >> 1);
    }

    cout << ans;
    return 0;
}