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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author prakharjain
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        _675E solver = new _675E();
        solver.solve(1, in, out);
        out.close();
    }

    static class _675E {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();

            int[] a = new int[n];

            for (int i = 0; i < n - 1; i++) {
                a[i] = in.nextInt();
            }

            a[n - 1] = n;

            long[] ans = new long[n];

            ans[n - 2] = 1;

            SegmentTree st = new SegmentTree(n);
            st.build(0, a, 0, n - 1);

            long fans = 1;
            for (int i = n - 3; i >= 0; i--) {
                SegmentTree.node node = st.query(0, 0, n - 1, i + 1, a[i] - 1);

                long ca = ans[node.i];
                ca -= a[i] - 1 - node.i;
                ca += n - a[i];
                ca += a[i] - 1 - i;

                ans[i] = ca;

                fans += ans[i];
            }

            out.print(fans);
        }

        class SegmentTree {
            node[] st;
            int n;

            public SegmentTree(int n) {
                st = new node[4 * n];
                this.n = n;
            }

            node build(int i, int[] a, int r1, int r2) {
                if (r1 == r2) {
                    return st[i] = new node(a[r1], r1);
                } else {
                    node p1 = build(i * 2 + 1, a, r1, (r1 + r2) / 2);
                    node p2 = build(i * 2 + 2, a, (r1 + r2) / 2 + 1, r2);

                    if (p1.max >= p2.max) {
                        return st[i] = new node(p1.max, p1.i);
                    } else {
                        return st[i] = new node(p2.max, p2.i);
                    }
                }
            }

            node query(int i, int ra, int rb, int r1, int r2) {
                if (ra > r2 || rb < r1) {
                    return null;
                }

                if (ra >= r1 && rb <= r2) {
                    return st[i];
                }

                node p1 = query(i * 2 + 1, ra, (ra + rb) / 2, r1, r2);
                node p2 = query(i * 2 + 2, (ra + rb) / 2 + 1, rb, r1, r2);

                if (p1 == null) {
                    return p2;
                } else if (p2 == null) {
                    return p1;
                } else {
                    if (p1.max >= p2.max) {
                        return new node(p1.max, p1.i);
                    } else {
                        return new node(p2.max, p2.i);
                    }
                }
            }

            class node {
                long max;
                int i;

                public node(long max, int i) {
                    this.max = max;
                    this.i = i;
                }

                public node(node node) {
                    this.max = node.max;
                    this.i = node.i;
                }

            }

        }

    }

    static class OutputWriter {
        private final 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 close() {
            writer.close();
        }

        public void print(long i) {
            writer.print(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

