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.math.BigInteger;
import java.security.SecureRandom;
import java.util.*;

/**
 * Created by noureldin on 4/05/17.
 */

public class Main {
    private static final int MAX = 100*1000 + 10;
    private static int A[] = new int[MAX];
    private static long ST[] = new long[MAX << 2];
    private static int n;
    private static void build(int node,int s,int e) {
        ST[node] = 1 << 28;
        if(s == e) return;
        int m = (s + e) >> 1,left = node << 1,right = left | 1;
        build(left,s,m);
        build(right,m+1,e);
    }
    private static void update(int node,int s,int e,int p,long v){
        if(s == e) {
            ST[node] = p + v;
            return;
        }
        int m = (s + e) >> 1,left = node << 1,right = left | 1;
        if(p <= m) update(left,s,m,p,v);
        else update(right,m+1,e,p,v);
        ST[node] = Math.min(ST[left],ST[right]);
    }
    private static long query(int node,int s,int e,int l,int r){
        if(l <= s && e <= r) return ST[node];
        int m = (s + e) >> 1,left = node << 1,right = left | 1;
        if(r <= m) return query(left,s,m,l,r);
        if(m < l) return query(right,m+1,e,l,r);
        return Math.min(query(left,s,m,l,m),query(right,m+1,e,m+1,r));
    }

    public static void main(String[] args) throws Exception{
        IO io = new IO(null,null);
        n = io.getNextInt();
        for (int i = 1;i < n;i++) A[i] = io.getNextInt();
        build(1,1,n);
        update(1,1,n,n,0);
        long ans = 0;
        for (int i = n-1;i >= 1;i--) {
            long t = n - i - A[i] + query(1,1,n,i+1,A[i]);
            update(1,1,n,i,t);
            ans += t;
        }
        io.println(ans);
        io.close();
    }
}




class IO{
    private BufferedReader br;
    private StringTokenizer st;
    private PrintWriter writer;
    private String inputFile,outputFile;

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

    public String getNextLine() throws FileNotFoundException, IOException{
        return br.readLine().trim();
    }

    public int getNextInt() throws FileNotFoundException, IOException{
        return Integer.parseInt(getNext());
    }
    public long getNextLong() throws FileNotFoundException, IOException{
        return Long.parseLong(getNext());
    }

    public void print(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f" ,x);
    }
    public void println(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f\n" ,x);
    }
    public void print(Object o) throws  IOException{
        writer.print(o.toString());
    }

    public void println(Object o) throws  IOException{
        writer.println(o.toString());
    }
    public IO(String x,String y) throws FileNotFoundException, IOException{
        inputFile = x;
        outputFile = y;
        if(x != null) br = new BufferedReader(new FileReader(inputFile));
        else br = new BufferedReader(new InputStreamReader(System.in));
        if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
        else writer = new PrintWriter(new OutputStreamWriter(System.out));
    }

    protected void close() throws IOException{
        br.close();
        writer.close();
    }
}
