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

using namespace std;


int main () {
  int N;
  scanf("%d", &N);
  map<int, int> monety;

  for (int i = 0; i < N; ++i) {
    int nominal;
    scanf("%d", &nominal);
    if (monety.count(nominal) == 0) {
      monety[nominal] = 0;
    }
    monety[nominal] += 1;
  }

  map<int, int>::iterator it;
  //for (it = monety.begin(); it != monety.end(); ++it) {
  //  printf("%d : %d\n", it->first, it->second);
  //}



  for (it = monety.begin(); it != monety.end(); ++it) {
    int potega; // nominal monet
    int n; // ilosc monet o nominale
    potega = it->first;
    n = it->second;
    if (n > 1) {
      it->second = 0;
      int i =0;
      while (n > 0) {
        if (n % 2 == 1) {
          if (monety.count(potega + i) == 0) {
            monety[potega + i] = 0;
          }
          monety[potega + i] += 1;
        }
        n = n / 2; // przesuniecia bitowe sa szybsze
        ++i;
      }
    }
  }

  int max_potega = monety.rbegin()->first;
  printf("%d", max_potega);
  return 0;
}