func_code_string: #include <bits/stdc++.h>   using namespace std;   long long int visited1[200005], visited2[200005], step1[200005], step2[200005],       ar[200005];   long long int n;   void fill_array(long long int ar[], long long int value, long long int size) {     for (long long int i = 0; i < size; i++) ar[i] = value;   }   long long int dfs(long long int node, long long int step,                     long long int parent) {     if (step == 1) {       visited1[node] = 1;       if (node + ar[node] > n)         step1[node] = ar[node];       else {         if (visited2[node + ar[node]]) {           if (step2[node + ar[node]] < 0)             step1[node] = -1;           else if (step2[node + ar[node]] == 0)             step1[node] = -1;           else             step1[node] = step2[node + ar[node]] + ar[node];         } else {           long long int temp = dfs(node + ar[node], 2, node);           if (temp < 0)             step1[node] = -1;           else             step1[node] = temp + ar[node];         }       }       return step1[node];     } else {       visited2[node] = 1;       if (node - ar[node] < 1)         step2[node] = ar[node];       else if (node - ar[node] == 1)         step2[node] = -1;       else {         if (visited1[node - ar[node]]) {           if (step1[node - ar[node]] < 0)             step2[node] = -1;           else if (step1[node - ar[node]] == 0)             step2[node] = -1;           else             step2[node] = step1[node - ar[node]] + ar[node];         } else {           long long int temp = dfs(node - ar[node], 1, node);           if (temp < 0)             step2[node] = -1;           else             step2[node] = temp + ar[node];         }       }       return step2[node];     }   }   int main() {     cin >> n;     for (long long int i = 2; i <= n; i++) cin >> ar[i];     fill_array(visited1, 0, n + 1);     fill_array(visited2, 0, n + 1);     fill_array(step1, 0, n + 1);     fill_array(step2, 0, n + 1);     for (long long int i = 2; i <= n; i++) {       if (!visited1[i]) dfs(i, 1, -1);       if (!visited2[i]) dfs(i, 2, -1);     }     for (long long int i = 2; i <= n; i++) {       if (step2[i] == -1)         cout <<  -1 n ;       else         cout << step2[i] + i - 1 << endl;     }     return 0;   }   