CF961E.Tufurama

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn seasons (numbered 11 through nn ), the ii -th season has aia_{i} episodes (numbered 11 through aia_{i} ). Polycarp thinks that if for some pair of integers xx and yy ( x<yx<y ) exist both season xx episode yy and season yy episode xx then one of these search queries will include the wrong results. Help Polycarp to calculate the number of such pairs!

输入格式

The first line contains one integer nn (1<=n<=2105)(1<=n<=2·10^{5}) — the number of seasons.

The second line contains nn integers separated by space a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ai<=109)(1<=a_{i}<=10^{9}) — number of episodes in each season.

输出格式

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

输入输出样例

  • 输入#1

    5
    1 2 3 4 5
    

    输出#1

    0
    
  • 输入#2

    3
    8 12 7
    

    输出#2

    3
    
  • 输入#3

    3
    3 2 1
    

    输出#3

    2
    

说明/提示

Possible pairs in the second example:

  1. x=1x=1 , y=2y=2 (season 1 episode 2 season 2 episode 1);
  2. x=2x=2 , y=3y=3 (season 2 episode 3 season 3 episode 2);
  3. x=1x=1 , y=3y=3 (season 1 episode 3 season 3 episode 1).

In the third example:

  1. x=1x=1 , y=2y=2 (season 1 episode 2 season 2 episode 1);
  2. x=1x=1 , y=3y=3 (season 1 episode 3 season 3 episode 1).
首页