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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;


public class COVID {




static SparseTable st;
static int[] a;
static int n;
static long memo[];
public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw =new PrintWriter(System.out);
		 n=sc.nextInt();
		 a= new int[n];
		for(int i=0;i<n-1;i++)
			a[i]=sc.nextInt();
		 memo=new long [n];
		 st= new SparseTable(a);
		Arrays.fill(memo, -1);
		long ans=0;
		for(int i=0;i<n;i++)
		dp(i);
		for(int i=0;i<memo.length;i++)
			ans+=(memo[i]!=-1)?memo[i]:0;
		pw.println(ans);
		
		pw.flush();

}
static long dp(int idx) {
	if(idx==n-1)return	memo[idx] =0l;
	if(memo[idx]!=-1)return memo[idx];
	
	int maxJumpIdx=st.query(idx+1,a[idx]-1 );
	
	long ans=( n-idx-1)-(a[idx]-1-maxJumpIdx);
//	System.out.println(idx+" "+maxJumpIdx+" "+ans);
	
	ans+=dp(maxJumpIdx);
//	System.out.println(" "+ans);
	return memo[idx]=ans;
}

static HashMap<Integer,Long> cnt;

static void BS(int i,int start ,int lo , int hi, int val) {
			
			int l =lo,r=hi;
			while(lo<=hi) {
				int mid=lo+hi>>1;
				if( (st.query(i,mid))>=val) {
					lo=mid+1;
				}else {
					hi=mid-1;
				}
			}
		//	System.out.println(val+" "+hi+" "+start);
			cnt.put(val,cnt.getOrDefault(val, 0l)+hi-start+1);
			hi++;
			if(hi==n)return;
			BS(i,hi,hi,n-1,st.query(i, hi));
			
		}

static class SparseTable{
	int[][] spt;
	int[] log;
	int[] arr;
	
	public SparseTable(int[] arr) {
		this.arr=arr;
		int k =(int) (Math.floor(Math.log(arr.length)/Math.log(2)))+1;
		int n=arr.length;
		spt=new int[n][k];
		for(int i=0;i<n;i++)
			spt[i][0]=i;
		
		for(int j=1;j<=k;j++) {
			for(int i=0;i+(1<<j)-1<n;i++) {
				if(arr[spt[i][j-1]]>=arr[spt[i+(1<<(j-1))][j-1]])
					spt[i][j]=spt[i][j-1];
				else
					spt[i][j]=spt[i+(1<<(j-1))][j-1];
			}
		}
		
		log=new int[n+1];
		for(int i=2;i<=n;i++)
			log[i]=log[i/2]+1;
		
	}
	int query(int l , int r) {
		int k =log[(r-l+1)];
		if(arr[spt[l][k]]>=arr[spt[r-(1<<k)+1][k]])
			return spt[l][k];
		else
			return spt[r-(1<<k)+1][k];
	}
}

//static class SparseTable{
//int[][] spt;
//int n;
//int k;
//int[] log;
//static int gcd(int a ,int b) {
//	return (a==0)?b:gcd(b%a,a);
//}
//
//public SparseTable(int[] arr) {
//	n=arr.length;
//	
//	k=(int)( Math.floor(Math.log(arr.length)/Math.log(2))+1);
//	spt=new int[n][k];
//	for(int i=0;i<n;i++)spt[i][0]=arr[i];
//	
//	for(int j=1;j<=k;j++)
//		for(int i=0;i+(1<<j)-1<n;i++)
//			spt[i][j]=gcd(spt[i][j-1],spt[i+(1<<(j-1))][j-1]);
//	
//	log=new int[n+1];
//	for(int i=2;i<=n;i++)
//		log[i]=log[i/2]+1;
//}
//public int query(int l , int r) {
//	int k=log[r-l+1];
//	return gcd(spt[l][k],spt[r-(1<<k)+1][k]);
//}
//
//}
static class Pair implements Comparable<Pair>{
	long  x;int y,z;
	public Pair(long a,int b, int c) {
		this.x=a;y=b;this.z=c;
	}


	public int compareTo(Pair o) {
		//return (this.x==o.x)?(this.y==o.y)?z-o.z:this.y-o.y:this.x-o.x;
		return this.x>o.x?1:(this.x<o.x)?-1:0;
	}

}




static class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}
	public Scanner(String s) throws FileNotFoundException{	br = new BufferedReader(new FileReader(s));}


	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine()," ,");
		return st.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}


	public double nextDouble() throws IOException {
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if (x.charAt(0) == '-') {
			neg = true;
			start++;
		}
		for (int i = start; i < x.length(); i++) {
			if (x.charAt(i) == '.') {
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			} else {
				sb.append(x.charAt(i));
				if (dec)
					f *= 10;
			}
			if (sb.length() == 18) {
				res += Long.parseLong(sb.toString()) / f;
				sb = new StringBuilder("0");
			}
		}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg ? -1 : 1);
	}

	public boolean ready() throws IOException {
		return br.ready();
	}

}

public static void shuffle(int[] a) {
	int n = a.length;
	for (int i = 0; i < n; i++) {
		int r = i + (int) (Math.random() * (n - i));
		int tmp = a[i];
		a[i] = a[r];
		a[r] = tmp;
	}
}
}
