One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the entire series someday and won't be able to find the right episodes to watch? Polycarp now wants to count the number of times he will be forced to search for an episode using some different method.

TV series have n seasons (numbered 1 through n), the i-th season has a_{i} episodes (numbered 1 through a_{i}). Polycarp thinks that if for some pair of integers x and y (x < y) exist both season x episode y and season y episode x then one of these search queries will include the wrong results. Help Polycarp to calculate the number of such pairs!


-----Input-----

The first line contains one integer n (1  ≤ n  ≤  2·10^5) — the number of seasons.

The second line contains n integers separated by space a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — number of episodes in each season.


-----Output-----

Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.


-----Examples-----
Input
5
1 2 3 4 5

Output
0

Input
3
8 12 7

Output
3

Input
3
3 2 1

Output
2



-----Note-----

Possible pairs in the second example:  x = 1, y = 2 (season 1 episode 2 [Image] season 2 episode 1);  x = 2, y = 3 (season 2 episode 3 [Image] season 3 episode 2);  x = 1, y = 3 (season 1 episode 3 [Image] season 3 episode 1). 

In the third example:  x = 1, y = 2 (season 1 episode 2 [Image] season 2 episode 1);  x = 1, y = 3 (season 1 episode 3 [Image] season 3 episode 1).

Difficulty: interview

Starter code:

Solutions:
import sys

class RangeBit:
    def __init__(self, n):
        sz = 1
        while n >= sz:
            sz *= 2
        self.size = sz
        self.dataAdd = [0 for _ in range(sz)]
        self.dataMul = [0 for _ in range(sz)]

    def sum(self, i):
        assert i > 0
        add, mul, start = 0, 0, i
        while i > 0:
            add += self.dataAdd[i]
            mul += self.dataMul[i]
            i -= i & -i
        return mul * start + add

    def add(self, left, right, by):
        assert 0 < left <= right
        self._add(left, by, -by * (left - 1))
        self._add(right, -by, by * right)

    def _add(self, i, mul, add):
        assert i > 0
        while i < self.size:
            self.dataAdd[i] += add
            self.dataMul[i] += mul
            i += i & -i

n = int(input())
l = list(map(int, sys.stdin.readline().split()))

queries = []
for i in range(n):
    if min(l[i], n) >= i+2:
        queries.append((i+2, min(l[i], n), i+1))

result = 0

a = sorted(list(zip(list(range(1, n+1)), l)) + queries, key=lambda x:(-x[-1], len(x)))
ft = RangeBit(n+1)

for el in a:
    #print(el)
    if len(el) == 2: #update
        ind, val = el
        ft.add(ind, ind, 1)
    else: #query
        fr, to, val = el
        # print(fr, to, val)
        # print(ft.sum(to) - (ft.sum(fr - 1) if fr > 1 else 0))
        result += ft.sum(to) - (ft.sum(fr - 1) if fr > 1 else 0)

print(result)


from sys import stdin
from sys import setrecursionlimit as SRL; SRL(10**7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())


n = int(rd())
a = list(rrd())

bit = [0] * (n+10)


def get(x):
    tot = 0
    while x:
        tot += bit[x]
        x -= x&(-x)
    return tot

def ins(x):
    while x<=(n+1):
        bit[x] += 1
        x += x&(-x)

b = []
preans = 0
for i,v in enumerate(a):
    if v > i:
        preans += 1
    b.append([i+1,v])

b.sort(key=lambda x:x[1])

ans = 0
i = 0

for x in b:
    while i<n and i < x[1]:
        ins(a[i])
        i += 1
    ans += i - get(x[0] - 1)


print((ans-preans)//2)

import sys
from collections import defaultdict


class BIT_RSQ(object):
    __slots__ = ['nodes', 'size']

    def __init__(self, size: int):
        self.nodes = [0]*(size+1)
        self.size = size+1

    def add(self, index: int, value: int):
        while index < self.size:
            self.nodes[index] += value
            index += index & -index

    def sum(self, right: int):
        result = 0

        while right:
            result += self.nodes[right]
            right -= right & -right

        return result


n = int(input())
a = list(map(int, input().split()))
bit = BIT_RSQ(n+10)
remove = defaultdict(list)
ans = 0

for i, x in enumerate(a, start=1):
    ans += bit.sum(min(i, x))
    if i < x:
        bit.add(i, 1)
        remove[min(n+1, x)].append(i)
    for j in remove[i]:
        bit.add(j, -1)

print(ans)