Problem:


Score: 500 points

Problem Statement

You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.

There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i.

According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.

The absolute difference of their attendee numbers is equal to the sum of their heights.

There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above?

P.S.: We cannot let you know the secret.

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the number of pairs satisfying the condition.

Sample Input 1

6
2 3 3 1 3 1

Sample Output 1

3

A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.

A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.

A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.

No other pair satisfies the condition, so you should print 3.

Sample Input 2

6
5 2 4 2 8 8

Sample Output 2

0

No pair satisfies the condition, so you should print 0.

Sample Input 3

32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Sample Output 3

22



Sample input:
6
2 3 3 1 3 1


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = tuple(map(int, input().split()))

cnt = 0
# for i in range(N):
#     for j in range(i+1, N):
#         if j - i == As[i] + As[j]:
#             cnt += 1

for i, a in enumerate(As):
    end = i+a if i+a <= N else N
    forward = As[end+1:]

    hoge = list(j+1 == v for j, v in enumerate(forward))

    cnt += sum(hoge)

    # end = i-a if i-a >= 0 else 0
    # backward = As[:end+1]
    
    # import ipdb; ipdb.set_trace()

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n=int(input())
a=list(map(int,input().split()))


b=[]
for i in range(1,n):
  b.append(a[i]+a[0])

c=[i for i in range(n)]

b=np.array(b)
c=np.array(c)
c=c[1:]

ans=0
ans+=np.sum(b==c)
for i in range(1,n):
  b+=a[i]-a[i-1]
#  b=b[1:]

  c-=1
#  c=c[1:]

  ans+=np.sum(b==c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

# coding: utf-8
# Your code here!
#N, K = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)

count = 0

for d in range(1,N):
    #print(d)
    buf = A[:-d]+A[d:]
    #print(buf)
    #print(d, len(buf[buf==d]))
    #差がdのペア
    #print(A[:-d]-A[d:])
    count += len(buf[buf==d])
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
#N, K = (int(i) for i in input().split())
#B = [int(x) for x in stdin.readline().rstrip().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
seen = set()
for i in range(1, N+1):
    for j in range(A[i-1]+1, N+1):
        if (j, i) in seen:
            continue
        seen.add((i, j))

        # print(A)
for i, j in seen:
    if abs(j-i) == A[i-1]+A[j-1]:
        #print(j, i)
        ans += 1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
alist=list(map(int,input().split()))
count=0
for i in range(n-1):
    for j in range(i+1,n):
        if j-i==alist[j]+alist[i]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(n):
  for j in range(i+1,n):
    if j-i == a[j]+a[i]:
      s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int,input().split()))

a1_list = []
a2_list = []
for i in range(n):
    a1_list.append(a_list[i]+i+1)
    a2_list.append(-a_list[i]+i+1)
a1_list.sort()
a2_list.sort()
tmp = 0
cnt = 0
for a1_idx in range(n):
    a2_idx = tmp
    a1 = a1_list[a1_idx]
    if tmp == n:
        break
    while a2_idx <= n-1 and  a1 >= a2_list[a2_idx]:
        if a1 == a2_list[a2_idx]:
            cnt += 1
        else:
            tmp = a2_idx
            if tmp == n:
                tmp = tmp-1
        a2_idx += 1
        
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

import numpy as np
n = int(input())
h = [int(x) for x in input().split()]
count = 0
for i in range(n):
    for k in range(i,n):
        height = np.abs(h[i] + h[k])
        if k - i == height:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
H = list(map(int,input().split()))
count=0
for i in range(N):
    h_i = H[i]
    j = i+1
    while j < N:
        if (j-i) == (H[j]+h_i):
            count+=1
        
        j+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3


def main():
    N = int(input())
    A = [i for i in map(int, input().split())]
    #print (N, A)
    gsize = 20
    numg = (N - 1) // gsize + 1
    maxg = [0] * numg
    ming = [0] * numg
    size = len(A)
    for g in range(0, numg):
        gA = A[gsize*g:min(gsize*(g+1), size)]
        maxg[g] = max(gA)
        ming[g] = min(gA)

    count = 0
    for g1 in range(0, numg):
        for g2 in range(g1, numg):
            #print('checking group', g1, g2)
            gd = abs(g1 - g2)
            if maxg[g1] + maxg[g2] < gsize * (gd - 1):
                continue
            if ming[g1] + ming[g2] > gsize * (gd + 1):
                continue
            for g1i in range(gsize*g1, min(gsize*(g1+1), size)):
                for g2i in range(max(g1i+1, gsize*g2), min(gsize*(g2+1), size)):
                    d = abs(g1i - g2i)
                    if A[g1i] + A[g2i] == d:
                        count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    A_arr_sort = sorted(A_arr)
    height_range = [sum(A_arr_sort[:2]),min(sum(A_arr_sort[-2:]),N-1)]
    cnt = 0
    for height in range(height_range[0],height_range[1]+1):
        for i in range(N-height):
            j = i+height
            if A_arr[j]+A_arr[i]==j-i:
                cnt += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    if A[i] + A[j] == j - i:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input());a=list(map(int,input().split()))
print(len([True for i in range(n)for s in range(i,n)if a[i]+a[s]==abs(i-s)]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A=list(map(int, input().split()))
B=[A[i]+i+1 for i in range(n)]
C=[j+1-A[j] for j in range(n)]
C2=set(C)

t=0
for i in range(n):
  if B[i] in C2:
    t+= C.count(B[i])
print(t)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L_A = [int(s) for s in input().rstrip().split(' ')]
[M,m] = [0,10**9]
ans = 0
a = 0
for k in range(N,0,-1):
    p = L_A[k-1]
    if p+m <= a:
        for i in range(p+m,min(p+M+1,a+1)):
            if p + L_A[k-1+i] == i:
                ans += 1
    M = max(M,p)
    m = min(m,p)
    a += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(1, len(a)+1):
    for j in range(i+1, len(a)+1):
        if abs(i - j) == (a[i-1] + a[j-1]):
            c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(1, n):
    for j in range(i+a[i-1], n+1):
        if j-i == a[i-1]+a[j-1]:
            c += 1
            
print(c)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n=int(input())
  a=[0]+list(map(int,input().split()))
  ans=0
  for i in range(1,n):
    if a[i]<n-i:
      for j in range(i+1,n+1):
        if j-i==a[i]+a[j]:
          ans+=1
  print(ans)
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N=int(input())
A=deque(map(int,input().split()))
B=deque([])
x=A.popleft()
B.append(x)
s=0
for i in range(N-1):
    x=A.popleft()
    for j in range(i+1):
        if B[j]+x-i-1+j==0:
           s+=1
    B.append(x)
print(s)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
c = Counter(A)
hs = []
for k,v in c.items():
  if v == 1:
    hs.append(k)
  elif v >= 2:
    hs.append(k)
    hs.append(k)
    
    
ts = []    
for cmb in combinations(hs,2):
  ts.append(sum(cmb))
  
ts = list(set(ts))

ans = 0
for h in ts:
  for i in range(n-h):    
    if abs(A[i]+A[i+h]) == h:
      ans += 1
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
n_list=input().split()
count=0
for i in range(N) :
  for j in range(i+1,N) :
    if int(n_list[j])+int(n_list[i])==j-i :
      count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
M = np.asarray(input().split(), dtype=int)
result = 0
for i in range(N):
  x = M[i]
  result += np.sum(M[i+x+1:]==np.arange(1,N-i-x))
print(result)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import numpy as np
# from itertools import *
# from collections import *

# S = input().split()
# N = int(input().split())
# N, K = [int(x) for x in input().split()]

N = int(input())
A = [int(x) for x in input().split()]

number = range(1, N+1)
numhei = [0] * N
for n in range(N):
    numhei[n] = number[n] + A[n]

numhei = np.array(numhei)

count = 0
for n in number:
    count += sum(n - A[n-1] == numhei[0:n-1])

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A=list(map(int, input().split()))
sumx=0
for i in range(N-1):
    for j in range(i+1,N):
        if abs(i-j)==A[i]+A[j]:
            sumx+=1
print(sumx)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A=list(map(int,input().split()))
cnt=0
import numpy as np
table=np.array([[0]*(n+1) for i in range(n)])
B=[]
C=[]
for i,a in enumerate(A):
    B.append(A[i]+i)
    C.append(A[i]-i)
from collections import Counter
Bd=dict(Counter(B))
Cd=dict(Counter(C))
cnt=0
for k in Bd.keys():
    try:
        cnt+=Bd[k]*Cd[-k]
    except KeyError:
        continue
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))

spy = 0
_max = max(A)
for i in range(N-1):
  if i < N:
    for j in range(i+A[i],N):
      if j - i == A[i] + A[j]:
        spy += 1
      if j - i > _max+ A[i]:
        break
      
print(spy)

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
A = [int(i) for i in sys.stdin.readline().rstrip().split()]
#print(N)
#print(A)
count = 0
for i in range(len(A)):
  for l in range(i+1,len(A)):
    if A[i] + A[l] == l - i:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
idList = [i for i in range(1, n+1)]
'''
com = list(itertools.combinations(idList, 2))

num = len(com)
'''
ans = 0

for i in range(1, n + 1):
    for j in range(i + 2, n + 1):
        key = j - i
        heiA = a[i - 1]
        heiB = a[j - 1]
        height = heiA + heiB
        if (height == key):
            ans += 1

print(ans)
'''
for i in range(num):
    aa = com[i]
    # print(aa)
    idA = aa[0]
    idB = aa[1]
    dif = abs(idA - idB)
    indexA = idList.index(idA)
    indexB = idList.index(idB)

    height = a[indexA] + a[indexB]

    if (height == dif):
        ans += 1

print(ans)
'''

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
N = int(input())
#A = np.array([int(i) for i in input().split()], dtype='int')
A = [int(i) for i in input().split()] 

arr = []
count = 0
for a in A:
    tmp_list = []
    for x in A:
      tmp_list.append(x+a)
    arr.append(tmp_list)

for i, lis in enumerate(arr):
    for j, x in enumerate(lis[i:]):
      if x == j:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[0]*n
a[:]=map(int,input().split())
import numpy as np
r=0
for ii in range(n):
  for jj in np.arange(ii+1,n):
    if a[ii]+a[jj]==jj-ii:
      r+=1
print(r)

Submission status: Time Limit Exceeded

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

import numpy as np
n=n0()
a=n1()
A=np.array(a)

ans=0
for i in range(n):
    h=A[i]
    B=np.array(range(-i,-i+n))
    C=abs(B)-A-h
    ans+=n-np.count_nonzero(C)
print(ans//2)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import math
read = sys.stdin.readline

N = int(read().rstrip())
A = list(map(int,read().rstrip().split()))
da = []
for i , a in enumerate(A):
    da.append([i,a])

sumN = [0] * N
for i , a in enumerate(A):
    sumN[i] = i + a + 1


newA = sorted(da , key = lambda x:(x[1]))
ans = 0
for s in sumN :
    if s > 200000:
        continue

    for a in newA :
        if s + a[1] > 200000:
            break

        if s  + a[1]  == a[0] + 1:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
l = len(A)
a = []
a = [[i,j] for i in range(l) for j in range(i,l) if (j - i)==A[i]+A[j]]
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
l=np.array(list(map(int,input().split())))
r=list(np.arange(1,n)-l[1:])
rx=sorted(r)
for i in range(n-1):
  r[i]=[r[i],i]
r=sorted(r)
t=list(l+np.arange(n))
ans=0
import bisect
for i in range(n):
  le=bisect.bisect_left(rx,t[i])
  ri=bisect.bisect_right(rx,t[i])
  for j in range(ri-le):
    if i<r[le+j][1]:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter
from collections import defaultdict
N = int(input())
A = [int(v) for v in input().split()]
cnt = 0
left_list = [i + a for i, a in enumerate(A, 1)]
right_list = [i - a for i, a in enumerate(A, 1)]
right_dict = defaultdict(set)
for i, right in enumerate(right_list, 1):
    right_dict[right].add(i)
for i, left in enumerate(left_list, 1):
    pair_num = len(right_dict[left] - set([i]))
    cnt += pair_num
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
import itertools
num = [i for i in range(n)]
l = list(itertools.combinations(num, 2))
ans = 0
for i in l:
    if a[i[0]]+a[i[1]] == i[1]-i[0]:
        ans += 1
            #print(s,i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))

def func(lst1,lst2):
    lst3=[]
    for i in range(len(lst1)):
        lst3.append(lst1[i]-lst2[i])

    lst3.sort()

    num=0
    for s in lst3:
        if s>0:
            break
        elif s==0:
            num+=1
    return num

ans=0
for i in reversed(list(range(0,N))):
    lst=[]
    for j in list(range(0,i)):
        lst.append(i-j-A[i])

    ans += func(A[:i],lst)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        if j - i == a[j] + a[i]:
            ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    answer = 0
    for i in range(N):
        for j in range(i + A[i] + 1, N):
            if A[i] + A[j] == j - i:
                answer += 1
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a = [int(_) for _ in input().split()]
ans=0
for x in range(n-1):
    for y in range(x + 1, n):
        if abs(y - x) == a[x] + a[y]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(N-1,0,-1):
    num=a[i]
    for j in range(i-num+1):
        if a[j]+num==i-j:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())

# b = []
c = []
for i in range(n):
    # b.append(i+a[i])
    if i<a[i]:
        pass
    else:
        c.append(i-a[i])
# print(b)
# print(c)

ans = 0
for i in range(n):
    m = i + a[i]
    ans += c.count(m)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = np.asarray(list(map(int, input().split())))

# n = 10**5
# a = np.asarray([0] * n)

idx = np.argsort(a)
a = a[idx]

count = 0

for i in range(1, n):
    for j in range(n - i):
        sum_ = a[j] + a[j+i]
        if sum_ >= n:
            break
        if abs(idx[j+i] - idx[j]) == sum_:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
num = int(input())

s = list(map(int, input().split(" ")))

ans = 0
for i in range(num) :
    x = s[i]
    if x > num -i :
        continue
    if i + x < num :
        for j in range(num-i-1-x) :
            y = s[i+j+1+x]
            if j+1 == y:
                ans = ans + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = (int)(input())
count= 0
person = list(map(int, input().split(" ")))
for i in range(0, num - 1):
    for j in range(i + 1, num):
        if j - i == person[j] + person[i]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
def solve():
    n = int(input())
    a = list(map(int, input().split()))

    m = len(a)
    cnt = 0
    for i in combinations(range(m), 2):
        x = i[0]
        y = i[1]
        if abs(x-y) == a[x]+ a[y]:
            cnt += 1



    
    return cnt




print(solve())

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
Agents=list(map(int,input().split()))

# from itertools import combinations

# comb = list(combinations([i for i in range(N)],2))

# cnt=0
# for i in comb:
#     if Agents[i[0]] + Agents[i[1]] == abs(i[0] - i[1]):
#         print(i[0],i[1])
#         cnt+=1

# print(cnt)
cnt=0

for i in range(0,N):
    k=Agents[i]-(i+1)
    if k<i:
        k=i+1
    for j in range(k,N):
        if Agents[i]+Agents[j]==abs(i-j):
            # print(i,j,Agents[i],Agents[j])
            cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))

ans = set([])
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if a[i] + a[j] == abs(i-j):
            d = tuple(list(sorted([i,j])))
            ans.add(d)
ans = len(ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a_list = list(map(int, input().split()))

count = 0
for split_n, a in enumerate(a_list):
    count += np.count_nonzero((np.array(a_list[split_n+1:])) == (np.array([i-a for i in range(1, (n - split_n))])))


print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = list(map(int,input().split()))
a = np.array([],dtype = int)

ans = 0
for i in range(N-1):
    a = np.append(a,1-A[i])
    ans += np.count_nonzero(a==A[i+1])
    a = a + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
num = (int)(input())
count= 0
person = list(map(int, input().split(" ")))
for i in range(0, num - 1):
    for j in range(i + 1, num):
        if j - i == person[j] + person[i]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

ans = []
for i in range(n):
    h = a[i]
    for j in range(0,i-a[i]-1):
        if h + a[j] == abs(j-i):
            ans.append((i,j))
            ans.append((j,i))
    for j in range(a[i]+1,n):
        if h + a[j] == abs(j-i):
            ans.append((i,j))
            ans.append((j,i))

sans = set(ans)

print(len(sans)//2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))

i_plus_Ai = [0 for i in range(N)]
dict = {}
for i in range(N):
    i_plus_Ai[i] = i + As[i]
    tmp = i - As[i]
    if tmp not in dict:
        dict[tmp] = [i]
    else:
        dict[tmp].append(i)
    dict[tmp].sort()

count = 0
for i in range(N):
    if i_plus_Ai[i] in dict:
        kouho = dict[i_plus_Ai[i]]
        for j in range(len(kouho)):
            if kouho[j] > i:
                count += len(kouho) - j
                break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))

count = 0

for diff in range(1, N):
    for i in range(N-diff):
#        print(diff, i, i+diff)
        if i+diff < N and A[i] + A[i+diff] == diff:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():

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

    ans = 0

    for i in range(n):
        if l[i] >= n - i - 1:
            continue
        for j in range(i+2, n):
            if l[i] >= j - i:
                continue
            elif l[i] + l[j] == j - i:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  a_temp = a[i]
  for j in range(i+a_temp, n):
    if a_temp + a[j] == j-i:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
counter = 0
for j in range(1, N):
    for i in range(j + 1, N + 1):
        if j + A[j-1] == i - A[i-1]:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
#N, K = (int(i) for i in input().split())
#B = [int(x) for x in stdin.readline().rstrip().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
seen = set()
for i in range(1, N+1):
    for j in range(A[i-1]+1, N+1):
        if (i, j) in seen:
            continue
        seen.add((i, j))
        seen.add((j, i))

        # print(A)
        if abs(j-i) == A[i-1]+A[j-1]:
            #print(j, i)
            ans += 1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
A = [int(i) for i in input().split()]

st = list(range(n))
st2 = list(itertools.combinations(st,2))


ans = 0


for i in range (len(st2)):
    if A[st2[i][0]] + A[st2[i][1]] == abs(st2[i][0]- st2[i][1]):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
count=0
for i in range(0,N):
    for j in range(max(i+1,A[i]),N):
        if j-i==A[i]+A[j]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
total = 0
for i in range(n):
    for j in range(i+1,n):
        if j-i == a[i]+a[j]:
            total += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0

for i in range(n):
    a_height = h_list[i]
    if n - 1 - i <= a_height:
        continue
    for k in range(i + 1 + a_height, n):
        b_height = h_list[k]
        if k - i == a_height + b_height:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
buf = []
ans = 0
for i in range(n):
    if buf:
        for x in range(len(buf)):
            if buf[x]==a[i]:
                ans += 1
            buf[x] += 1
    buf.append(-(a[i]-1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    lis = list(map(int, input().split()))
    ans = 0

    for i in range(n):
        for j in range(max(i,lis[i]), n):
            if lis[i] + lis[j] == j - i:
                ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
def add(n):
    return n+1
cnt=0
li=[]
for i in range(n):
    cnt += li.count(a[i])
    li=list(map(add,li))
    li.append(1-a[i])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
i = 0
j = 1
ans = 0
p = 0
nextj = 0
while True:
    if j == n:
        i += 1
        p = 0
        j = min(n-1,min(i+a[i]+1,nextj))

    
    if p == 0 and a[i] + a[j] == j-i:
        ans += 1
        nextj = j
        p = 1
    elif p == 1 and a[i] + a[j] == j-i:
        ans += 1
    j += 1
    
    if i == n-1:
        print(ans)
        exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))

checked = {}
cnt = 0

for i in range(N):
    for j in range(N):
        if (i, j) not in checked.keys() and (j, i) not in checked.keys():

            # 番号の差の絶対ｈ氏が伸長の輪に等しい
            if abs(i - j) == A[i] + A[j]:
                cnt += 1
            checked.update({(i, j): True})
            checked.update({(j, i): True})

# print(checked)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
ans=0
b=input().split()

for i in range(a-2):
    for j in range(i+1,a):
        if j-i==int(b[i])+int(b[j]):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import math
read = sys.stdin.readline

N = int(read().rstrip())
A = list(map(int,read().rstrip().split()))
da = []
for i , a in enumerate(A):
    da.append([i,a])

sumN = [0] * N
for i , a in enumerate(A):
    sumN[i] = i + a + 1


newA = sorted(da , key = lambda x:(x[1]))
ans = 0
for s in sumN :
    for a in newA :
        if s + a[1] > 200000:
            break

        if s  + a[1]  == a[0] + 1:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))

cnt = 0

for i in range (N-1):
  for j in range(i+1, N):
    if A[i]+A[j] == abs((i+1)-(j+1)):
      cnt += 1
      
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))

B=[0]*N
for i in range(N):
    if i-A[i]>0:
        B.append(i-A[i])

ans=0
for i in range(N):
    ans+=B.count(i+A[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
#r1 = np.array(range(1,N+1))
#r2 = np.array(range(N,0,-1))
#X = (A-r1)
#Y = (A-r2)
#print(X)
#print(Y)
ans = 0
for i in range(N):
  X = A+A[i]
  r1 = np.array(range(-i,N-i))
  r2 = r1*(-1)
  ans += sum((X+r1)==0)
  ans += sum((X+r2)==0)
  #ans += (sum((X-X[i]*(1))==0)-1)
  #ans += (sum((Y-Y[i]*(1))==0)-1)
print(ans//2)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
a_ls = list(map(int, input().split()))
ans = 0
inds = [i for i in range(n)]
for ind_a, ind_b in combinations(inds, 2):
    Sum = a_ls[ind_a] + a_ls[ind_b]
    diff = abs(ind_a - ind_b)
    if Sum == diff:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))

cnt=0

for i in range(n):
  for j in range(i+a[i],n):
    if j-i==a[i]+a[j]:
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = tuple(map(int, input().split()))
cnt = 0
for i in range(1,n):
    for j in range(i+1,n+1):
        if a[i-1]+a[j-1] == j-i:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n):
    for j in range(i + a[i], n):
        if a[i] + a[j] == j - i:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = min(a)
l = []
for i in range(n):
  if a[i] < 2*10**5-m:
    l.append((i, a[i]))
count = 0

for i in range(len(l)-1):
  for j in range(i+1, len(l)):
    if l[j][0]-l[i][0] == l[j][1]+l[i][1]:
      count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
am = max(a)
ans = 0
for i in range(n-1):
    for j in range(i+a[i], min(n, i+a[i]+am+1)):
        if j-i == a[i]+a[j]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
b=[i+a[i]+1 for i in range(n)]
c=[i-a[i]+1 for i in range(n)]
count=0
for i in range(n-1,-1,-1):
    count+=c.count(b[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list((map(int,input().split()))))

basic=np.arange(1,N+1)
ans=0
for i in range(N):
    # print(A[i:])
    # print(basic[:N-i]-A[i]-1)
    ans+=(A[i:]==(basic[:N-i]-A[i]-1)).sum()
print(ans)