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 math
import sys


class MaxSqrtList(object):
    def __init__(self, list_total):
        self.list_total = list_total
        self.bucket_size = int(math.floor(math.sqrt(len(list_total))))
        buckets_num = len(list_total) / self.bucket_size
        if len(list_total) % self.bucket_size != 0:
            buckets_num += 1

        self.buckets = [(-1, -1)] * buckets_num
        for index, element in enumerate(list_total):
            bucket_index = index / self.bucket_size
            if element >= self.buckets[bucket_index][0]:
                self.buckets[bucket_index] = (element, index)

    def __len__(self):
        return len(self.list_total)

    def __getitem__(self, element):
        return self.list_total[element]


    def _get_bucket(self, element):
        return element / self.bucket_size

    def _get_bucket_index(self, element):
        return element % self.bucket_size

    def _get_bucket_margins(self, bucket):
        return self.bucket_size * bucket,  min(self.bucket_size * (bucket + 1) - 1, len(self.list_total) - 1)

    def max(self, left, right):
        if left < 0 or right >= len(self.list_total) or left > right:
            raise ValueError("Bad margins: left %s, right %s" % (left, right))
        left_bucket_num = self._get_bucket(left)
        left_bucket_margins = self._get_bucket_margins(left_bucket_num)
        left_bucket_index = self._get_bucket_index(left)

        right_bucket_num = self._get_bucket(right)
        right_bucket_margins = self._get_bucket_margins(right_bucket_num)
        right_bucket_index = self._get_bucket_index(right)

        item_index = 0
        item_max = 0
        if left_bucket_num == right_bucket_num:
            for index, element in enumerate(self.list_total[left: right + 1]):
                if element >= item_max:
                    item_max = element
                    item_index = left + index
        else:
            if left_bucket_index == 0:
                if self.buckets[left_bucket_num] >= item_max:
                    item_max = self.buckets[left_bucket_num][0]
                    item_index = self.buckets[left_bucket_num][1]
            else:
                for index, element in enumerate(self.list_total[left: left_bucket_margins[1] + 1]):
                    if element >= item_max:
                        item_max = element
                        item_index = left + index

            for index, element in enumerate(self.buckets[left_bucket_num + 1: right_bucket_num]):
                if element[0] >= item_max:
                    item_max = element[0]
                    item_index = element[1]
            if right == right_bucket_margins[1]:
                if self.buckets[right_bucket_num][0] >= item_max:
                    item_max = self.buckets[right_bucket_num][0]
                    item_index = self.buckets[right_bucket_num][1]
            else:
                for index, element in enumerate(self.list_total[right_bucket_margins[0]: right + 1]):
                    if element >= item_max:
                        item_max = element
                        item_index = index + right_bucket_margins[0]

        return item_index, item_max

#
# k..node...a_k..a_m..n
#

if __name__ == "__main__":
    n = int(sys.stdin.readline().strip())
    ai = MaxSqrtList([int(a) - 1 for a in sys.stdin.readline().strip().split()] + [n-1])

    si = [0] * len(ai)

    for k in range(len(ai) - 2, -1, -1):
        node, a_m = ai.max(k + 1, ai[k])
        si[k] = si[node] + (ai[k] - k) - (ai[k] - node) + (len(ai) - 1 - ai[k])

    print sum(si)


