func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MX = 100 * 1000 + 7;   int a[MX];   int hup[MX], hdown[MX];   long long cup[MX], cdown[MX];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       int cost = 0;       if (a[i] <= hup[i - 1]) cost = (hup[i - 1] + 1 - a[i]);       hup[i] = a[i] + cost;       cup[i] = cup[i - 1] + cost;     }     for (int i = n; i >= 1; i--) {       int cost = 0;       if (a[i] <= hdown[i + 1]) cost = (hdown[i + 1] + 1 - a[i]);       hdown[i] = a[i] + cost;       cdown[i] = cdown[i + 1] + cost;     }     long long res = (long long)1e18;     for (int i = 1; i <= n; i++) {       int need = max(hup[i - 1] + 1, hdown[i + 1] + 1);       int cost = 0;       if (a[i] < need) cost = need - a[i];       res = min(res, cup[i - 1] + cdown[i + 1] + cost);     }     printf( %lld n , res);   }   