func_code_string: #include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const long long int INFLL = 0x3f3f3f3f3f3f3f3fll;   long long int getint() {     long long int ret = 0;     bool f = 0;     char c;     while ((c = getchar()) <  0  || c >  9 )       if (c ==  - ) f ^= 1;     while (c >=  0  && c <=  9 ) {       ret = ret * 10 + c -  0 ;       c = getchar();     }     return f ? -ret : ret;   }   using namespace std;   const int MAXN = 200000;   int a[MAXN + 10], f[MAXN + 10][20], w[MAXN + 10], lg2[MAXN + 10];   int nxt[MAXN + 10][20], far[MAXN + 10][20];   int query(int l, int r) {     int t = lg2[r - l + 1];     int ret = f[r - (1 << t) + 1][t];     if (w[f[l][t]] > w[ret]) ret = f[l][t];     return ret;   }   int main() {     int n = getint(), N = 2 * n;     for (int i = n; i >= 1; --i) a[i + n] = a[i] = getint();     lg2[0] = -1;     for (int i = 1; i <= N; ++i) {       w[i] = i + a[i];       f[i][0] = i;       lg2[i] = lg2[i >> 1] + 1;     }     for (int j = 1; j <= lg2[N]; ++j)       for (int i = 1; i + (1 << j) - 1 <= N; ++i) {         f[i][j] = f[i + (1 << (j - 1))][j - 1];         if (w[f[i][j - 1]] > w[f[i][j]]) f[i][j] = f[i][j - 1];       }     for (int i = 1; i < N; ++i) {       nxt[i][0] = query(i + 1, min(N, i + a[i]));       far[i][0] = w[i];     }     far[N][0] = nxt[N][0] = N;     for (int j = 1; j <= lg2[N]; ++j)       for (int i = 1; i <= N; ++i) {         nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];         far[i][j] = far[nxt[i][j - 1]][j - 1];       }     long long int output = 0;     for (int i = 1; i <= n; ++i) {       int ans = 0, u = i;       for (int j = lg2[N]; j >= 0; --j)         if (far[u][j] < i + n - 1) ans += 1 << j, u = nxt[u][j];       output += ans + 1;     }     printf( %I64d n , output);     return 0;   }   