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

public class Cf1605E {
    private static InputReader in = new InputReader(System.in);
    private static OutputWriter out = new OutputWriter(System.out);




    private static void solve() throws Exception{
        int n = in.readInt();
        int[] a = new int[n-1];
        for(int i=0; i<n-1; ++i){
            a[i] = in.readInt()-1;
        }
        int size = n;
        if((n&n-1)!=0){
            size = Integer.highestOneBit(n);
            size <<=1;
        }
        int[] aa = Arrays.copyOf(a,size);
        SegmentTree segmentTree = new SegmentTree(aa);
        long[] dp = new long[n-1];
        dp[n-2] = 1;
        long answer = 1;
        for(int i=n-3; i>=0; --i){
            int maxIndex = segmentTree.rangeMaxIndex(1,i+1,a[i]);
            dp[i] = dp[maxIndex]-(a[i]-maxIndex)+n-i-1;
            answer += dp[i];
        }

        out.println(answer);



    }



    public static void main(String[] args) throws Exception {
        solve();
        out.close();
    }



    private static class SegmentTree{
        Node[] holder;
        int[] a;
        SegmentTree(int[] a){
            holder = new Node[2*a.length];
            this.a = a;
            build(1,0,a.length-1);
        }

        void build(int v, int from, int to){
            if(from==to){
                holder[v] = new Node(from,to,from);
                return;
            }
            build(2*v,from,(from+to)/2);
            build(2*v+1,1+(from+to)/2,to);
            int maxInd;
            if(a[holder[2*v].maxIndex]>a[holder[2*v+1].maxIndex]){
                maxInd = holder[2*v].maxIndex;
            }
            else{
                maxInd = holder[2*v+1].maxIndex;
            }
            holder[v] = new Node(from,to,maxInd);
        }

        int rangeMaxIndex(int v,int from, int to){
            if((holder[v].to<from)||(holder[v].from>to)){
                return -1;
            }
            if(holder[v].from==holder[v].to){
                return holder[v].maxIndex;
            }
            if((holder[v].from>=from)&&(holder[v].to<=to)){
                return holder[v].maxIndex;
            }
            int lIndex = rangeMaxIndex(2*v,from,to);
            int rIndex = rangeMaxIndex(2*v+1,from,to);
            if(lIndex==-1){
                return rIndex;
            }
            if(rIndex==-1){
                return lIndex;
            }
            if(a[lIndex]>=a[rIndex]){
                return lIndex;
            }
            return rIndex;
        }
    }

    private static class Node{
        int from;
        int to;
        int maxIndex;
        Node(int from, int to, int maxIndex){
            this.from = from;
            this.to = to;
            this.maxIndex = maxIndex;
        }
    }

    private static class InputReader {
        private InputStream stream;
        private byte[] buffer;
        private int currentIndex;
        private int bytesRead;

        public InputReader(InputStream stream) {
            this.stream = stream;
            buffer = new byte[131072];
        }


        public InputReader(InputStream stream, int bufferSize) {
            this.stream = stream;
            buffer = new byte[bufferSize];
        }


        private int read() throws IOException {
            if (currentIndex >= bytesRead) {
                currentIndex = 0;
                bytesRead = stream.read(buffer);
                if (bytesRead <= 0) {
                    return -1;
                }
            }
            return buffer[currentIndex++];
        }

        public String readString() throws IOException {
            int c = read();
            while (!isPrintable(c)) {
                c = read();
            }
            StringBuilder result = new StringBuilder();
            do {
                result.appendCodePoint(c);
                c = read();
            } while (isPrintable(c));
            return result.toString();
        }

        public int readInt() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            int result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public long readLong() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            long result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public double readDouble() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            boolean fraction = false;
            double multiplier = 1;
            double result = 0;
            do {
                if ((c == 'e') || (c == 'E')) {
                    return sign * result * Math.pow(10, readInt());
                }
                if ((c < '0') || (c > '9')) {
                    if ((c == '.') && (!fraction)) {
                        fraction = true;
                        c = read();
                        continue;
                    }
                    throw new InputMismatchException();
                }
                if (fraction) {
                    multiplier /= 10;
                    result += (c - '0') * multiplier;
                    c = read();
                } else {
                    result *= 10;
                    result += (c - '0');
                    c = read();
                }
            } while (isPrintable(c));
            return sign * result;
        }

        private boolean isPrintable(int c) {
            return ((c > 32) && (c < 127));
        }
    }

    private static class OutputWriter {
        private PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }
    }
}