#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	int T=1;
	//cin >> T;
	while(T--){
		ll n,y;
		cin>>n;
		ll a[n-1];
		rep(i,n-1){
			cin>>y;
			a[i]=--y;
		}
		int z=(int)log2(n-1)+2;
		ii st[n-1][z]={};
		rep(i,n-1) st[i][0]=mp(a[i],i);
		rep_a(i,1,z){
			for(int j=0;j+(1<<i)<n;j++) st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
		}
		int v[n-1]={0};
		ll ans=0,mx,lmx,l1,k,cnt;
		ii tmp;
		rep(i,n-1){
			if(!v[i]){
				v[i]=1;
				mx=a[i];
				l1=i;
				cnt=1;
				ans+=(n-1-l1);
				lmx=a[i];
				while(lmx<n-1){
					k=(int)log2(lmx-l1+1);
					tmp=max(st[i][k],st[lmx-(1<<k)+1][k]);
					mx=tmp.ff;
					l1=tmp.ss;
					if(!v[l1]){
						v[l1]=1;
						ans+=(lmx-l1);
						cnt++;
					}
					ans+=(cnt*(n-1-lmx));
					lmx=mx;
				}
			}
		}
		cout<<ans<<el;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(ll i=0;i<n;i++)
#define rev(i,n) for(ll i=n;i>=0;i--)
#define rep_a(i,a,n) for(ll i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	int T=1;
	//cin >> T;
	while(T--){
		ll n,y;
		cin>>n;
		ll a[n-1];
		rep(i,n-1){
			cin>>y;
			a[i]=--y;
		}
		ll z=(ll)log2(n-1)+2;
		ii st[n-1][z]={};
		rep(i,n-1) st[i][0]=mp(a[i],i);
		rep_a(i,1,z){
			for(ll j=0;j+(1<<i)<n;j++) st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
		}
		int vis[n-1]={0};
		ll ans=0,mx,lmx,l1,k,cnt;
		ii tmp;
		ll dp[n-1]={};
		vi v,u;
		rep(i,n-1){
			if(!vis[i]){
				//cout<<i<<" "<<":"<<el;
				vis[i]=1;
				mx=a[i];
				l1=i;
				cnt=1;
				ans+=(n-1-l1);
				lmx=a[i];
				while(lmx<n-1){
					k=(ll)log2(lmx-l1+1);
					tmp=max(st[i][k],st[lmx-(1<<k)+1][k]);
					mx=tmp.ff;
					l1=tmp.ss;
					if(!vis[l1]){
						vis[l1]=1;
						ans+=(lmx-l1);
						dp[l1]=lmx-l1;
						cnt++;
					}
					else{
						ans-=(cnt*(lmx-l1));
						ans+=(cnt*dp[l1]);
						if(u.size()>0){
							u[u.size()-1]+=(dp[l1]-(lmx-l1));
						}
						//cout<<ans<<el;
						break;
					}
					ans+=(cnt*(n-1-lmx));
					v.pb(l1);
					u.pb(n-1-lmx);
					lmx=mx;
					//cout<<ans<<el;
				}
				if(v.size()>0){
					ll s=0;
					rev(j,v.size()-1){
						s+=u[j];
						dp[v[j]]+=s;
					}
					v.clear();
					u.clear();
				}
			}
		}
		cout<<ans<<el;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	int T=1;
	//cin >> T;
	while(T--){
		ll n,y;
		cin>>n;
		ll a[n-1];
		rep(i,n-1){
			cin>>y;
			a[i]=--y;
		}
		int z=(int)log2(n-1)+2;
		ii st[n-1][z]={};
		rep(i,n-1) st[i][0]=mp(a[i],i);
		rep_a(i,1,z){
			for(int j=0;j+(1<<i)<n;j++) st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
		}
		int vis[n-1]={0};
		ll ans=0,mx,lmx,l1,k,cnt;
		ii tmp;
		ll dp[n-1]={};
		vi v,u;
		rep(i,n-1){
			if(!vis[i]){
				//cout<<i<<" "<<":"<<el;
				vis[i]=1;
				mx=a[i];
				l1=i;
				cnt=1;
				ans+=(n-1-l1);
				lmx=a[i];
				while(lmx<n-1){
					k=(int)log2(lmx-l1+1);
					tmp=max(st[i][k],st[lmx-(1<<k)+1][k]);
					mx=tmp.ff;
					l1=tmp.ss;
					if(!vis[l1]){
						vis[l1]=1;
						ans+=(lmx-l1);
						dp[l1]=lmx-l1;
						cnt++;
					}
					else{
						ans-=(cnt*(lmx-l1));
						ans+=(cnt*dp[l1]);
						if(u.size()>0){
							u[u.size()-1]+=(dp[l1]-(lmx-l1));
						}
						//cout<<ans<<el;
						break;
					}
					ans+=(cnt*(n-1-lmx));
					v.pb(l1);
					u.pb(n-1-lmx);
					lmx=mx;
					//cout<<ans<<el;
				}
				if(v.size()>0){
					ll s=0;
					rev(j,v.size()-1){
						s+=u[j];
						dp[v[j]]+=s;
					}
					v.clear();
					u.clear();
				}
			}
		}
		cout<<ans<<el;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	int T=1;
	//cin >> T;
	while(T--){
		ll n,y;
		cin>>n;
		ll a[n-1];
		rep(i,n-1){
			cin>>y;
			a[i]=--y;
		}
		int z=(int)log2(n-1)+2;
		ii st[n-1][z]={};
		rep(i,n-1) st[i][0]=mp(a[i],i);
		rep_a(i,1,z){
			for(int j=0;j+(1<<i)<n;j++) st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
		}
		int v[n-1]={0};
		ll ans=0,mx,lmx,l1,k,cnt;
		ii tmp;
		rep(i,n-1){
			if(!v[i]){
				v[i]=1;
				mx=a[i];
				l1=i;
				cnt=1;
				ans+=(n-1-l1);
				lmx=a[i];
				while(lmx<n-1){
					cnt++;
					k=(int)log2(lmx-l1+1);
					tmp=max(st[i][k],st[lmx-(1<<k)+1][k]);
					mx=tmp.ff;
					l1=tmp.ss;
					v[l1]=1;
					ans+=(lmx-l1);
					ans+=(cnt*(n-1-lmx));
					lmx=mx;
				}
			}
		}
		cout<<ans<<el;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(ll i=0;i<n;i++)
#define rev(i,n) for(ll i=n;i>=0;i--)
#define rep_a(i,a,n) for(ll i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w" , stdout);
	#endif
	int T=1;
	//cin >> T;
	while(T--){
		ll n,y;
		cin>>n;
		ll a[n-1];
		rep(i,n-1){
			cin>>y;
			a[i]=--y;
		}
		ll z=(ll)log2(n-1)+2;
		ii st[n-1][z]={};
		rep(i,n-1) st[i][0]=mp(a[i],i);
		rep_a(i,1,z){
			for(ll j=0;j+(1<<i)<n;j++) st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
		}
		int vis[n-1]={0};
		ll ans=0,mx,lmx,l1,k,cnt;
		ii tmp;
		ll dp[n-1]={};
		vi v,u;
		rep(i,n-1){
			if(!vis[i]){
				//cout<<i<<" "<<":"<<el;
				vis[i]=1;
				mx=a[i];
				l1=i;
				cnt=1;
				ans+=(n-1-l1);
				lmx=a[i];
				while(lmx<n-1){
					k=(ll)log2(lmx-l1+1);
					tmp=max(st[l1][k],st[lmx-(1<<k)+1][k]);
					mx=tmp.ff;
					l1=tmp.ss;
					if(!vis[l1]){
						vis[l1]=1;
						ans+=(lmx-l1);
						dp[l1]=lmx-l1;
						cnt++;
					}
					else{
						ans-=(cnt*(lmx-l1));
						ans+=(cnt*dp[l1]);
						if(u.size()>0){
							u[u.size()-1]+=(dp[l1]-(lmx-l1));
						}
						//cout<<ans<<el;
						break;
					}
					ans+=(cnt*(n-1-lmx));
					v.pb(l1);
					u.pb(n-1-lmx);
					lmx=mx;
					//cout<<ans<<el;
				}
				if(v.size()>0){
					ll s=0;
					rev(j,v.size()-1){
						s+=u[j];
						dp[v[j]]+=s;
					}
					v.clear();
					u.clear();
				}
			}
		}
		cout<<ans<<el;

	}

	return 0;
}


#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>

#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second

#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;

    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<ll> dp(n + 1);
        vector<ll> v(n);
        for(i = 1; i < n; i++){
            cin >> v[i];
        }
        dp[n - 1] = 1;
        ll sum = 1;
        for(i = n - 2; i >= 1; i--){
            j = v[i];
            dp[i] = dp[j] + (n - v[i]) + j - i;
            //cout << dp[i] << endl;
            sum += dp[i];
        }
        cout << sum;
    }
    return 0;
}


#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>

#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second

#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 1e5 + 1;
ll m[N][20];
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;

    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<ll> dp(n + 1);
        vector<ll> v(n);
        for(i = 1; i < n; i++){
            cin >> v[i];
        }
        dp[n - 1] = 1;
        ll sum = 1;
        m[n][0] = dp[n] + n;
        m[n - 1][0] = dp[n - 1] + n - 1;
        m[n - 1][1] = min(dp[n] + n, dp[n - 1] + n - 1);
        for(i = n - 2; i >= 1; i--){
            //j = v[i];
            //dp[i] = dp[j] + (n - v[i]) + j - i;
            //cout << dp[i] << endl;
            ll len = v[i] - i;
            ll logy = log2(len);
            ll start = i + 1, end = v[i];
            ll minval = min(m[i + 1][logy], m[end - (1 << logy) + 1][logy]);
            dp[i] = n - v[i] - i + minval;
            sum += dp[i];
            m[i][0] = dp[i] + i;
            for(j = 1; i + (1 << j) - 1 <= n; j++){
                m[i][j] = min(m[i][j - 1], m[i + (1 << (j - 1))][j - 1]);
            }
        }
        cout << sum;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
long long n,v,dp[100005];
pair<long long,long long> a[100005],spar[17][100005];

long long mx(long long x,long long y){
	long long ix = log2(y-x+1);
	pair<long long,long long> sp = max(spar[ix][x],spar[ix][y-(1<<ix)+1]);
	return sp.second;
}

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(long long i=1;i<n;i++){
		cin>>v;
		a[i]={v,i};
	}
	a[n]={n,n};

	for(long long i=1;i<=n;i++){
		spar[0][i] = a[i];
	}
	for(long long i=1;i<=log2(n);i++){
		for(long long j=1;j+(1<<i)-1<=n;j++){
			spar[i][j]=max(spar[i-1][j],spar[i-1][j+(1<<(i-1))]);
			//cout<<i<<" "<<j<<" "<<spar[i-1][j].first<<" "<<spar[i-1][j+(1<<(i-1))].first<<endl;
		}
	}

	long long m;
	dp[n]=0;
	for(long long i=n-1;i>=1;i--){
		m = mx(i+1,a[i].first);
		//cout<<m;
		dp[i] = dp[m]-a[i].first-i+n+m;
		//cout<<dp[i]<<endl;
	}

	long long ans=0;
	for(long long i=1;i<n;i++){
		ans+=dp[i];
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>

using namespace std;
int n,v,dp[100005];
pair<int,int> a[100005],spar[17][100005];

int mx(int x,int y){
	int ix = log2(y-x+1);
	pair<int,int> sp = max(spar[ix][x],spar[ix][y-(1<<ix)+1]);
	return sp.second;
}

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>v;
		a[i]={v,i};
	}
	a[n]={n,n};

	for(int i=1;i<=n;i++){
		spar[0][i] = a[i];
	}
	for(int i=1;i<=log2(n);i++){
		for(int j=1;j+(1<<i)-1<=n;j++){
			spar[i][j]=max(spar[i-1][j],spar[i-1][j+(1<<(i-1))]);
			//cout<<i<<" "<<j<<" "<<spar[i-1][j].first<<" "<<spar[i-1][j+(1<<(i-1))].first<<endl;
		}
	}

	int m;
	dp[n]=0;
	for(int i=n-1;i>=1;i--){
		m = mx(i+1,a[i].first);
		//cout<<m;
		dp[i] = dp[m]-a[i].first-i+n+m;
		//cout<<dp[i]<<endl;
	}

	int ans=0;
	for(int i=1;i<n;i++){
		ans+=dp[i];
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>

#define lp(i,a,b) for(int i = a ; i < b ; i++ )
#define MAXN 100010

using namespace std;

int N ;
int d[MAXN] ;
int a[MAXN] ;

//seg stuff
int v[4*MAXN] ;

void build(int no , int l , int r)
{
  if( l == r ) { v[no] = l ; return ; }
  int mid = ( l + r ) / 2 ;
  build( 2*no , l , mid ) ;
  build( 2*no + 1 , mid+1 , r ) ;
  //merge
  v[no] = v[2*no] ;
  if( a[ v[2*no+1] ] > a[ v[no] ] ) v[no] = v[2*no+1] ;
}

int query( int no , int l , int r , int ini , int fim )
{
  if( l > fim or r < ini ) return MAXN-5 ;

  if( l >= ini && r <= fim ) return v[no] ;

  int mid = ( l + r ) / 2 ;

  int re = query( 2*no , l , mid , ini , fim ) ;
  int rd = query( 2*no+1 , mid+1 , r , ini , fim ) ;

  return (a[re] > a[rd]) ? re : rd ;

}

int recursao( int cara )
{

  if(d[cara] != -1) return d[cara] ;
  if( cara == N-1 ) return d[cara] = 1 ;

  if( a[cara] == N ) return d[cara] = N - cara ;

  int maior = query( 1 , 1 , N-1 , cara+1 , a[cara] ) ;

  int dis = recursao( maior ) + N - cara - a[cara] + maior ;

  return d[cara] = dis ;

}

int main()
{
  scanf("%d", &N ) ;
  lp(i,1,N) scanf( "%d", &a[i] ) ;

  build(1 , 1  , N-1) ;
  memset( d , -1 , sizeof d ) ;
  a[N] = N-1 ;
  a[MAXN-5] = -MAXN ;

  long long ans = 0 ;
  lp(i,1,N) ans += recursao(i) ;
  printf("%lld\n" , ans ) ;

}


#include <bits/stdc++.h>

#define lp(i,a,b) for(int i = a ; i < b ; i++ )
#define MAXN 100010
#define ll long long

using namespace std;

int N ;
ll d[MAXN] ;
int a[MAXN] ;

//seg stuff
int v[4*MAXN] ;

void build(int no , int l , int r)
{
  if( l == r ) { v[no] = l ; return ; }
  int mid = ( l + r ) / 2 ;
  build( 2*no , l , mid ) ;
  build( 2*no + 1 , mid+1 , r ) ;
  //merge
  v[no] = v[2*no] ;
  if( a[ v[2*no+1] ] > a[ v[no] ] ) v[no] = v[2*no+1] ;
}

int query( int no , int l , int r , int ini , int fim )
{
  if( l > fim or r < ini ) return MAXN-5 ;

  if( l >= ini && r <= fim ) return v[no] ;

  int mid = ( l + r ) / 2 ;

  int re = query( 2*no , l , mid , ini , fim ) ;
  int rd = query( 2*no+1 , mid+1 , r , ini , fim ) ;

  return (a[re] > a[rd]) ? re : rd ;

}

ll recursao( int cara )
{

  if(d[cara] != -1) return d[cara] ;
  if( cara == N-1 ) return d[cara] = 1 ;

  if( a[cara] == N ) return d[cara] = N - cara ;

  int maior = query( 1 , 1 , N-1 , cara+1 , a[cara] ) ;

  ll dis = recursao( maior ) + N - cara - a[cara] + maior ;

  return d[cara] = dis ;

}

int main()
{
  scanf("%d", &N ) ;
  lp(i,1,N) scanf( "%d", &a[i] ) ;

  build(1 , 1  , N-1) ;
  memset( d , -1 , sizeof d ) ;
  a[N] = N-1 ;
  a[MAXN-5] = -MAXN ;

  long long ans = 0 ;
  lp(i,1,N) ans += recursao(i) ;
  printf("%lld\n" , ans ) ;

}


#include <bits/stdc++.h>

#define lp(i,a,b) for(int i = a ; i < b ; i++ )
#define MAXN 100005

using namespace std;

int N ;
int d[MAXN] ;
int a[MAXN] ;

//seg stuff
int v[4*MAXN] ;

void build(int no , int l , int r)
{
  if( l == r ) { v[no] = l ; return ; }
  int mid = ( l + r ) / 2 ;
  build( 2*no , l , mid ) ;
  build( 2*no + 1 , mid+1 , r ) ;
  //merge
  v[no] = v[2*no] ;
  if( a[ v[2*no+1] ] > a[ v[no] ] ) v[no] = v[2*no+1] ;
}

int query( int no , int l , int r , int ini , int fim )
{
  if( l > fim or r < ini ) return -MAXN ;

  if( l >= ini && r <= fim ) return v[no] ;

  int mid = ( l + r ) / 2 ;

  int re = query( 2*no , l , mid , ini , fim ) ;
  int rd = query( 2*no+1 , mid+1 , r , ini , fim ) ;

  return (a[re] > a[rd]) ? re : rd ;

}

int recursao( int cara )
{

  if(d[cara] != -1) return d[cara] ;
  if( cara == N-1 ) return d[cara] = 1 ;

  if( a[cara] == N ) return d[cara] = N - cara ;

  int maior = query( 1 , 1 , N-1 , cara+1 , a[cara] ) ;

  int dis = recursao( maior ) + a[cara] - cara - (a[cara] - maior) + N - cara - 1;

  return d[cara] = dis ;

}

int main()
{
  scanf("%d", &N ) ;
  lp(i,1,N) scanf( "%d", &a[i] ) ;

  build(1 , 1  , N-1) ;
  memset( d , -1 , sizeof d ) ;
  a[N] = N-1 ;

  long long ans = 0 ;
  lp(i,1,N) ans += recursao(i) ;
  printf("%lld\n" , ans ) ;

}


#include<bits/stdc++.h>
#define z 100001
#define ll long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int a[n+1];for(int i=1;i<n;i++)cin>>a[i];
    a[n]=0;
    int dp[n+1];
    ll sum=0;

        int j=2,co=0,maxi,tmp=a[1];
        while(j<=n)
        {
            co++;maxi=tmp;
        while(j<=n && j<=maxi)
        {
            sum+=co;
            dp[j]=co;
            if(a[j]>tmp)tmp=a[j];
            j++;
        }
        }
    int prev=sum;
     for(int i=2;i<n;i++)
     {
         int add;
         if(dp[i]!=dp[i+1])
            add=prev-1-(n-i);
         else add=prev-1;
         prev=add;
         sum+=add;
     }
    cout<<sum<<"\n";
}


#include<bits/stdc++.h>
#define z 100001
#define ll long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int a[n+1];for(int i=1;i<n;i++)cin>>a[i];
    a[n]=0;
    //int dp[n][n+1];
    ll sum=0;
    for(int i=1;i<n;i++)
    {
        int j=i+1,co=0,maxi,tmp=a[i];
        while(j<=n)
        {
            co++;maxi=tmp;
        while(j<=n && j<=maxi)
        {
            sum+=co;
            if(a[j]>tmp)tmp=a[j];
            j++;
        }
        }

    }
    cout<<sum<<"\n";
}


#include<bits/stdc++.h>
#define z 100001
#define ll long long
using namespace std;
int n;
vector<int> a(z);
vector<vector<int> > t(z,vector<int>(21));
void build()
{
    int k=ceil(log2(n));
   for(int i=0;i<n;i++)t[i][0]=a[i];
   for(int j=1;j<=k;j++)
   {
       for(int i=0;(i+(1<<j))<=n;i++)
           t[i][j]=max(t[i][j-1],t[i+(1<<(j-1))][j-1]);
   }
}
int query(int l,int r)
{
        int j=log2(r-l+1);
        return max(t[l][j],t[r-(1<<j)+1][j]);
}
int main()
{
   // ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n-1;i++)
    {cin>>a[i];
    }
    for(int i=0;i<n-1;i++)
    a[i]-=1;
    a[n-1]=0;
    build();
    ll sum=0;

    for(int i=0;i<n-1;i++)
    {
         int j=i+1,co=0,maxi=a[i];
        while(j<n)
        {
            co++;
            sum+=co*(maxi-j+1);
            int tmp=maxi+1;
            maxi=query(j,maxi);
            j=tmp;
           // cout<<i<<" "<<j<<" "<<sum<<" "<<maxi<<endl;
        }
    }
    cout<<sum<<"\n";
}


#include<bits/stdc++.h>
#define z 100001
#define ll long long
using namespace std;
int n;
vector<int> a(z);
vector<vector<int> > t(z,vector<int>(21)),pos(z,vector<int>(21));
void build()
{
    int k=ceil(log2(n));
   for(int i=0;i<n;i++){t[i][0]=a[i];pos[i][0]=i;}
   for(int j=1;j<=k;j++)
   {
       for(int i=0;(i+(1<<j))<=n;i++)
       {
           if(t[i][j-1]>=t[i+(1<<(j-1))][j-1])
           {
               pos[i][j]=pos[i][j-1];
               t[i][j]=t[i][j-1];
           }
            else
            {
               pos[i][j]=pos[i+(1<<(j-1))][j-1];
               t[i][j]=t[i+(1<<(j-1))][j-1];
            }

       }
   }
}
pair<int,int> query(int l,int r)
{
        int j=log2(r-l+1);
        if(t[l][j]>=t[r-(1<<j)+1][j])
            return make_pair(pos[l][j],t[l][j]);
        else
        return make_pair(pos[r-(1<<j)+1][j],t[r-(1<<j)+1][j]);
}
int main()
{
   // ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n-1;i++)
    {cin>>a[i];
    }
    for(int i=0;i<n-1;i++)
    a[i]-=1;
    a[n-1]=0;
    build();
    ll sum=0;
    vector<ll> dp(n);dp[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        pair<int,int> tmp=query(i+1,a[i]);
        int p=tmp.first,maxi=tmp.second;
      //  cout<<"max"<<p<<endl;
        ll add=p-i+dp[p]+(n-p-1)-(a[i]-p);
        sum+=add;
        dp[i]=add;
       // cout<<i<<" "<<add<<endl;
    }
    cout<<sum<<"\n";
}


#include<bits/stdc++.h>
#define z 100001
#define ll long
using namespace std;
int n;
vector<int> a(z);
vector<vector<int> > t(z,vector<int>(21));
void build()
{
    int k=ceil(log2(n));
   for(int i=0;i<n;i++)t[i][0]=a[i];
   for(int j=1;j<=k;j++)
   {
       for(int i=0;(i+(1<<j))<=n;i++)
           t[i][j]=max(t[i][j-1],t[i+(1<<(j-1))][j-1]);
   }
}
int query(int l,int r)
{
        int j=log2(r-l+1);
        return max(t[l][j],t[r-(1<<j)+1][j]);
}
int main()
{
   // ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n-1;i++)
    {cin>>a[i];
    }
    for(int i=0;i<n-1;i++)
    a[i]-=1;
    a[n-1]=0;
    build();
    ll sum=0;

    for(int i=0;i<n-1;i++)
    {
         int j=i+1,co=0,maxi=a[i];
        while(j<n)
        {
            co++;
            sum+=co*(maxi-j+1);
            int tmp=maxi+1;
            maxi=query(j,maxi);
            j=tmp;
           // cout<<i<<" "<<j<<" "<<sum<<" "<<maxi<<endl;
        }
    }
    cout<<sum<<"\n";
}


// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long double ld;
typedef long long int lli;
typedef pair <lli, lli> pii;
#define pb push_back
#define recout(x) return cout << (x), 0
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
#define all(x) x.begin(), x.end()
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const lli N = 1e5 + 10, N2 = 2e5, delta = 10499, mod = 1e9 + 7, oo = 1e18, LOG = 20, SQ = 300;
const ld PI = 3.141592653589793;

lli a[N], dp[N], rmq[LOG][N];

lli get (lli l, lli r) {
	lli x = 31 - __builtin_clz(r - l);
	return (a[rmq[x][l]] < a[rmq[x][r - (1 << x)]]? rmq[x][r - (1 << x)]: rmq[x][l]);
}

int32_t main() {
	fast;
	lli n, ans = 0;
	cin >> n;
	for (lli i = 0; i < n - 1; i++)
		cin >> a[i];
	for (lli i = 0; i < LOG; i++) {
		if (!i)
			for (lli j = 0; j < n; j++)
				rmq[i][j] = j;
		else
			for (lli j = 0; j < n - (1 << i); j++) {
				if (a[rmq[i - 1][j]] < a[rmq[i - 1][j + (1 << i - 1)]])
					rmq[i][j] = rmq[i - 1][j + (1 << i - 1)];
				else
					rmq[i][j] = rmq[i - 1][j];
			}
	}
	for (lli i = n - 2; ~i; i--) {
		if (a[i] == n) {
			//cout << ":)))   ";
			dp[i] = n - i - 1;
		}
		else {
			//cout << ":(((   ";
			lli p = get(i, a[i]);
			dp[i] = dp[p] - (a[i] - p - 1) + n - i - 1;
			//cout << p + 1 << ' ';
		}
		//cout << i << ' ' << dp[i] << '\n';
		ans += dp[i];
	}
	cout << ans << '\n';
	return 0;
}


// " --- IN THE NAME OF ALLAH --- " // ;)
// ------------sphr_agz------------ // ;)
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long double ld;
typedef long long int lli;
typedef pair <lli, lli> pii;
#define pb push_back
#define recout(x) return cout << (x), 0
#define f first
#define s second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define stp(x) cout << setprecision(x) << fixed
#define mk make_pair
#define all(x) x.begin(), x.end()
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const lli N = 1e5 + 10, N2 = 2e5, delta = 10499, mod = 1e9 + 7, oo = 1e18, LOG = 20, SQ = 300;
const ld PI = 3.141592653589793;

lli a[N], dp[N], rmq[LOG][N];

lli get (lli l, lli r) {
	lli x = __builtin_ctz(r - l);
	return max (rmq[x][l], rmq[x][r - (1 << x) + 1]);
}

int32_t main() {
	fast;
	lli n, ans = 0;
	cin >> n;
	for (lli i = 0; i < n - 1; i++)
		cin >> a[i];
	for (lli i = 0; i < LOG; i++) {
		if (!i)
			for (lli j = 0; j < n; j++)
				rmq[i][j] = a[j];
		else
			for (lli j = 0; j < n - (1 << i); j++)
				rmq[i][j] = max (rmq[i - 1][j], rmq[i - 1][j + (1 << i - 1)]);
	}
	for (lli i = n - 2; ~i; i--) {
		if (a[i] == n)
			dp[i] = n - i - 1;
		else {
			lli p = get(i, a[i]);
			dp[i] = dp[p] - (a[i] - p) + n - i;
		}
		ans += dp[i];
	}
	cout << ans << '\n';
	return 0;
}


/* Manish Pant - insider_pants */

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

#define F first
#define S second
#define endl "\n"
#define pb push_back
typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int N = 1e5 + 5;
int n;
vector<int> v(N);
vector<pii> segtree(4 * N);
vector<ll> dp(N);

void build(int node = 0, int l = 1, int r = n)
{
    if(l == r)
    {
        segtree[node] = make_pair(v[l], l);
        return;
    }
    int mid = (l + r) >> 1;
    build(2 * node + 1, l, mid);
    build(2 * node + 2, mid + 1, r);

    segtree[node] = max(segtree[2 * node + 1], segtree[2 * node + 2]);
}

pii query(int x, int y, int node = 0, int l = 1, int r = n)
{
    if(l > y || r < x || x > y)
        return make_pair(0, 0);
    if(x <= l && r <= y)
        return segtree[node];

    int mid = (l + r) >> 1;
    return max(query(x, y, 2 * node + 1, l, mid), query(x, y, 2 * node + 2, mid + 1, r));
}

void solve()
{
    build();
    dp[n] = 0;
    for(int i = n - 1; i > 0; i--)
    {
        pii temp = query(i + 1, v[i]);
        dp[i] = dp[temp.S] - v[i] + temp.S + n - i;
    }

    cout << accumulate(dp.begin(), dp.end(), 0LL) << endl;
}

int main()
{
    fast();
    cin >> n;
    for(int i = 1; i < n; i++)
        cin >> v[i];
    v[n] = n;
    solve();
}


/* Manish Pant - insider_pants */

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

#define F first
#define S second
#define endl "\n"
#define pb push_back
typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int N = 1e5 + 5;
int n;
vector<int> v(N);
vector<pii> segtree(4 * N);
vector<ll> dp(N);

void build(int node = 0, int l = 1, int r = n)
{
    if(l == r)
    {
        segtree[node] = make_pair(v[l], l);
        return;
    }
    int mid = (l + r) >> 1;
    build(2 * node + 1, l, mid);
    build(2 * node + 2, mid + 1, r);

    segtree[node] = max(segtree[2 * node + 1], segtree[2 * node + 2]);
}

pii query(int x, int y, int node = 0, int l = 1, int r = n)
{
    if(l > y || r < x || x > y)
        return make_pair(0, 0);
    if(x <= l && r <= y)
        return segtree[node];

    int mid = (l + r) >> 1;
    return max(query(x, y, 2 * node + 1, l, mid), query(x, y, 2 * node + 2, mid + 1, r));
}

void solve()
{
    build();
    dp[n] = 0;
    for(int i = n - 1; i > 0; i--)
    {
        pii temp = query(i + 1, v[i]);
        dp[i] = dp[temp.S] - v[i] + temp.S + n - i;
    }

    cout << accumulate(dp.begin(), dp.end(), 0) << endl;
}

int main()
{
    fast();
    cin >> n;
    for(int i = 1; i < n; i++)
        cin >> v[i];
    v[n] = n;
    solve();
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma optimize("-O3")
using namespace std;
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(ll i =(ll)j; i!=(ll)k; i = i + l)
#define INP(v,n) f(i,1,n+1,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int N = 100005;
int st[4*N];
int a[N],n;
ll an[N];
ll ans = 0;
void ct(int lo, int hi, int pos){
	if(lo == hi){
		st[pos] = lo;
		return;
	}
	int mid = (lo + hi)/2;
	ct(lo, mid, 2*pos + 1);
	ct(mid+1, hi, 2*pos + 2);
	if(a[st[2*pos+1]] > a[st[2*pos+2]]){
		st[pos] = st[2*pos+1];
	}else st[pos] = st[2*pos+2];
	return;
}

int rq(int qlo, int qhi, int lo, int hi, int pos){
	if(lo > qhi || hi < qlo){
		return n;
	}
	if(lo >= qlo && hi <= qhi){
		return st[pos];
	}
	int mid = (hi + lo)/2;
	int l =rq(qlo,qhi,lo,mid,2*pos + 1),r= rq(qlo, qhi, mid+1, hi, 2*pos+2);
	if(st[l] > st[r]){
		r = l;
	}
	return r;
}

void solve(){
	cin>>n;
	INP(a,n-1);
	a[n] = -1;
	ct(1,n-1,0);
	an[n] = 0;
	f(i,n-1,0,-1){
		if(a[i] == n){
			an[i] = 1ll*(n-i);
			ans += an[i];
			continue;
		}
		int j = rq(i+1,a[i],1,n-1,0);
		an[i] = an[j]+1ll*(n-a[i]) + 1ll*(j-i);
		ans += an[i];
	}
	cout<<ans<<endl;
}

int main(){
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t = 1;
	while(t--){
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma optimize("-O3")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(ll i =(ll)j; i!=(ll)k; i = i + l)
#define INP(v,n) f(i,1,n+1,1) cin>>v[i];
#define OUT(v,n) f(i,1,n+1,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int N = 100005;
int st[4*N];
int a[N],n;
ll an[N];
ll ans = 0;
void ct(int lo, int hi, int pos){
	if(lo == hi){
		st[pos] = lo;
		return;
	}
	int mid = (lo + hi)/2;
	ct(lo, mid, 2*pos + 1);
	ct(mid+1, hi, 2*pos + 2);
	if(a[st[2*pos+1]] > a[st[2*pos+2]]){
		st[pos] = st[2*pos+1];
	}else st[pos] = st[2*pos+2];
	return;
}

int rq(int qlo, int qhi, int lo, int hi, int pos){
	if(lo > qhi || hi < qlo){
		return n;
	}
	if(lo >= qlo && hi <= qhi){
		return st[pos];
	}
	int mid = (hi + lo)/2;
	int l =rq(qlo,qhi,lo,mid,2*pos + 1),r= rq(qlo, qhi, mid+1, hi, 2*pos+2);
	// if(qlo == qhi && qlo == 9) trace(qlo,qhi,lo,pos,st[pos],l,r);
	if(a[l] > a[r]){
		r = l;
	}
	// if(qlo == qhi && qlo == 9) trace(qlo,qhi,lo,pos,st[pos],l,r);
	return r;
}

void solve(){
	cin>>n;
	INP(a,n-1);
	a[n] = -1;
	ct(1,n-1,0);
	an[n] = 0;
	f(i,n-1,0,-1){
		if(a[i] == n){
			an[i] = 1ll*(n-i);
			ans += an[i];
			continue;
		}
		int j = rq(i+1,a[i],1,n-1,0);
		trace(i,a[i],j,a[j],an[j]);
		an[i] = an[j]+1ll*(n-a[i]) + 1ll*(j-i);
		ans += an[i];
	}
	// OUT(an,n-1);
	cout<<ans<<endl;
}

int main(){
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t = 1;
	while(t--){
		solve();
	}
}


#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ ";
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ ";
  for(auto s:S) os<<s<<" ";  return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair

const int mod = 1e9+7;

inline int add(int a,int b){a+=b;if(a>=mod)a-=mod; return a;}
inline int sub(int a,int b){a-=b;if(a<0) a += mod; return a;}
inline int mul(int a, int b){ return a*1ll*b%mod;}
inline int power(int x, ll y){
  int res = 1;
  while(y){
    if(y&1) res = mul(res , x);
    x = mul(x,x);
    y >>= 1;
  }
  return res;
}

const int N = 1e5 + 100;

pii seg[4*N];
int A[N];
ll dp[N];

void build(int i, int l, int r){
  if(l == r){
    seg[i] = mp(l, A[l]);
    return;
  }
  int m = (l+r)>>1;
  build(2*i, l , m);
  build(2*i+1 , m+1 , r);
  if(seg[2*i].S > seg[2*i+1].S){
    seg[i] = seg[2*i];
  }
  else{
    seg[i] = seg[2*i+1];
  }
}

pii get(int i,int l, int r,int L, int R){
  if(l  > R || r< L) return make_pair(0,0);
  else if(l >= L && r <= R) return seg[i];
  int m = (l+r)>>1;
  pii lft = get(2*i , l , m , L , R);
  pii rht = get(2*i+1 , m+1 , r , L , R);
  if(lft.S < rht.S) return rht;
  else return lft;
}

int main(){
  fio; cout<<fixed<<setprecision(25);
  int n; cin >> n;
  for(int i = 1 ;i <= n-1 ; ++i){
    cin >> A[i];
  }
  A[n] = n;
  build(1 , 1 , n);
  ll ans = 0;
  for(int i = n-1 ;i >= 1 ; --i){
    pii p = get(1 , 1 , n , i+1 , A[i]);
    //cout << i << ' ' << p << endl;
    dp[i] = dp[p.F] + (A[i]-i)+1 - (A[i]- p.first);
    ans += dp[i];
  }
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ ";
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ ";
  for(auto s:S) os<<s<<" ";  return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair

const int mod = 1e9+7;

inline int add(int a,int b){a+=b;if(a>=mod)a-=mod; return a;}
inline int sub(int a,int b){a-=b;if(a<0) a += mod; return a;}
inline int mul(int a, int b){ return a*1ll*b%mod;}
inline int power(int x, ll y){
  int res = 1;
  while(y){
    if(y&1) res = mul(res , x);
    x = mul(x,x);
    y >>= 1;
  }
  return res;
}

const int N = 1e5 + 100;

pii seg[4*N];
int A[N];
ll dp[N];

void build(int i, int l, int r){
  if(l == r){
    seg[i] = mp(l, A[l]);
    return;
  }
  int m = (l+r)>>1;
  build(2*i, l , m);
  build(2*i+1 , m+1 , r);
  if(seg[2*i].S > seg[2*i+1].S){
    seg[i] = seg[2*i];
  }
  else{
    seg[i] = seg[2*i+1];
  }
}

pii get(int i,int l, int r,int L, int R){
  if(l  > R || r< L) return make_pair(0,0);
  else if(l >= L && r <= R) return seg[i];
  int m = (l+r)>>1;
  pii lft = get(2*i , l , m , L , R);
  pii rht = get(2*i+1 , m+1 , r , L , R);
  if(lft.S < rht.S) return rht;
  else return lft;
}

int main(){
  fio; cout<<fixed<<setprecision(25);
  int n; cin >> n;
  for(int i = 1 ;i <= n-1 ; ++i){
    cin >> A[i];
  }
  A[n] = n;
  build(1 , 1 , n);
  ll ans = 0;
  for(ll i = n-1 ;i >= 1 ; --i){
    pll p = get(1 , 1 , n , i+1 , A[i]);
    //cout << i << ' ' << p << endl;
    dp[i] = dp[p.F] + (p.first-i) + (n-A[i]);
    //cout << i << ' ' << dp[i] << endl;
    ans += dp[i];
  }
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int N = 5e3 + 10;

ll n, dp[N], seg[N << 2], a[N];

void build(int id = 1, int b = 0, int e = n) {
	if(e - b == 1) {
		seg[id] = b;
		return;
	}
	int mid = (b + e) >> 1;
	build(id * 2, b, mid);
	build(id*2+1, mid, e);
	int left = seg[id * 2], right = seg[id*2+1];
	seg[id] = ((a[left] > a[right])? left : right);
	return;
}

int get(int l, int r, int id = 1, int b = 0, int e = n) {
	if(l >= e || b >= r)
		return -1;
	if(l <= b && e <= r)
		return seg[id];
	int mid = (b + e) >> 1;
	int left = get(l, r, id * 2, b, mid);
	int right = get(l, r, id*2+1, mid, e);
	if(left == -1)
		return right;
	if(right == -1)
		return left;
	return ((a[left] > a[right])? left : right);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	build();
	ll ans = 0;
	for (int i = n - 2; ~i; i--) {
		int mx = get(i + 1, a[i] + 1);
		dp[i] = dp[mx] - (a[i] - mx) + n - i - 1;
		ans += dp[i];
	}
	cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int N = 1e5 + 10;

ll n, dp[N], seg[N << 2], a[N];

void build(int id = 1, int b = 0, int e = n) {
	if(e - b == 1) {
		seg[id] = b;
		return;
	}
	int mid = (b + e) >> 1;
	build(id * 2, b, mid);
	build(id*2+1, mid, e);
	int left = seg[id * 2], right = seg[id*2+1];
	seg[id] = ((a[left] > a[right])? left : right);
	return;
}

int get(int l, int r, int id = 1, int b = 0, int e = n) {
	if(l >= e || b >= r)
		return -1;
	if(l <= b && e <= r)
		return seg[id];
	int mid = (b + e) >> 1;
	int left = get(l, r, id * 2, b, mid);
	int right = get(l, r, id*2+1, mid, e);
	if(left == -1)
		return right;
	if(right == -1)
		return left;
	return ((a[left] > a[right])? left : right);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	build();
	ll ans = 0;
	for (int i = n - 2; ~i; i--) {
		int mx = get(i + 1, a[i] + 1);
		dp[i] = dp[mx] - (a[i] - mx) + n - i - 1;
		ans += dp[i];
	}
	cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int N = 5e3 + 10;

ll n, dp[N], seg[N << 2], a[N];

void build(int id = 1, int b = 0, int e = n) {
	if(e - b == 1) {
		seg[id] = b;
		return;
	}
	int mid = (b + e) >> 1;
	build(id * 2, b, mid);
	build(id*2+1, mid, e);
	int left = seg[id * 2], right = seg[id*2+1];
	seg[id] = ((a[left] > a[right])? left : right);
	return;
}

int get(int l, int r, int id = 1, int b = 0, int e = n) {
	if(l >= e || b >= r)
		return -1;
	if(l <= b && e <= r)
		return seg[id];
	int mid = (b + e) >> 1;
	int left = get(l, r, id * 2, b, mid);
	int right = get(l, r, id*2+1, mid, e);
	if(left == -1)
		return right;
	if(right == -1)
		return left;
	return ((a[left] > a[right])? left : right);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i];
	}
	a[n - 1] = n - 1;
	build();
// a[i] baste baz
	for (int i = n - 2; ~i; i--) {
		int mx = get(i + 1, a[i]);
		dp[i] = dp[mx] - (a[i] - mx - 1) + n - i + 1;
	}
	cout << dp[0] << "\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int N = 5e3 + 10;

ll n, dp[N], seg[N << 2], a[N];

void build(int id = 1, int b = 0, int e = n) {
	if(e - b == 1) {
		seg[id] = b;
		return;
	}
	int mid = (b + e) >> 1;
	build(id * 2, b, mid);
	build(id*2+1, mid, e);
	int left = seg[id * 2], right = seg[id*2+1];
	seg[id] = ((a[left] > a[right])? left : right);
	return;
}

int get(int l, int r, int id = 1, int b = 0, int e = n) {
	if(l >= e || b >= r)
		return -1;
	if(l <= b && e <= r)
		return seg[id];
	int mid = (b + e) >> 1;
	int left = get(l, r, id * 2, b, mid);
	int right = get(l, r, id*2+1, mid, e);
	if(left == -1)
		return right;
	if(right == -1)
		return left;
	return ((a[left] > a[right])? left : right);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	build();
// a[i] baste baz
	for (int i = n - 2; ~i; i--) {
		int mx = get(i + 1, a[i] + 1);
		dp[i] = dp[mx] - (a[i] - mx) + n - i + 1;
	}
	cout << dp[0] + n - 3 << "\n";
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
typedef long long ll;
typedef pair<int,int>pii;
const int N = 1e5;
pii tree[N+100];
int dp[N+100],a[N+100];

void update(int idx,int val)
{
	int cur = idx;
	while(idx<=N)
	{
		tree[idx] = max(tree[idx],mp(val,cur));
		idx += (idx&-idx);
	}
}
pii query(int idx)
{
	pii mx = mp(0,0);
	while(idx>0)
	{
		mx = max(tree[idx],mx);
		idx -= (idx&-idx);
	}
	return mx;
}
int main()
{
	int n;
	ll ans = 0;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d",a+i);
	}
	dp[n-1] = 1;
	update(n-1,a[n-1]);
	for(int i=n-2;i>0;i--){
		pii mx = query(a[i]);
		dp[i] = dp[mx.second]-(a[i]-mx.second)+n-i;
		ans += dp[i];
		update(i,a[i]);
	}
	printf("%lld\n",ans+1);
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
typedef long long ll;
typedef pair<int,int>pii;
const int N = 1e5;
pii tree[N+100];
ll dp[N+100];
int a[N+100];

void update(int idx,int val)
{
	int cur = idx;
	while(idx<=N)
	{
		tree[idx] = max(tree[idx],mp(val,cur));
		idx += (idx&-idx);
	}
}
pii query(int idx)
{
	pii mx = mp(0,0);
	while(idx>0)
	{
		mx = max(tree[idx],mx);
		idx -= (idx&-idx);
	}
	return mx;
}
int main()
{
	int n;
	ll ans = 0;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d",a+i);
	}
	dp[n-1] = 1;
	update(n-1,a[n-1]);
	for(int i=n-2;i>0;i--){
		pii mx = query(a[i]);
		dp[i] = dp[mx.second]-(a[i]-mx.second)+n-i;
		ans += dp[i];
		update(i,a[i]);
	}
	printf("%lld\n",ans+1);
}


//#pragma GCC optimize("Ofast,unroll-loops,fast-math,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt")
//#pragma GCC target("avx,avx2")
// #define INTER

#include <bits/stdc++.h>

//----------------------------------------------------------------
typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

std::random_device rd;
std::mt19937 Random(rd());
const int inf = 0x3f3f3f3f;
const ll llinf = 2e18;
const ld eps = 1e-15;
const ll mod = 1e9 + 7;

//----------------------------------------------------------------
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fast_io std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0), std::cerr.tie(0);
#define debug(x) std::cerr << #x << ": " << x << '\n'
#define PROBLEM "task"
#define mp std::make_pair

long long mx(long long &a, long long b) { return (a > b ? a : a = b); }
int mx(int &a, int b) { return (a > b ? a : a = b); }
long long mn(long long &a, long long b) { return (a < b ? a : a = b); }
int mn(int &a, int b) { return (a < b ? a : a = b); }
//----------------------------------------------------------------

namespace Kon567889 {
    template <class A, class B>
    std::ostream &operator<<(std::ostream &out, std::pair<A, B> &p) {
        return out << p.first << ' ' << p.second;
    }
    template <class A, class B>
    std::istream &operator>>(std::istream &in, std::pair<A, B> &p) {
        return in >> p.first >> p.second;
    }
    template <class T>
    std::ostream &operator<<(std::ostream &out, std::vector<T> &a) {
        for (auto &i : a) out << i << ' ';
        return out;
    }
    template <class T>
    std::istream &operator>>(std::istream &in, std::vector<T> &a) {
        for(auto &i : a) in >> i;
        return in;
    }
}
using namespace Kon567889;

class SegmentTree {
private:
    struct Node {
        int v, ind, l, r;

        Node() : v(0), ind(-1), l(-1), r(-1) {}
        Node(int v, int ind, int l, int r) : v(v), ind(ind), l(l), r(r) {}

        Node operator+(const Node &a) const {
            return Node(std::max(v, a.v), (v >= a.v ? ind : a.ind), l, a.r);
        };
    };

    Node tree[4 * (1 << 17)];
public:

    void build(int v, int l, int r) {
        if(l == r) {
            tree[v] = { 0, l, l, r };
            return;
        }
        int m = (l + r) / 2;
        build(2 * v, l, m);
        build(2 * v + 1, m + 1, r);
        tree[v] = tree[2 * v] + tree[2 * v +  1];
    }

    SegmentTree(int n) { build(1, 0, n - 1); }

    Node get(int v, int l, int r) {
        if(r < tree[v].l || tree[v].r < l) return Node();
        if(l <= tree[v].l && tree[v].r <= r) return tree[v];
        return get(2 * v, l, r) + get(2 * v + 1, l, r);
    }

    void upd(int v, int i, int d) {
        if(tree[v].l == tree[v].r) {
            tree[v].v = d;
            return;
        }
        upd(2 * v + (i >= tree[2 * v + 1].l), i, d);
        tree[v] = tree[2 * v] + tree[2 * v + 1];
    }
};

const int N = 200000;
int a[N];
ll dp[N];

int32_t main() {
    #ifndef DEBUG
        #ifndef INTER
            fast_io;
        #endif
    #else
        freopen(PROBLEM".in", "r", stdin);
    #endif

    std::cout << std::setprecision(10) << std::fixed;
    std::cerr << std::setprecision(10) << std::fixed;
    ld START_TIME = clock();

    int n;
    std::cin >> n;
    SegmentTree st(n);
    for(int i = 0; i < n - 1; i++) {
        std::cin >> a[i];
        a[i]--;
        st.upd(1, i, a[i]);
    }
    a[n - 1] = n - 1;
    dp[n - 1] = 0;
    st.upd(1, n - 1, n - 1);
    ll ans = 0;
    for(int i = n - 2; i >= 0; i--) {
        auto res = st.get(1, i + 1, a[i]);
        auto [val, ind, l111231, r321312312] = res;
        dp[i] = 0ll + dp[ind] + (n - ind) - (a[i] - ind) + (ind - i - 1);
        // dp[i] = dp[ind] + n - a[i] + ind - i - 1
        // std::cout << res.v << ' ' << res.ind << '\n';
        ans += dp[i];
        // debug(i);
        // debug(ind);
        // debug(dp[i]);
    }

    std::cout << ans;

    std::cerr << '\n';
    ld TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    debug(TIME);
    return 0;
}


//#pragma GCC optimize("Ofast,unroll-loops,fast-math,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt")
//#pragma GCC target("avx,avx2")
// #define INTER

#include <bits/stdc++.h>

//----------------------------------------------------------------
typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

std::random_device rd;
std::mt19937 Random(rd());
const int inf = 0x3f3f3f3f;
const ll llinf = 2e18;
const ld eps = 1e-15;
const ll mod = 1e9 + 7;

//----------------------------------------------------------------
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fast_io std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0), std::cerr.tie(0);
#define debug(x) std::cerr << #x << ": " << x << '\n'
#define PROBLEM "task"
#define mp std::make_pair

long long mx(long long &a, long long b) { return (a > b ? a : a = b); }
int mx(int &a, int b) { return (a > b ? a : a = b); }
long long mn(long long &a, long long b) { return (a < b ? a : a = b); }
int mn(int &a, int b) { return (a < b ? a : a = b); }
//----------------------------------------------------------------

namespace Kon567889 {
    template <class A, class B>
    std::ostream &operator<<(std::ostream &out, std::pair<A, B> &p) {
        return out << p.first << ' ' << p.second;
    }
    template <class A, class B>
    std::istream &operator>>(std::istream &in, std::pair<A, B> &p) {
        return in >> p.first >> p.second;
    }
    template <class T>
    std::ostream &operator<<(std::ostream &out, std::vector<T> &a) {
        for (auto &i : a) out << i << ' ';
        return out;
    }
    template <class T>
    std::istream &operator>>(std::istream &in, std::vector<T> &a) {
        for(auto &i : a) in >> i;
        return in;
    }
}
using namespace Kon567889;

class SegmentTree {
private:
    struct Node {
        int v, ind, l, r;

        Node() : v(0), ind(-1), l(-1), r(-1) {}
        Node(int v, int ind, int l, int r) : v(v), ind(ind), l(l), r(r) {}

        Node operator+(const Node &a) const {
            return Node(std::max(v, a.v), (v >= a.v ? ind : a.ind), l, a.r);
        };
    };

    Node tree[4 * (1 << 17)];
public:

    void build(int v, int l, int r) {
        if(l == r) {
            tree[v] = { 0, l, l, r };
            return;
        }
        int m = (l + r) / 2;
        build(2 * v, l, m);
        build(2 * v + 1, m + 1, r);
        tree[v] = tree[2 * v] + tree[2 * v +  1];
    }

    SegmentTree(int n) { build(1, 0, n - 1); }

    Node get(int v, int l, int r) {
        if(r < tree[v].l || tree[v].r < l) return Node();
        if(l <= tree[v].l && tree[v].r <= r) return tree[v];
        return get(2 * v, l, r) + get(2 * v + 1, l, r);
    }

    void upd(int v, int i, int d) {
        if(tree[v].l == tree[v].r) {
            tree[v].v = d;
            return;
        }
        upd(2 * v + (i >= tree[2 * v + 1].l), i, d);
        tree[v] = tree[2 * v] + tree[2 * v + 1];
    }
};

const int N = 200000;
int a[N];
int dp[N];

int32_t main() {
    #ifndef DEBUG
        #ifndef INTER
            fast_io;
        #endif
    #else
        freopen(PROBLEM".in", "r", stdin);
    #endif

    std::cout << std::setprecision(10) << std::fixed;
    std::cerr << std::setprecision(10) << std::fixed;
    ld START_TIME = clock();

    int n;
    std::cin >> n;
    SegmentTree st(n);
    for(int i = 0; i < n - 1; i++) {
        std::cin >> a[i];
        a[i]--;
        st.upd(1, i, a[i]);
    }
    a[n - 1] = n - 1;
    dp[n - 1] = 0;
    st.upd(1, n - 1, n - 1);
    ll ans = 0;
    for(int i = n - 2; i >= 0; i--) {
         auto res = st.get(1, i + 1, a[i]);
         auto [val, ind, l111231, r321312312] = res;
         dp[i] = dp[ind] + (n - ind) - (a[i] - ind);
//         std::cout << res.v << ' ' << res.ind << '\n';
        ans += dp[i];
        // debug(i);
        // debug(ind);
        // debug(dp[i]);
    }

    std::cout << ans;

    std::cerr << '\n';
    ld TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    debug(TIME);
    return 0;
}


//#pragma GCC optimize("Ofast,unroll-loops,fast-math,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt")
//#pragma GCC target("avx,avx2")
// #define INTER

#include <bits/stdc++.h>

//----------------------------------------------------------------
typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

std::random_device rd;
std::mt19937 Random(rd());
const int inf = 0x3f3f3f3f;
const ll llinf = 2e18;
const ld eps = 1e-15;
const ll mod = 1e9 + 7;

//----------------------------------------------------------------
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fast_io std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0), std::cerr.tie(0);
#define debug(x) std::cerr << #x << ": " << x << '\n'
#define PROBLEM "task"
#define mp std::make_pair

long long mx(long long &a, long long b) { return (a > b ? a : a = b); }
int mx(int &a, int b) { return (a > b ? a : a = b); }
long long mn(long long &a, long long b) { return (a < b ? a : a = b); }
int mn(int &a, int b) { return (a < b ? a : a = b); }
//----------------------------------------------------------------

namespace Kon567889 {
    template <class A, class B>
    std::ostream &operator<<(std::ostream &out, std::pair<A, B> &p) {
        return out << p.first << ' ' << p.second;
    }
    template <class A, class B>
    std::istream &operator>>(std::istream &in, std::pair<A, B> &p) {
        return in >> p.first >> p.second;
    }
    template <class T>
    std::ostream &operator<<(std::ostream &out, std::vector<T> &a) {
        for (auto &i : a) out << i << ' ';
        return out;
    }
    template <class T>
    std::istream &operator>>(std::istream &in, std::vector<T> &a) {
        for(auto &i : a) in >> i;
        return in;
    }
}
using namespace Kon567889;

class SegmentTree {
private:
    struct Node {
        int v, ind, l, r;

        Node() : v(0), ind(-1), l(-1), r(-1) {}
        Node(int v, int ind, int l, int r) : v(v), ind(ind), l(l), r(r) {}

        Node operator+(const Node &a) const {
            return Node(std::max(v, a.v), (v >= a.v ? ind : a.ind), l, a.r);
        };
    };

    Node tree[4 * (1 << 10)];
public:

    void build(int v, int l, int r) {
        if(l == r) {
            tree[v] = { 0, l, l, r };
            return;
        }
        int m = (l + r) / 2;
        build(2 * v, l, m);
        build(2 * v + 1, m + 1, r);
        tree[v] = tree[2 * v] + tree[2 * v +  1];
    }

    SegmentTree(int n) { build(1, 0, n - 1); }

    Node get(int v, int l, int r) {
        if(r < tree[v].l || tree[v].r < l) return Node();
        if(l <= tree[v].l && tree[v].r <= r) return tree[v];
        return get(2 * v, l, r) + get(2 * v + 1, l, r);
    }

    void upd(int v, int i, int d) {
        if(tree[v].l == tree[v].r) {
            tree[v].v = d;
            return;
        }
        upd(2 * v + (i >= tree[2 * v + 1].l), i, d);
        tree[v] = tree[2 * v] + tree[2 * v + 1];
    }
};

const int N = 200000;
int a[N];
int dp[N];

int32_t main() {
    #ifndef DEBUG
        #ifndef INTER
            fast_io;
        #endif
    #else
        freopen(PROBLEM".in", "r", stdin);
    #endif

    std::cout << std::setprecision(10) << std::fixed;
    std::cerr << std::setprecision(10) << std::fixed;
    ld START_TIME = clock();

    int n;
    std::cin >> n;
    SegmentTree st(n);
    for(int i = 0; i < n - 1; i++) {
        std::cin >> a[i];
        a[i]--;
        st.upd(1, i, a[i]);
    }
    a[n - 1] = n - 1;
    dp[n - 1] = 0;
    st.upd(1, n - 1, n - 1);
    ll ans = 0;
    for(int i = n - 2; i >= 0; i--) {
         auto res = st.get(1, i + 1, a[i]);
         auto [val, ind, l111231, r321312312] = res;
         dp[i] = dp[ind] + (n - ind) - (a[i] - ind) + (ind - i - 1);
//         std::cout << res.v << ' ' << res.ind << '\n';
        ans += dp[i];
        // debug(i);
        // debug(ind);
        // debug(dp[i]);
    }

    std::cout << ans;

    std::cerr << '\n';
    ld TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    debug(TIME);
    return 0;
}


//#pragma GCC optimize("Ofast,unroll-loops,fast-math,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt")
//#pragma GCC target("avx,avx2")
// #define INTER

#include <bits/stdc++.h>

//----------------------------------------------------------------
typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

std::random_device rd;
std::mt19937 Random(rd());
const int inf = 0x3f3f3f3f;
const ll llinf = 2e18;
const ld eps = 1e-15;
const ll mod = 1e9 + 7;

//----------------------------------------------------------------
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fast_io std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0), std::cerr.tie(0);
#define debug(x) std::cerr << #x << ": " << x << '\n'
#define PROBLEM "task"
#define mp std::make_pair

long long mx(long long &a, long long b) { return (a > b ? a : a = b); }
int mx(int &a, int b) { return (a > b ? a : a = b); }
long long mn(long long &a, long long b) { return (a < b ? a : a = b); }
int mn(int &a, int b) { return (a < b ? a : a = b); }
//----------------------------------------------------------------

namespace Kon567889 {
    template <class A, class B>
    std::ostream &operator<<(std::ostream &out, std::pair<A, B> &p) {
        return out << p.first << ' ' << p.second;
    }
    template <class A, class B>
    std::istream &operator>>(std::istream &in, std::pair<A, B> &p) {
        return in >> p.first >> p.second;
    }
    template <class T>
    std::ostream &operator<<(std::ostream &out, std::vector<T> &a) {
        for (auto &i : a) out << i << ' ';
        return out;
    }
    template <class T>
    std::istream &operator>>(std::istream &in, std::vector<T> &a) {
        for(auto &i : a) in >> i;
        return in;
    }
}
using namespace Kon567889;

class SegmentTree {
private:
    struct Node {
        int v, ind, l, r;

        Node() : v(0), ind(-1), l(-1), r(-1) {}
        Node(int v, int ind, int l, int r) : v(v), ind(ind), l(l), r(r) {}

        Node operator+(const Node &a) const {
            return Node(std::max(v, a.v), (v >= a.v ? ind : a.ind), l, a.r);
        };
    };

    Node tree[4 * (1 << 17)];
public:

    void build(int v, int l, int r) {
        if(l == r) {
            tree[v] = { 0, l, l, r };
            return;
        }
        int m = (l + r) / 2;
        build(2 * v, l, m);
        build(2 * v + 1, m + 1, r);
        tree[v] = tree[2 * v] + tree[2 * v +  1];
    }

    SegmentTree(int n) { build(1, 0, n - 1); }

    Node get(int v, int l, int r) {
        if(r < tree[v].l || tree[v].r < l) return Node();
        if(l <= tree[v].l && tree[v].r <= r) return tree[v];
        return get(2 * v, l, r) + get(2 * v + 1, l, r);
    }

    void upd(int v, int i, int d) {
        if(tree[v].l == tree[v].r) {
            tree[v].v = d;
            return;
        }
        upd(2 * v + (i >= tree[2 * v + 1].l), i, d);
        tree[v] = tree[2 * v] + tree[2 * v + 1];
    }
};

const int N = 200000;
int a[N];
int dp[N];

int32_t main() {
    #ifndef DEBUG
        #ifndef INTER
            fast_io;
        #endif
    #else
        freopen(PROBLEM".in", "r", stdin);
    #endif

    std::cout << std::setprecision(10) << std::fixed;
    std::cerr << std::setprecision(10) << std::fixed;
    ld START_TIME = clock();

    int n;
    std::cin >> n;
    SegmentTree st(n);
    for(int i = 0; i < n - 1; i++) {
        std::cin >> a[i];
        a[i]--;
        st.upd(1, i, a[i]);
    }
    a[n - 1] = n - 1;
    dp[n - 1] = 0;
    st.upd(1, n - 1, n - 1);
    ll ans = 0;
    for(int i = n - 2; i >= 0; i--) {
         auto res = st.get(1, i + 1, a[i]);
         auto [val, ind, l111231, r321312312] = res;
         dp[i] = dp[ind] + (n - ind) - (a[i] - ind) + (ind - i - 1);
//         std::cout << res.v << ' ' << res.ind << '\n';
        ans += dp[i];
        // debug(i);
        // debug(ind);
        // debug(dp[i]);
    }

    std::cout << ans;

    std::cerr << '\n';
    ld TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
    debug(TIME);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N = 1e5 + 7;

int ind[4 * N], a[N], dp[N];

int f(int x, int y) {
    if (x == -1) return y;
    if (y == -1) return x;
    return a[x] > a[y] ? x : y;
}

void build(int v, int tl, int tr) {
    if (tr - tl == 1) ind[v] = tl; else {
        int mid = (tl + tr) / 2;
        build(2 * v, tl, mid);
        build(2 * v + 1, mid, tr);
        ind[v] = f(ind[2 * v], ind[2 * v + 1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (tl >= r || tr <= l) return -1;
    if (tl >= l && tr <= r) return ind[v];
    int mid = (tl + tr) / 2;
    return f(query(2 * v, tl, mid, l, r), query(2 * v + 1, mid, tr, l, r));
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    n--;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    //return 0;
    build(1, 0, n);
    //return 0;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        int to = a[i] == n ? n : query(1, 0, n, i + 1, a[i] + 1);
        dp[i] = dp[to] + n - a[i] + to - i;
        //cout << "to = " << to << " " << "dp = " << dp[i] << endl;
    }
    for (int i = 0; i < n; i++) ans += dp[i];
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N = 1e5 + 7;

int ind[4 * N], a[N], dp[N];

int f(int x, int y) {
    if (x == -1) return y;
    if (y == -1) return x;
    return a[x] > a[y] ? x : y;
}

void build(int v, int tl, int tr) {
    if (tr - tl == 1) ind[v] = tl; else {
        int mid = (tl + tr) / 2;
        build(2 * v, tl, mid);
        build(2 * v + 1, mid, tr);
        ind[v] = f(ind[2 * v], ind[2 * v + 1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (tl >= r || tr <= l) return -1;
    if (tl >= l && tr <= r) return ind[v];
    int mid = (tl + tr) / 2;
    return f(query(2 * v, tl, mid, l, r), query(2 * v + 1, mid, tr, l, r));
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    n--;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    //return 0;
    build(1, 0, n);
    // return 0;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] == n) {
            dp[i] = n - i;
            continue;
        }
        int to = query(1, 0, n, i + 1, a[i] + 1);
        dp[i] = dp[to] + n - i;
        //cout << "to = " << to << " " << "dp = " << dp[i] << endl;
    }
    for (int i = 0; i < n; i++) ans += dp[i];
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N = 1e5 + 7;

int ind[4 * N], a[N], dp[N];

int f(int x, int y) {
    if (x == -1) return y;
    if (y == -1) return x;
    return a[x] >= a[y] ? x : y;
}

void build(int v, int tl, int tr) {
    if (tr - tl == 1) ind[v] = tl; else {
        int mid = (tl + tr) / 2;
        build(2 * v, tl, mid);
        build(2 * v + 1, mid, tr);
        ind[v] = f(ind[2 * v], ind[2 * v + 1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (tl >= r || tr <= l) return -1;
    if (tl >= l && tr <= r) return ind[v];
    int mid = (tl + tr) / 2;
    return f(query(2 * v, tl, mid, l, r), query(2 * v + 1, mid, tr, l, r));
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    n--;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    //return 0;
    build(1, 0, n);
    // return 0;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        int to = a[i] == n ? n : query(1, 0, n, i + 1, a[i] + 1);
        dp[i] = dp[to] + n - i;
        //cout << "to = " << to << " " << "dp = " << dp[i] << endl;
    }
    for (int i = 0; i < n; i++) ans += dp[i];
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    n--;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    vector<int> dp(n + 1, 0);
    int ans = 0;
    for (int i = n - 1; i > -1; i--) {
        dp[i] = a[i] - i + dp[a[i]] + n - a[i];
        ans += dp[i];
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100111],n;
int dp[100111];
int sparse[100111][20];

void init(){
	for(int i=0;i<n;i++)
		sparse[i][0]=i;
	for(int j=1;(1<<j)<=n;j++){
		for(int i=0;i+(1<<j)<=n;i++){
			int x=sparse[i][j-1];
			int y=sparse[i+(1<<(j-1))][j-1];
			if(a[x]<=a[y]){
				sparse[i][j]=y;
			}else{
				sparse[i][j]=x;
			}
		}
	}
}

int main(){
	cin>>n;

	for(int i=0;i<n-1;i++){
		cin>>a[i];
		--a[i];
	}
	a[n-1]=n-1;
	dp[n-1]=0;

	init();

	for(int i=n-2;i>=0;i--){
		int index=log2(a[i]-i);
		//cout<<a[i]-i<<endl;
		//cout<<index<<endl;
		int x=sparse[i][index];
		int y=sparse[a[i]-(1<<index)+1][index];
		int m=a[x]<=a[y]?y:x;
		//cout<<m<<endl;
		dp[i]=dp[m]+n-1-a[i]+m-i;
		//cout<<dp[i]<<endl;
	}

	int ans=0;
	for(int i=0;i<n;i++)
		ans+=dp[i];
	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100111],n;
int dp[100111];
int sparse[100111][10];

void init(){
	for(int i=0;i<n;i++)
		sparse[i][0]=i;
	for(int j=1;(1<<j)<=n;j++){
		for(int i=0;i+(1<<j)<=n;i++){
			int x=sparse[i][j-1];
			int y=sparse[i+(1<<(j-1))][j-1];
			if(a[x]<=a[y]){
				sparse[i][j]=y;
			}else{
				sparse[i][j]=x;
			}
		}
	}
}

int main(){
	cin>>n;

	for(int i=0;i<n-1;i++){
		cin>>a[i];
		--a[i];
	}
	a[n-1]=n-1;
	dp[n-1]=0;

	init();

	for(int i=n-2;i>=0;i--){
		int index=log2(a[i]-i);
		//cout<<a[i]-i<<endl;
		//cout<<index<<endl;
		int x=sparse[i][index];
		int y=sparse[a[i]-(1<<index)+1][index];
		int m=a[x]<=a[y]?y:x;
		//cout<<m<<endl;
		dp[i]=dp[m]+n-1-a[i]+m-i;
		//cout<<dp[i]<<endl;
	}

	int ans=0;
	for(int i=0;i<n;i++)
		ans+=dp[i];
	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	int a[n];
	for(int i=1;i<n;i++)
		cin>>a[i];

	int dp[n+1];
	memset(dp,0,sizeof(dp));

	dp[n]=0;
	int cnt=0;
	for(int i=n-1;i>0;i--){
		dp[i]=dp[a[i]]+n-i;
		cnt+=dp[i];
	}

	cout<<cnt<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100111],n;
int dp[100111];
int sparse[100111][20];

void init(){
	for(int i=0;i<n;i++)
		sparse[i][0]=i;
	for(int j=1;(1<<j)<=n;j++){
		for(int i=0;i+(1<<j)<=n;i++){
			int x=sparse[i][j-1];
			int y=sparse[i+(1<<(j-1))][j-1];
			if(a[x]<=a[y]){
				sparse[i][j]=y;
			}else{
				sparse[i][j]=x;
			}
		}
	}
}

int main(){
	cin>>n;

	for(int i=0;i<n-1;i++){
		cin>>a[i];
		--a[i];
	}
	a[n-1]=n-1;
	dp[n-1]=0;

	init();

	for(int i=n-2;i>=0;i--){
		int index=log2(a[i]-i);
		//cout<<a[i]-i<<endl;
		//cout<<index<<endl;
		int x=sparse[i][index];
		int y=sparse[a[i]-(1<<index)+1][index];
		int m=a[x]<=a[y]?y:x;
		//cout<<m<<endl;
		dp[i]=dp[m]+n-1-a[i]+m-i;
		//cout<<dp[i]<<endl;
	}

	long long ans=0;
	for(int i=0;i<n;i++)
		ans+=dp[i];
	cout<<ans<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int n;
int a[100111];
int sparse[100111][20];
int lg[100111];
int dp[100111];

void init(){
	for(int i=0;i<n;i++)
		sparse[i][0]=a[i+1];
	for(int j=1;(1<<j)-1<n;j++){
		for(int i=0;i+(1<<j)-1<n;i++){
			sparse[i][j]=max(sparse[i][j-1],sparse[i+(1<<(j-1))][j-1]);
		}
	}
}

void genlg(){
	lg[1]=0;
	for(int i=2;i<100111;i++){
		lg[i]=lg[i/2]+1;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;

	for(int i=1;i<n;i++){
		cin>>a[i];
	}

	a[n]=n;

	init();
	genlg();

	memset(dp,0,sizeof(dp));

	int cnt=0;

	for(int i=n-1;i>0;i--){
		int r=a[i];
		int l=i+1;
		int x=lg[r-l+1];
		int x_max=max(sparse[l-1][x],sparse[r-(1<<x)][x]);
		int index=0;
		for(int k=l;k<=r;k++){
			if(a[k]==x_max){
				index=k;
				break;
			}
		}
		dp[i]=dp[index]+n-i-(r-index);
		cnt+=dp[i];
	}

	cout<<cnt<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	int a[n];
	for(int i=1;i<n;i++)
		cin>>a[i];

	int dp[n+1];
	memset(dp,0,sizeof(dp));

	dp[n]=0;
	int cnt=0;
	for(int i=n-2;i>0;i--){
		dp[i]=dp[a[i]]+n-i;
		cnt+=dp[i];
	}

	cout<<cnt+1<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
int a[100111];
int sparse[100111][20];
int lg[100111];
ll dp[100111];

void init(){
	for(int i=0;i<n;i++)
		sparse[i][0]=i+1;
	for(int j=1;(1<<j)-1<n;j++){
		for(int i=0;i+(1<<j)-1<n;i++){
			if(a[sparse[i][j-1]]>=a[sparse[i+(1<<(j-1))][j-1]]){
				sparse[i][j]=sparse[i][j-1];
			}else{
				sparse[i][j]=sparse[i+(1<<(j-1))][j-1];
			}
		}
	}
}

void genlg(){
	lg[1]=0;
	for(int i=2;i<100111;i++){
		lg[i]=lg[i/2]+1;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;

	for(int i=1;i<n;i++){
		cin>>a[i];
	}

	a[n]=n;

	init();
	genlg();

	ll cnt=0;

	for(int i=n-1;i>0;i--){
		int r=a[i];
		int l=i+1;
		int x=lg[r-l+1];
		int x_max=0;

		if(a[sparse[l-1][x]]>=a[sparse[r-(1<<x)][x]]){
			x_max=sparse[l-1][x];
		}else{
			x_max=sparse[r-(1<<x)][x];
		}
		dp[i]=dp[x_max]+n-i-(r-x_max);
		cnt+=dp[i];
	}

	cout<<cnt<<"\n";

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
int a[100111];
int sparse[100111][20];
int lg[100111];
ll dp[100111];

void init(){
	for(int i=0;i<n;i++)
		sparse[i][0]=a[i+1];
	for(int j=1;(1<<j)-1<n;j++){
		for(int i=0;i+(1<<j)-1<n;i++){
			sparse[i][j]=max(sparse[i][j-1],sparse[i+(1<<(j-1))][j-1]);
		}
	}
}

void genlg(){
	lg[1]=0;
	for(int i=2;i<100111;i++){
		lg[i]=lg[i/2]+1;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;

	for(int i=1;i<n;i++){
		cin>>a[i];
	}

	a[n]=n;

	init();
	genlg();

	memset(dp,0,sizeof(dp));

	ll cnt=0;

	for(int i=n-1;i>0;i--){
		int r=a[i];
		int l=i+1;
		int x=lg[r-l+1];
		int x_max=max(sparse[l-1][x],sparse[r-(1<<x)][x]);
		int index=0;
		for(int k=l;k<=r;k++){
			if(a[k]==x_max){
				index=k;
				break;
			}
		}
		dp[i]=dp[index]+n-i-(r-index);
		cnt+=dp[i];
	}

	cout<<cnt<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100111],n;
long long dp[100111];
int sparse[100111][20];

void init(){
	for(int i=0;i<n;i++)
		sparse[i][0]=i;
	for(int j=1;(1<<j)<=n;j++){
		for(int i=0;i+(1<<j)<=n;i++){
			int x=sparse[i][j-1];
			int y=sparse[i+(1<<(j-1))][j-1];
			if(a[x]<=a[y]){
				sparse[i][j]=y;
			}else{
				sparse[i][j]=x;
			}
		}
	}
}

int main(){
	cin>>n;

	for(int i=0;i<n-1;i++){
		cin>>a[i];
		--a[i];
	}
	a[n-1]=n-1;
	dp[n-1]=0;

	init();

	for(int i=n-2;i>=0;i--){
		int index=log2(a[i]-i);
		//cout<<a[i]-i<<endl;
		//cout<<index<<endl;
		int x=sparse[i][index];
		int y=sparse[a[i]-(1<<index)+1][index];
		int m=a[x]<=a[y]?y:x;
		//cout<<m<<endl;
		dp[i]=dp[m]+n-1-a[i]+m-i;
		//cout<<dp[i]<<endl;
	}

	long long ans=0;
	for(int i=0;i<n;i++)
		ans+=dp[i];
	cout<<ans<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int n;
int h[100005];

template<int MAXN>
struct segtree {

	struct node_t {
		/* DATA MEMBERS */
		int x;

		/* CONSTRUCTOR */
		node_t(int x = 123123123) : x(x) {}

		node_t& operator+= (const node_t& other) {
			/* ADDITION */
			x = min(x, other.x);

			return *this;
		}

		node_t operator+ (const node_t& other) const {
			node_t tmp = *this;
			tmp += other;
			return tmp;
		}
	};

	node_t a[2*MAXN];

	node_t get(int l, int r, int node=1, int nl=1, int nr=MAXN) {
		if (r < nl || nr < l) {
			return node_t();
		}
		if (l <= nl && nr <= r) {
			return a[node];
		}

		int nm = (nl + nr) >> 1;
		return get(l, r, 2*node, nl, nm) + get(l, r, 2*node+1, nm+1, nr);
	}

	void add(int pos, node_t val) {
		pos += MAXN-1;
		a[pos] += val;
		while (pos > 1) {
			pos >>= 1;
			a[pos] = a[2*pos] + a[2*pos+1];
		}
	}

	void set(int pos, node_t val) {
		pos += MAXN-1;
		a[pos] = val;
		while (pos > 1) {
			pos >>= 1;
			a[pos] = a[2*pos] + a[2*pos+1];
		}
	}
};

segtree<131072> drvo;

const int MAXN = 131072;
ll a[2*MAXN], b[2*MAXN];

void push(int x, int xl, int xr) {
	if (x < MAXN) {
		b[2*x] += b[x];
		b[2*x+1] += b[x];
	}
	a[x] += b[x] * (xr-xl+1);
	b[x] = 0;
}

void update(int l, int r, int v, int x=1, int xl=0, int xr=MAXN-1) {
	if (r < xl || xr < l) {
		push(x, xl, xr);
		return;
	}

	if (l <= xl && xr <= r) {
		b[x] += v;
		push(x, xl, xr);
		return;
	}

	push(x, xl, xr);
	int xm = (xl+xr) >> 1;
	update(l, r, v, 2*x, xl, xm);
	update(l, r, v, 2*x+1, xm+1, xr);
	a[x] = a[2*x] + a[2*x+1];
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n;
	for (int i=1; i<n; i++)
		cin >> h[i];
	h[n] = n;

	for (int i=1; i<=n; i++) {
		drvo.set(i, h[i]);
	}

	ll sol = 0;
	basic_string<int> st;

	for (int i=n; i>=1; i--) {
		while (st.size() && drvo.get(h[i], st.back()).x >= st.back()) {
			update(st.back()+1, n, -1);
			st.pop_back();
		}

		st += h[i];
		update(h[i]+1, n, 1);
		st += i;
		update(i+1, n, 1);

		// for (int x : st)
		// 	cerr << x << ' ';
		// cerr << '\n';

		sol += a[1];
	}

	cout << sol << '\n';
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int MAXN = 131072;

int n;
int h[100005];
pair<int, int> a[2*MAXN];
ll dp[100005];

void update(int x, pair<int, int> v) {
	x += MAXN;
	a[x] = v;
	while (x > 1) {
		x >>= 1;
		a[x] = max(a[2*x], a[2*x+1]);
	}
}

pair<int, int> query(int l, int r, int x=1, int xl=0, int xr=MAXN-1) {
	if (r < xl || xr < l)
		return {0, 0};
	if (l <= xl && xr <= r)
		return a[x];
	int xm = (xl+xr) >> 1;
	return max(query(l, r, 2*x, xl, xm), query(l, r, 2*x+1, xm+1, xr));
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n;
	for (int i=1; i<n; i++) {
		cin >> h[i];
		update(i, {h[i], i});
	}
	h[n] = n;
	update(n, {n, n});

	ll sol = 0;

	for (int i=n-1; i>=1; i--) {
		int j = query(i+1, h[i]).second;
		dp[i] = dp[j] - (h[i] - j) + (n - h[i]) + (h[i] - i);
		// cerr << i << ' ' << dp[i] << '\n';
		sol += dp[i];
	}

	cout << sol << '\n';
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int n;
int h[100005];

const int MAXN = 131072;
ll a[2*MAXN], b[2*MAXN];

void push(int x, int xl, int xr) {
	if (x < MAXN) {
		b[2*x] += b[x];
		b[2*x+1] += b[x];
	}
	a[x] += b[x] * (xr-xl+1);
	b[x] = 0;
}

void update(int l, int r, int v, int x=1, int xl=0, int xr=MAXN-1) {
	if (r < xl || xr < l) {
		push(x, xl, xr);
		return;
	}

	if (l <= xl && xr <= r) {
		b[x] += v;
		push(x, xl, xr);
		return;
	}

	push(x, xl, xr);
	int xm = (xl+xr) >> 1;
	update(l, r, v, 2*x, xl, xm);
	update(l, r, v, 2*x+1, xm+1, xr);
	a[x] = a[2*x] + a[2*x+1];
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n;
	for (int i=1; i<n; i++)
		cin >> h[i];
	h[n] = n;

	ll sol = 0;
	basic_string<int> st;

	for (int i=n; i>=1; i--) {
		while (st.size() && h[i] >= st.back()) {
			update(st.back()+1, n, -1);
			st.pop_back();
		}
		st += h[i];
		update(h[i]+1, n, 1);
		st += i;
		update(i+1, n, 1);
		sol += a[1];
	}

	cout << sol << '\n';
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const int N = 1000005;

const int K = 20;
ll a[N];
pair<ll,ll> st[N][K + 1];
void createst(ll n)
{
	for (ll i = 0; i < n; i++)
	{
		st[i][0] = { a[i],i };
	}
	for (ll j = 1; j <= K; j++)
	{
		for (ll i = 0; i + (1 << j) <= n; i++)
		{
			st[i][j] = max(st[i][j - 1], st[i + 1 << (j - 1)][j - 1]);
		}
	}
}

ll lg2[N + 1];
pair<ll,ll> getMax(ll l, ll r)
{
	ll j = lg2[r - l + 1];
	return max(st[l][j], st[r - (1 << j) + 1][j]);
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	lg2[1] = 0;
	for (ll i = 2; i <= N; i++)
		lg2[i] = lg2[i / 2] + 1;

	ll n;
	cin >> n;
	for (ll i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<ll> dp(n);
	dp[n - 1] = 0;
	ll sum = 0;
	for (ll i = n - 2; i >= 0; i--)
	{
		auto [am, m] = getMax(i + 1, a[i]);
		dp[i] = dp[m] - ((ll)a[i] - m) + n - i - 1;
		sum += dp[i];
	}
	print(sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const int N = 100005;

const int K = 20;
ll a[N];
pair<ll,ll> st[N][K + 1];
void createst(ll n)
{
	for (int i = 0; i < n; i++)
	{
		st[i][0] = { a[i],i };
	}
	for (int j = 1; j <= K; j++)
	{
		for (int i = 0; i + (1 << j) <= n; i++)
		{
			st[i][j] = max(st[i][j - 1], st[i + 1 << (j - 1)][j - 1]);
		}
	}
}

ll lg2[N + 1];
pair<ll,ll> getMax(int l, int r)
{
	ll j = lg2[r - l + 1];
	return max(st[l][j], st[r - (1 << j) + 1][j]);
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	lg2[1] = 0;
	for (ll i = 2; i <= N; i++)
		lg2[i] = lg2[i / 2] + 1;

	ll n;
	cin >> n;
	for (ll i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<ll> dp(n);
	dp[n - 1] = 0;
	ll sum = 0;
	for (ll i = n - 2; i >= 0; i--)
	{
		auto [am, m] = getMax(i + 1, a[i]);
		dp[i] = dp[m] - ((ll)a[i] - m) + n - i - 1;
		sum += dp[i];
	}
	print(sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const int N = 100005;

const int K = 20;
ll a[N];
pair<ll,ll> st[N][K + 1];
void createst(ll n)
{
	for (ll i = 0; i < n; i++)
	{
		st[i][0] = { a[i],i };
	}
	for (ll j = 1; j <= K; j++)
	{
		for (ll i = 0; i + (1 << j) <= n; i++)
		{
			st[i][j] = max(st[i][j - 1], st[i + 1 << (j - 1)][j - 1]);
		}
	}
}

ll lg2[N + 1];
pair<ll,ll> getMax(ll l, ll r)
{
	ll j = lg2[r - l + 1];
	return max(st[l][j], st[r - (1 << j) + 1][j]);
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	lg2[1] = 0;
	for (ll i = 2; i <= N; i++)
		lg2[i] = lg2[i / 2] + 1;

	ll n;
	cin >> n;
	for (ll i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<ll> dp(n);
	dp[n - 1] = 0;
	ll sum = 0;
	for (ll i = n - 2; i >= 0; i--)
	{
		auto [am, m] = getMax(i + 1, a[i]);
		dp[i] = dp[m] - ((ll)a[i] - m) + n - i - 1;
		sum += dp[i];
	}
	print(sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const int N = 1000005;

const int K = 20;
int a[N];
pair<int,int> st[N][K + 1];
void createst(int n)
{
	for (int i = 0; i < n; i++)
	{
		st[i][0] = { a[i],i };
	}
	for (int j = 1; j <= K; j++)
		for (int i = 0; i + (1 << j) <= N; i++)
			st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}

int lg2[N + 1];
int get(int l, int r)
{
	int j = lg2[r - l + 1];
	return max(st[l][j], st[r - (1 << j) + 1][j]).second;
}

int main()
{

	lg2[1] = 0;
	for (int i = 2; i <= N; i++)
		lg2[i] = lg2[i / 2] + 1;

	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<ll> dp(n);
	dp[n - 1] = 0;
	ll sum = 0;
	for (int i = n - 2; i >= 0; i--)
	{
		int m = get(i + 1, a[i]);
		dp[i] = dp[m] - (a[i] - m) + n - i - 1;
		sum += dp[i];
	}
	print(sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const ll N = 1000005;

const ll K = 20;
ll a[N];
pair<ll,ll> st[N][K + 1];
void createst(ll n)
{
	for (ll i = 0; i < n; i++)
	{
		st[i][0] = { a[i],i };
	}
	for (ll j = 1; j <= K; j++)
	{
		for (ll i = 0; i + (1 << j) <= n; i++)
		{
			st[i][j] = max(st[i][j - 1], st[i + 1 << (j - 1)][j - 1]);
		}
	}
}

ll lg2[N + 1];
pair<ll,ll> getMax(ll l, ll r)
{
	ll j = lg2[r - l + 1];
	return max(st[l][j], st[r - (1 << j) + 1][j]);
}

int main()
{

	lg2[1] = 0;
	for (ll i = 2; i <= N; i++)
		lg2[i] = lg2[i / 2] + 1;

	ll n;
	cin >> n;
	for (ll i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<ll> dp(n);
	dp[n - 1] = 0;
	ll sum = 0;
	for (ll i = n - 2; i >= 0; i--)
	{
		auto [am, m] = getMax(i + 1, a[i]);
		dp[i] = dp[m] - ((ll)a[i] - m) + n - i - 1;
		sum += dp[i];
	}
	print(sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const int N = 1000005;

const int K = 20;
ll a[N];
pair<ll,ll> st[N][K + 1];
void createst(ll n)
{
	for (ll i = 0; i < n; i++)
	{
		st[i][0] = { a[i],i };
	}
	for (ll j = 1; j <= K; j++)
	{
		for (ll i = 0; i + (1 << j) <= n; i++)
		{
			st[i][j] = max(st[i][j - 1], st[i + 1 << (j - 1)][j - 1]);
		}
	}
}

ll lg2[N + 1];
pair<ll,ll> getMax(ll l, ll r)
{
	ll j = lg2[r - l + 1];
	return max(st[l][j], st[r - (1 << j) + 1][j]);
}

int main()
{

	lg2[1] = 0;
	for (ll i = 2; i <= N; i++)
		lg2[i] = lg2[i / 2] + 1;

	ll n;
	cin >> n;
	for (ll i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<ll> dp(n);
	dp[n - 1] = 0;
	ll sum = 0;
	for (ll i = n - 2; i >= 0; i--)
	{
		auto [am, m] = getMax(i + 1, a[i]);
		dp[i] = dp[m] - ((ll)a[i] - m) + n - i - 1;
		sum += dp[i];
	}
	print(sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const int N = 1000005;

const int K = 20;
int a[N];
pair<int,int> st[N][K + 1];
void createst(int n)
{
	for (int i = 0; i < n; i++)
	{
		st[i][0] = { a[i],i };
	}
	for (int j = 1; j <= K; j++)
	{
		for (int i = 0; i + (1 << j) <= n; i++)
		{
			st[i][j] = max(st[i][j - 1], st[i + 1 << (j - 1)][j - 1]);
		}
	}
}

int lg2[N + 1];
pair<int,int> getMax(int l, int r)
{
	int j = lg2[r - l + 1];
	return max(st[l][j], st[r - (1 << j) + 1][j]);
}

int main()
{

	lg2[1] = 0;
	for (int i = 2; i <= N; i++)
		lg2[i] = lg2[i / 2] + 1;

	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<int> dp(n);
	dp[n - 1] = 0;
	int sum = 0;
	for (int i = n - 2; i >= 0; i--)
	{
		auto [am, m] = getMax(i + 1, a[i]);
		dp[i] = dp[m] - (a[i] - m) + n - i - 1;
		sum += dp[i];
	}
	print(sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const int N = 1000005;

const int K = 20;
int a[N];
pair<int,int> st[N][K + 1];
void createst(int n)
{
	for (int i = 0; i < n; i++)
	{
		st[i][0] = { a[i],i };
	}
	for (int j = 1; j <= K; j++)
	{
		for (int i = 0; i + (1 << j) <= n; i++)
		{
			st[i][j] = max(st[i][j - 1], st[i + 1 << (j - 1)][j - 1]);
		}
	}
}

int lg2[N + 1];
pair<int,int> getMax(int l, int r)
{
	int j = lg2[r - l + 1];
	return max(st[l][j], st[r - (1 << j) + 1][j]);
}

int main()
{

	lg2[1] = 0;
	for (int i = 2; i <= N; i++)
		lg2[i] = lg2[i / 2] + 1;

	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<ll> dp(n);
	dp[n - 1] = 0;
	ll sum = 0;
	for (int i = n - 2; i >= 0; i--)
	{
		auto [am, m] = getMax(i + 1, a[i]);
		dp[i] = dp[m] - (a[i] - m) + n - i - 1;
		sum += dp[i];
	}
	print(sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const int N =  1000005;

const int K = 20;
int a[N];
int st[N][K + 1];
void createst(int n)
{
	for (int i = 0; i < n; i++)
	{
		st[i][0] = a[i];
	}
	for (int j = 1; j <= K; j++)
	{
		for (int i = 0; i + (1 << j) <= n; i++)
		{
			st[i][j] = max(st[i][j - 1], st[i + 1 << (j - 1)][j - 1]);
		}
	}
}

int lg2[N];
int getMax(int l, int r)
{
	int j = log(r - l + 1);
	return max(st[l][j], st[r - (1 << j)][j]);
}

int main()
{
	int pw = 1;
	lg2[1] = 0;
	for (size_t i = 2; i < K; i++)
	{
		int j = pw + 1;
		pw *= 2;
		if (pw >= N) break;
		while (pw >= j)
		{
			lg2[j] = i;
			j++;
		}

	}
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<int> dp(n);
	dp[n - 1] = 0;
	int sum = 0;
	for (int i = n-2; i >= 0; i--)
	{
		int lt = getMax(i, a[i]);
		dp[i] = n - i -1 + dp[lt] - (a[i] - lt);
		sum += dp[i];
	}
	print(sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const int N = 1000005;

const int K = 25;
int a[N];
pair<int,int> st[N][K + 1];
void createst(int n)
{
	for (int i = 0; i < n; i++)
	{
		st[i][0] = { a[i],i };
	}
	for (int j = 1; j <= K; j++)
	{
		for (int i = 0; i + (1 << j) <= n; i++)
		{
			st[i][j] = max(st[i][j - 1], st[i + 1 << (j - 1)][j - 1]);
		}
	}
}

int lg2[N + 1];
pair<int,int> getMax(int l, int r)
{
	int j = lg2[r - l + 1];
	return max(st[l][j], st[r - (1 << j) + 1][j]);
}

int main()
{

	lg2[1] = 0;
	for (int i = 2; i <= N; i++)
		lg2[i] = lg2[i / 2] + 1;

	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<int> dp(n);
	dp[n - 1] = 0;
	int sum = 0;
	for (int i = n - 2; i >= 0; i--)
	{
		auto [am, m] = getMax(i + 1, a[i]);
		dp[i] = dp[m] - (a[i] - m) + n - i - 1;
		sum += dp[i];
	}
	print(sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <initializer_list>

using namespace std;

using ll = long long;

ll mod = pow(10, 9) + 7;
using namespace std;
template <typename T>
void print(vector<T> t)
{
	for (auto& val : t)
	{
		cout << val << " ";
	}
	cout << endl;
}
template <typename T>
void print(initializer_list<T> t)
{
	for (auto val : t)
	{
		cout << t << " ";
	}
	cout << endl;
}
template <typename T>
void print(T t)
{
	std::cout << t << std::endl;
}

template<typename T, typename... Args>
void print(T t, Args... args)
{
	std::cout << t << " ";

	print(args...);
}

const int N = 1000005;

const int K = 20;
int a[N];
pair<int,int> st[N][K + 1];
void createst(int n)
{
	for (int i = 0; i < n; i++)
	{
		st[i][0] = { a[i],i };
	}
	for (int j = 1; j <= K; j++)
	{
		for (int i = 0; i + (1 << j) <= n; i++)
		{
			st[i][j] = max(st[i][j - 1], st[i + 1 << (j - 1)][j - 1]);
		}
	}
}

int lg2[N + 1];
pair<int,int> getMax(int l, int r)
{
	int j = log(r - l + 1);
	return max(st[l][j], st[r - (1 << j) + 1][j]);
}

int main()
{

	lg2[1] = 0;
	for (int i = 2; i <= N; i++)
		lg2[i] = lg2[i / 2] + 1;

	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	a[n - 1] = n - 1;
	createst(n);
	vector<int> dp(n);
	dp[n - 1] = 0;
	int sum = 0;
	for (int i = n - 2; i >= 0; i--)
	{
		auto [am, m] = getMax(i + 1, a[i]);
		dp[i] = dp[m] - (a[i] - m) + n - i - 1;
		sum += dp[i];
	}
	print(sum);
	return 0;
}