func_code_string: #include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int maxar(int arr[], int n) {     int res = arr[0];     for (int i = 0; i < n; i++) {       res = max(res, arr[i]);     }     return res;   }   long long maxar(long long arr[], long long n) {     long long res = arr[0];     for (long long i = 0; i < n; i++) {       res = max(res, arr[i]);     }     return res;   }   long long minar(long long arr[], long long n) {     long long res = arr[0];     for (long long i = 0; i < n; i++) {       res = min(res, arr[i]);     }     return res;   }   int minar(int arr[], int n) {     int res = arr[0];     for (int i = 0; i < n; i++) {       res = min(res, arr[i]);     }     return res;   }   void inpar(int arr[], int n) {     for (int i = 0; i < n; i++) {       cin >> arr[i];     }   }   void inpar(long long arr[], long long n) {     for (long long i = 0; i < n; i++) {       cin >> arr[i];     }   }   template <typename T>   inline T readInt() {     T n = 0, s = 1;     char p = getchar();     if (p ==  - ) s = -1;     while ((p <  0  || p >  9 ) && p != EOF && p !=  - ) p = getchar();     if (p ==  - ) s = -1, p = getchar();     while (p >=  0  && p <=  9 ) {       n = (n << 3) + (n << 1) + (p -  0 );       p = getchar();     }     return n * s;   }   void solve() {     int n = readInt<int>();     int a[n];     inpar(a, n);     int res = 0;     priority_queue<int> q;     for (int i = 1; i < n; i++) {       q.push(a[i]);     }     while (q.top() >= a[0]) {       res++;       a[0]++;       int temp = q.top();       temp--;       q.pop();       q.push(temp);     }     cout << res;   }   int32_t main() {     int tc;     tc = 1;     while (tc--) {       solve();     }     return 0;   }   