func_code_string: #include <bits/stdc++.h>   using namespace std;   bool isPrime(int x) {     if (x == 1) return false;     for (long long i = 2; i <= sqrt(x); i += 1)       if (x % i == 0) return false;     return true;   }   void print(int a[], int n) {     for (long long i = 0; i < n; i += 1) cout << a[i] <<    ;   }   void iarr(int *a, int n) {     for (long long i = 0; i < n; i += 1) cin >> a[i];   }   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = ((res % 1000000007) * (a % 1000000007)) % 1000000007;       a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;       b >>= 1;     }     return res;   }   long long numFactors(long long x) {     long long cnt = 0;     for (long long i = 1; i <= sqrt(x); i += 1) {       if (x % i == 0) {         if (x / i == i)           cnt += 1;         else           cnt += 2;       }     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout << fixed;     cout.precision(10);     ;     int n;     cin >> n;     int a[n];     iarr(a, n);     long long cnt = 0;     while (true) {       int ind = -1, mx = a[0];       for (long long i = 1; i < n; i += 1) {         if (a[i] >= mx) {           ind = i;           mx = a[i];         }       }       if (ind != -1) {         a[ind]--;         a[0]++;         cnt++;       } else if (ind == -1) {         break;       }     }     cout << cnt;     return 0;   }   