#include using namespace std; int main() { int n; cin >> n; int *Candy = new int[n]; for (int i = 0; i < n; i++) { cin >> Candy[i]; } int total = 0; while (1) { bool flag = true; for (int i = 1; i < n; i++) { if (Candy[0] != Candy[i]) { flag = false; break; } } if (flag == true) break; int temp = Candy[n - 1]; for (int i = n - 1; i >= 0; i--) { if (i == 0) { Candy[0] = Candy[0] / 2 + temp / 2; } else Candy[i] = Candy[i] / 2 + Candy[i - 1] / 2; if (Candy[i] % 2 == 0) { Candy[i] += 1; total += 1; } } } cout << total << endl; }