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.
//package com.company.codeforces.div2.div353;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

/**
 * Created by Daniil on 5/16/2016.
 */
public class Task4 {

    public static int currIndex;

    public static Pair[] intervalTree;

    public static long[] dp;
    public static int mx = 1<<18;

    public static int strIndex;
    public static void main(String[] args) throws IOException {

        //Scanner scanner = new Scanner(new FileInputStream("file.in"));
        //BufferedReader br = new BufferedReader(new FileReader("file.in"));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(br.readLine());

        char[] nums = br.readLine().toCharArray();
        strIndex = 0;

        int[] input = new int[n];
        for (int i = 0; i < n - 1; ++ i){
            int num = nextInt(nums);
            input[i] = num - 1;
            strIndex++;
        }
        input[n - 1] = n - 1;

        buildTree(input);

        dp = new long[n];

        dp[n-1] = 0;

        long sum = 0;
        for (int i = n - 2; i >= 0; -- i){
            int m = getMax(i + 1, input[i]).first;
            dp[i] = dp[m] - (input[i] - m) + n - i - 1;
            sum += dp[i];
        }

        System.out.println(sum);
        br.close();
        //scanner.close();
    }

    public static void buildTree(int[] input){
        intervalTree = new Pair[(mx) * 2];

        for (int i = 0; i < (mx) * 2; ++ i)intervalTree[i] = new Pair(-1,-1);
        for (int i = 0;i < input.length; ++ i){
            intervalTree[(mx) + i] = new Pair(i, input[i]);
        }

        for (int i = mx - 1; i > 0; -- i){
            if (intervalTree[i * 2].second > intervalTree[i * 2 + 1].second){
                intervalTree[i] = new Pair(intervalTree[i * 2].first, intervalTree[i * 2].second);
            }else{
                intervalTree[i] = new Pair(intervalTree[i * 2 + 1].first, intervalTree[i * 2 + 1].second);
            }
        }
    }

    public static Pair getMax(int l, int r){
        l = l + mx;
        r = r + mx;
        Pair res = new Pair(-1, -1);
        while (l <= r){
            if (l % 2 == 1){
                if (res.second < intervalTree[l].second){
                    res = intervalTree[l];
                }
            }

            if (r % 2 != 1){
                if (res.second < intervalTree[r].second){
                    res = intervalTree[r];
                }
            }

            l = (l + 1) / 2;
            r = (r - 1) / 2;
        }

        return res;
    }

    public static class Pair{
        public int first;
        public int second;

        public Pair(int first, int second) {
            this.first = first;
            this.second = second;
        }
    }

    public static int nextInt(char[] nums){
        int sum = 0;
        for (;strIndex < nums.length; ++ strIndex){
            if (nums[strIndex] == ' ')break;
            sum = sum * 10 + (nums[strIndex] - '0');
        }
        return sum;
    }

}
