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
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

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

	std::vector<int> coins;
	int n;
	std::cin >> n;
	coins.reserve(n);
	std::copy_n(std::istream_iterator<int>(std::cin), n, std::back_inserter(coins));

	std::sort(coins.begin(), coins.end());

	int cur_nominal = 0;
	int cur_nominal_count = 0;
	int pos = 0;
	while (pos < n || cur_nominal_count > 1) {
		cur_nominal++;
		cur_nominal_count /= 2;
		while (pos < n && coins[pos] == cur_nominal) {
			++pos;
			++cur_nominal_count;
		}
	}
	
	std::cout << cur_nominal;
}