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.ArrayList;
import java.util.Arrays;

public class ProblemE {
    StreamTokenizer in;
    PrintWriter out;
    int N;
    long answer = 0;
    int[] toStation;
    int[] SegmTreeMax;
    long[] ticketSums;

    public static void main(String[] args) throws IOException {
        new ProblemE().run();
    }

    void run() throws IOException
    {
        in  = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
    }

    private void solve() throws IOException{
        N = nextInt();
        toStation = new int[N];
        for (int i=0;i<N-1;i++){
          toStation[i] = nextInt()-1;
        }
        toStation[N-1] = N-1;

        SegmTreeMax = new int[4*N];
        fillSegmTree(1, 0, N-1);

        ticketSums = new long[N];
        int curMaxInd;
        for (int i=N-2;i>=0;i--) {
            curMaxInd = getMaxIndex(1, 0, N-1, i+1, toStation[i]);
//            out.println(i+1 + " " + curMaxInd + " " + toStation[i]);
            ticketSums[i] = ((N-1)-i) + ticketSums[curMaxInd] - (toStation[i] - curMaxInd);
            answer += ticketSums[i];
        }
        out.println(answer);
//        out.println(Arrays.toString(SegmTreeMax));
//        out.println(Arrays.toString(ticketSums));

    }

    private void fillSegmTree(int v, int vl, int vr) {
        if (vl==vr) {
            SegmTreeMax[v] = vl;
        }
        else {
            int vm = (vr - vl)/2 + vl;
            fillSegmTree(v*2, vl, vm);
            fillSegmTree(v*2+1, vm+1, vr);
            int left  = SegmTreeMax[v*2];
            int right = SegmTreeMax[v*2+1];
            SegmTreeMax[v] = (toStation[left] > toStation[right])?SegmTreeMax[v*2]:SegmTreeMax[v*2+1];
        }
    }

    private int getMaxIndex(int v, int begin, int end, int beginCur, int endCur){
        if (beginCur > endCur){
            return -1;
        }
        if (begin == beginCur && end == endCur){
            return SegmTreeMax[v];
        }
        int middle = (end - begin)/2 + begin;
        int left  = getMaxIndex(v*2, begin, middle, beginCur, Math.min(middle, endCur));
        int right = getMaxIndex(v*2 + 1, middle+1, end, Math.max(middle+1, beginCur), endCur);
        if ( (left == -1) || ( right != -1 && toStation[right] > toStation[left] )) {
            return right;
        }
        else if ( right == -1  || toStation[right] < toStation[left] ) {
            return left;
        }
        else {
            return Math.max(right, left);
        }
    }

    int nextInt() throws IOException
    {
        in.nextToken();
        return (int)in.nval;
    }
}
