func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX = 999999;   const double Eps = 1e-12;   const double PI = acos(-1.0);   int gcd(int x, int y) { return x % y == 0 ? y : gcd(y, x % y); }   long long pe[2222], key[2222];   char a[100], b[100];   int p[11111];   using namespace std;   int num[200004], ans[200005];   int main() {     int n;     while (cin >> n) {       for (int i = 1; i <= n; i++) scanf( %d , num + i);       memset(ans, -1, sizeof(ans));       ans[1] = 0;       queue<int> q;       q.push(1);       while (!q.empty()) {         int s = q.front();         q.pop();         for (int i = -1; i <= 1; ++i) {           if (i == 0) continue;           int d = s + i;           if (d >= 1 && d <= n && ans[d] == -1) {             ans[d] = ans[s] + 1;             q.push(d);           }         }         int d = num[s];         if (ans[d] == -1) {           ans[d] = ans[s] + 1;           q.push(d);         }       }       cout << ans[1];       for (int i = 2; i <= n; i++) printf(  %d , ans[i]);       puts(  );     }     return 0;   }   