func_code_string: #include <bits/stdc++.h>   using namespace std;   const int limite = 100005;   pair<int, int> maximo[limite];   void inserta(int pos, int val) {     pair<int, int> valor(val, pos);     for (; pos < limite; pos += pos & -pos) maximo[pos] = max(maximo[pos], valor);   }   int computamaximo(int pos) {     pair<int, int> maxi(0, 0);     for (; pos > 0; pos -= pos & -pos) maxi = max(maxi, maximo[pos]);     return maxi.second;   }   int n;   int a[limite];   long long int sr[limite];   long long int sol = 0;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i < n; i++) cin >> a[i];     for (int i = n - 1; i >= 1; i--) {       if (a[i] == n)         sr[i] = n - i;       else {         int jmin = computamaximo(a[i]);         sr[i] = a[i] - i + sr[jmin] - (a[i] - jmin) + (n - a[i]);       }       sol += sr[i];       inserta(i, a[i]);     }     cout << sol << endl;   }   