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 A implements Runnable{
	public static void main (String[] args) {new Thread(null, new A(), "Skyrim 2 days hype", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int n = fs.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n-1; i++) a[i] = fs.nextInt()-1;
		
		ST st = new ST(n, a);
		
		long[] dp = new long[n];
		long res = 0;
		for(int i = n-2; i >= 0; i--) {
			if(a[i] == n-1) {
				dp[i] = n - i - 1;
				res += dp[i];
				continue;
			}
			int len = a[i] - i;
			int best = st.max(1, 0, n-1, i+1, a[i]);
			dp[i] = len + dp[best] - (a[i] - best) + (n - a[i] - 1);
			res += dp[i];
		}
		
		out.println(res);

		out.close();
	}
	
	class ST {
		int n;
		int[] a;
		int[] tree;
		int[] best;
		
		ST (int b, int[] a) {
			this.a = a;
			n = b;
			tree = new int[4 * n];
			init(1, 0, n-1);
		}
		
		void init (int p, int l, int r) {
			if(l == r) {
				tree[p] = l;
				return;
			}
			int mid = (l + r) >> 1;
			init(2 * p, l, mid);
			init(2 * p + 1, mid+1, r);
			if(a[tree[2 * p]] >= a[tree[2 * p + 1]]) {
				tree[p] = tree[2 * p];
			} else {
				tree[p] = tree[2 * p + 1];
			}
		}
		
		int max (int p, int l, int r, int ol, int or) {
			if(l > or || r < ol) return -1;
			if(l >= ol && r <= or) {
				return tree[p];
			}
			int mid = (l + r) >> 1;
			int p1 = max(2 * p, l, mid, ol, or);
			int p2 = max(2 * p + 1, mid+1, r, ol, or);
			if(p1 == -1) {
				return p2;
			}
			if(p2 == -1) {
				return p1;
			}
			if(a[p1] >= a[p2]) return p1;
			return p2;
		}
		
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
//				br = new BufferedReader(new FileReader("chess.in"));
				st = new StringTokenizer("");
			} catch (Exception e){e.printStackTrace();}
		}
		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}
		public int nextInt() {return Integer.parseInt(next());}
		public long nextLong() {return Long.parseLong(next());}
		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			try {line = br.readLine();}
			catch (Exception e) {e.printStackTrace();}
			return line;
		}
		public Integer[] nextIntegerArray(int n) {
			Integer[] a = new Integer[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public char[] nextCharArray() {return nextLine().toCharArray();}
	}

}