#include <bits/stdc++.h>   int n, a[500005], L[500005], f[500005][22], g[500005][22];   long long ans;   int get(int x, int y) {     if (x < 0) return 0;     int k = (int)log2(y - x + 1);     return L[f[x][k]] <= L[f[y + 1 - (1 << k)][k]] ? f[x][k]                                                    : f[y + 1 - (1 << k)][k];   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]), a[n + i] = a[i];     for (int i = 0; i < n + n; i++) L[i] = i - a[i], f[i][0] = i;     for (int j = 0; j < 19; j++)       for (int i = 0; i < n + n - (1 << j); i++)         f[i][j + 1] =             L[f[i][j]] <= L[f[i + (1 << j)][j]] ? f[i][j] : f[i + (1 << j)][j];     for (int i = 0; i < n + n; i++) g[i][0] = get(L[i], i);     for (int j = 0; j < 19; j++)       for (int i = 0; i < n + n; i++) g[i][j + 1] = g[g[i][j]][j];     for (int i = 0; i < n + n; i++)       if (i >= n) {         int x = i;         ans += 1 + (L[i] > i - n + 1);         for (int j = 19; j >= 0; j--)           if (L[g[x][j]] > i - n + 1) x = g[x][j], ans += 1 << j;       }     printf( %I64d n , ans);     return 0;   }   