Vasya commutes by train every day. There are n train stations in the city, and at the i-th station it's possible to buy only tickets to stations from i + 1 to ai inclusive. No tickets are sold at the last station.

Let ρi, j be the minimum number of tickets one needs to buy in order to get from stations i to station j. As Vasya is fond of different useless statistic he asks you to compute the sum of all values ρi, j among all pairs 1 ≤ i < j ≤ n.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of stations.

The second line contains n - 1 integer ai (i + 1 ≤ ai ≤ n), the i-th of them means that at the i-th station one may buy tickets to each station from i + 1 to ai inclusive.

Output

Print the sum of ρi, j among all pairs of 1 ≤ i < j ≤ n.

Examples

Input

4
4 4 4


Output

6


Input

5
2 3 5 5


Output

17

Note

In the first sample it's possible to get from any station to any other (with greater index) using only one ticket. The total number of pairs is 6, so the answer is also 6.

Consider the second sample: 

  * ρ1, 2 = 1
  * ρ1, 3 = 2
  * ρ1, 4 = 3
  * ρ1, 5 = 3
  * ρ2, 3 = 1
  * ρ2, 4 = 2
  * ρ2, 5 = 2
  * ρ3, 4 = 1
  * ρ3, 5 = 1
  * ρ4, 5 = 1



Thus the answer equals 1 + 2 + 3 + 3 + 1 + 2 + 2 + 1 + 1 + 1 = 17.
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		int a[]=new int[n+1];
		for(int i=1;i<n;i++)
			a[i]=nextInt();
		a[n]=n;
		SegmentTree st=new SegmentTree(a,n);
		long sum=0;
		long dp[]=new long[n+1];
		for(int i=n-1;i>=1;i--)
		{
			int L=st.query(1,1,n,i+1,a[i]);
			dp[i]=n-i+dp[L]-(a[i]-L);
			sum+=dp[i];
		}
		out.println(sum);
	}
	public class SegmentTree
	{
		int n;
		int[] arr, tree, lazy;
		
		SegmentTree(int[] arr,int n)		
		{
			this.arr=arr;
			this.n=n;
			tree=new int[4*n];
			lazy=new int[4*n];
			build(1,1,n);
		}
		
		void build(int ti, int tl, int tr)
		{
			if(tl == tr)					
				tree[ti]=tl;
			else						
			{
				int tm=(tl+tr)/2;
				build(2*ti,tl,tm);
				build(2*ti+1,tm+1,tr);
				tree[ti]=arr[tree[2*ti]]>arr[tree[2*ti+1]]?tree[2*ti]:tree[2*ti+1];
			}
		}
		
		void update(int ti,int tl, int tr,int pos,int val)
		{
			if(tl==tr)
			{
				tree[ti]=val;
				return;
			}
			int tm=(tl+tr)/2;
			if(pos<=tm)
				update(2*ti,tl,tm,pos,val);
			else
				update(2*ti+1,tm+1,tr,pos,val);
			tree[ti]=tree[2*ti]+tree[2*ti+1];
		}
		
		void update(int ti, int tl, int tr, int l, int r, int addend)
		{
			if(l>tr || r<tl)		
				return;
			if(tl>=l && tr<=r)		
			{
				tree[ti]+=addend;			
				lazy[ti]+=addend;				
			}							
			else		
			{
				int tm=(tl+tr)/2;
				push(ti);
				update(2*ti,tl,tm,l,r,addend);
				update(2*ti+1,tm+1,tr,l,r,addend);
				tree[ti]=Math.max(tree[2*ti],tree[2*ti+1]);		
			}
			
		}
		void push(int ti)		
		{
			lazy[2*ti] += lazy[ti];
			lazy[2*ti+1] += lazy[ti];		
			lazy[ti]=0;
		}
		
		
		int query(int ti, int tl, int tr, int l, int r)
		{
			if(l>tr || r<tl)
				return 0;		
			if(tl>= l && tr <= r)
				return tree[ti];
			int tm=(tl+tr)/2;
			push(ti);
			int q1=query(2*ti,tl,tm,l,r);
			int q2=query(2*ti+1,tm+1,tr,l,r);
			return arr[q1]>arr[q2]?q1:q2;
		}
					
	}
	

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

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();

		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}