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())
a = list(map(int,input().split()))
d1 = []
d2 = []
for i, ele in enumerate(a,1):
    d1.append(i + ele)
    d2.append(i - ele)

cnt = 0

for i in range(n):
    cnt += d2[i+1:].count(d1[i])

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
d = []
for i, ele in enumerate(a,1):
    d.append( [(i+ele),(i-ele)] )

cnt = 0

for i in range(n):
    for j in range(i+1,n):
        if d[i][0] == d[j][1]:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=input().split()
A=[int(number) for number in a]
answer=0
for n in range(N):
    target=A[n]
    plus = n+target
    if plus <=N-1:
        for o in range(plus,N):
            if target + A[o] == o - n:
                answer+=1
print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N-2):
    j = i + 1
    while j <= N-1:
        if A[j] + A[i] == j - i:
            ans += 1
        else:
        	pass
        j += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = input()
a = list(map(int, input().split()))
ans = 0
a_sort = sorted(a, reverse=True)
add_max = a_sort[0] + a_sort[1]
for i in range(len(a)-1):
    for j in range(len(a)-i-1):
        t1 = a[i]
        t2 = a[i+j+1]
        t = t1 + t2
        num_del = j + 1
        if t == num_del:
            ans = ans + 1
            if j == add_max:
                break
print(ans)

Submission status: Time Limit Exceeded

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

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):
    total += int(abs(j-i) == a[i]+a[j])
print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0
L = []
R = []
# j - i = Ai + Aj --> i + Ai = j - Aj
for i in range(n):
    L.append(i + A[i])
    R.append(i - A[i])
    cnt += L.count(R[i])
#print(L, R)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
A = [0] + list(map(int,input().split()))

cnt = 0
combination = combinations(range(1, n+1), 2)
for comb in combination:
    x, y = comb[0], comb[1]
    if abs(x - y) == A[x] + A[y]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

num_of_member = int(input())
heights = np.array(list(map(int, input().split())), dtype=np.int64)

height_sums = np.array([], dtype=np.int64)
for i, height in enumerate(heights):
    height_sums = np.hstack((height_sums, heights[i] + heights[i+1:]))

diffs = np.array([], dtype=np.int64)
for i in range(num_of_member, 1, -1):
    diffs = np.hstack((diffs, np.arange(1, i)))

checks = height_sums - diffs

print(np.count_nonzero(checks == 0))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
hList = list(map(int, input().split()))
count = 0
nList = [ i + hList[i] for i in range(len(hList))]

for i in range(N):
  tmpVal = i - hList[i]
  count += nList.count(tmpVal)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

A=list(map(int,input().split()))

NA=[]

for i in range(N):
    NA.append(A[i]-i)

cnt=0
for i in range(N-1):
    cnt+=NA.count(-i-A[i])

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

x = []
y = []

for i, elem in enumerate(a):
    x.append(i+a[i])
    y.append(i-a[i])

ans = 0

for i in x:
    ans += y.count(i)

print(ans)

Submission status: Time Limit Exceeded

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

x = []
y = []

for i, elem in enumerate(a):
    x.append(i+a[i])
    y.append(i-a[i])

ans = 0

for j in range(n):
    for i in range(j):
        if x[i] == y[j]:
            ans += 1;

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from random import randint

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

last = {}
ans = 0;

for _ in range(10**7):
    x = randint(0, n-1)
    y = randint(0, n-1)
    if abs(x-y) == a[x]+a[y] and last.get((x, y), "Hola") == "Hola":
        ans += 1;
        last[(x, y)] = 1;
        last[(y, x)] = 1;

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from random import randint

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

last = {}
ans = 0;

for _ in range(10**8):
    x = randint(0, n-1)
    y = randint(0, n-1)
    if abs(x-y) == a[x]+a[y] and last.get((x, y), "Hola") == "Hola":
        ans += 1;
        last[(x, y)] = 1;
        last[(y, x)] = 1;

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from random import randint

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

last = {}
ans = 0;

for _ in range(10**9):
    x = randint(0, n-1)
    y = randint(0, n-1)
    if abs(x-y) == a[x]+a[y] and last.get((x, y), "Hola") == "Hola":
        ans += 1;
        last[(x, y)] = 1;
        last[(y, x)] = 1;

print(ans)

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,N):
        if abs(i-j)==A[i]+A[j]:
            S+=1

print(S)

Submission status: Time Limit Exceeded

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

ai = []
ans = 0

for i in range(n):
    ai.append(i + l[i])

for j in range(n):
    ans = ans + ai.count(j - l[j])

print(ans)

Submission status: Time Limit Exceeded

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

ai = []
aj = []
ans = 0

for i in range(n):
    ai.append(i + l[i])

for j in range(n):
    aj.append(j - l[j])

ai.sort()
aj.sort()

s = min(ai)
e = max(aj)

# print(ai)
# print(aj)
# print(s)
# print(e)

for x in range(n):
    ans = ans + aj.count(ai[x])
    if x >= e+1:
        break
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A = list(map(int,input().split()))
#t = {}
#for i,a in enumerate(A):
#  if a not in t: t[a]=0
#  t[a]+=1
ans = 0
for k in range(1,n):
  for i in range(k,n):
    if A[i] + A[i-k] == k:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())

A = list(map(int,input().split()))
L = []
R = []
for i in range(N):
  L.append(A[i]+i+1)
  R.append(i+1 - A[i])
L.sort()
R.sort()
i =0
j = 0
cnt = 0
while i<N and j <N:
  if L[i] == R[j]:
    k = j
    while k< N and R[k] == R[j]:
      k += 1
    cnt += k-j
    i += 1
    #j = min(k-1,N-1)
  else:
    if i == N-1:
      j += 1
    elif j == N-1:
      i += 1
    elif L[i] < R[j]:
      i += 1
    else:
      j += 1
print(cnt)

Submission status: Time Limit Exceeded

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

ai = []
aj = []
ans = 0
aiajmin = -9999999


for i in range(n):
    ai.append(i+l[i])

for j in range(n):
    aj.append(j-l[j])

#print(ai)
#print(aj)
    
aiajmin = min(max(ai),max(aj))
aiajmax = max(min(ai),min(aj))
ai.sort()
aj.sort()

for x in range(n):
    if(ai[x] <= aiajmin and ai[x] >= aiajmax):
        ans = ans + aj.count(ai[x])
    else:
        break
    
print(ans)

Submission status: Time Limit Exceeded

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

ai = []
aj = []
ans = 0
aiajmin = -9999999


for i in range(n):
    ai.append(i+l[i])

for j in range(n):
    aj.append(j-l[j])

#print(ai)
#print(aj)
    
aiajmin = min(max(ai),max(aj))
ai.sort()
aj.sort()

for x in range(n):
    if(ai[x] <= aiajmin):
        ans = ans + aj.count(ai[x])
    else:
        break
    
print(ans)

Submission status: Time Limit Exceeded

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

ai = []
aj = []
ans = 0

for i in range(n):
    ai.append(i+l[i])

for j in range(n):
    aj.append(j-l[j])

#print(ai)
#print(aj)

for x in range(n):
    ans = ans + aj.count(ai[x])
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
hList = list(map(int, input().split()))
count = 0

for i in range(N):
  for j in range(i+1,N):
    if (j-i) == (hList[i]+hList[j]):
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
hList = list(map(int, input().split()))
count = 0

for i in range(N):
  for j in range(i,N):
    if (j-i) == (hList[i]+hList[j]):
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    dd = defaultdict(list)
    count = 0
    for i in range(N - 1):
        ai = A[i]
        iai = i + ai
        if dd[iai] == []:
            for j in range(i + 1, N):
                if j - A[j] == iai:
                    dd[iai].append(j)
                    count += 1
        else:
            for j in dd[iai]:
                if j > i:
                    count += 1
    print(count)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    dd = defaultdict(list)
    count = 0
    for i in range(N - 1):
        ai = A[i]
        iai = i + ai
        if dd[iai] == []:
            for j in range(i + 1, N):
                if j - A[j] == iai:
                    dd[iai].append(j)
                    count += 1
        else:
            for j in dd[iai]:
                if j > i:
                    count += 1
    print(count)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dd = defaultdict(list)
count = 0
for i in range(N - 1):
    ai = A[i]
    iai = i + ai
    if dd[iai] == []:
        for j in range(i + 1, N):
            if j - A[j] == iai:
                dd[iai].append(j)
                count += 1
    else:
        for j in dd[iai]:
            if j > i:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dd = defaultdict(list)
count = 0
for i in range(N - 1):
    if dd[i + A[i]] == []:
        for j in range(i + 1, N):
            if j - A[j] == i + A[i]:
                dd[i + A[i]].append(j)
                count += 1
    else:
        for j in dd[i + A[i]]:
            if j > i:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(n):
    a = a_input[i]
    for idx,j in enumerate(range(i+1,n),1):
        if idx-a==a_input[j]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())


k=0
a={}
for i in map(int,input().split()):
    if i<n-1:
        a[k]=i
    k=k+1

cnt = 0

for i,h in a.items():
    for j,hh in a.items():
        if j-i==h+hh: 
            cnt=cnt+1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

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

cnt = 0

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

Submission status: Time Limit Exceeded

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

s = []
t = []
for i in range(N):
  s.append(i + A[i])
  t.append(i - A[i])

a = 0
for i in s:
  b = t.count(i)
  a = a + b
    
print(a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
cnt = 0

B = [i + a for i, a in enumerate(A)]

C = [j - a for j, a in enumerate(A)]

for i, b in enumerate(B):
    for j, c in enumerate(C):
        if i >= j:
            continue
        elif b == c:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

if __name__ == '__main__':
    n = input()
    n = int(n)
    A = input()
    A = A.split()
    A = list(map(int,A))

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

    num_list = list(itertools.combinations(num,2))

    count = 0
    for i in range(len(num_list)):
        sub_ab = abs(num_list[i][0]-num_list[i][1])
        sum_ab = A[num_list[i][0]] + A[num_list[i][1]]
        if sub_ab == sum_ab:
            count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
tmp_A = list(map(int, input().split()))
A = [0] + tmp_A

tmp_A = sorted(tmp_A)
min_h = sum(tmp_A[0:2])
max_h = sum(tmp_A[-2:])

ans = 0
for n in range(1, N + 1):
    now_h = A[n]
    min_i = max(n + 1, min(min_h, N))
    max_i = min(max_h + n + 1, N + 1)
    for i in range(min_i, max_i):
        if A[n] + A[i] is abs(n - i):
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
cnt = 0

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

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(n):
        if i >= j:
            continue
        if abs((i+1) - (j+1)) == (a[i] + a[j]):
            cnt += 1
print(cnt)

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(n):
        if i == j:
            continue
        if abs((i+1) - (j+1)) == (a[i] + a[j]):
            cnt += 1
print(cnt//2)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
for i in range(N):
    if i>A[i]:
        d[i]=A[i]

count=0
for i in range(N):
    for j in [j for j in d if j > i]:
        if j-i==A[i]+A[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
for i in range(N):
    if i>A[i]:
        d[i]=A[i]

count=0
for i in range(N):
    for j,aj in d.items():
        if j-i==A[i]+aj:
            count += 1
print(count)

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 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()))

def check(i,j):
    a = abs(i-j)
    h = A[i] + A[j]
    if a == h:
        return True
    else:
        return False

res = 0
for i in range(N):
    for j in range(i+1,N):
       if check(i,j):
           res += 1 

print(res)

Submission status: Time Limit Exceeded

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

setA = set(A)

def check(i,j):
    a = abs(i-j)
    h = A[i] + A[j]
    if a == h:
        return True
    else:
        return False

res = 0
for i in range(N):
    for j in range(i+1,N):
       if check(i,j):
           res += 1 

print(res)

Submission status: Time Limit Exceeded

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

x=list()
result=0
for i in range(n):
    result+=x.count(i-a[i])
    x.append(i+a[i])
    
print(result)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
result=[]
res=[]
for i in range(N):
    tmp=i+A[i]
    tmp2=i-A[i]
    result.append(tmp)
    res.append(tmp2)

count=0

for i in result:
    for j in res:
        if i==j:
            count+=1
        else:
            pass

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input()) + 1
A = [0] + [int(i) for i in input().split()]

MAX_I = 10 ** 9
cnt = 0

for i in range(1, N):
    if MAX_I >= i + A[i]:
        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:
count = 0
n = int(input())
l = list(map(int,input().split()))

#for i,j in enumerate(l):

for i in range(n):
    v = i + l[i]
    j = i + 1
    while(j < n):
        if(v == j-l[j]):
            count = count + 1
            #print(v,j-l[j])
        j = j + 1

print(count)

Submission status: Time Limit Exceeded

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

counter = 0
window = max(As)*2
for i in range(N):
    base = As[i] + i
    for j in range(i+1, min(i+window+1, N)):
        cret = j - base
        if As[j] == cret:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

counter = 0
window = max(As)*2
for i in range(N):
    for j in range(i+1, min(i+window+1, N)):
        diff = j - i
        sum = As[i] + As[j] 
        if diff == sum:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product

N=int(input())
a=list(map(int,input().split()))
b=[i for i in range(N)]
count=0

C=[i[0]+i[1] for i in combinations(a,2)]
D=[abs(i[0]-i[1]) for i in combinations(b,2)]

for i in range(len(C)):
    if C[i]==D[i]:
        count+=1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip() 
a = list(map(int, l.split()))
count = 0
for i in range(N):
    for j in range(i+1, N):
        if j - i == a[j] + a[i]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
diff = [(i+1)-A[i] for i in range(N)]
plus = [A[i]+(i+1) for i in range(N)]
ans = 0
for i in range(N-1):
    pnum = plus[i]
    ans += diff[i+1:].count(pnum)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product

N=int(input())
a=list(map(int,input().split()))
b=[i for i in range(N)]
A=list(combinations(a,2))
B=list(combinations(b,2))

C=[]
D=[]

for i in A:
    tmp=i[0]+i[1]
    C.append(tmp)

for i in B:
    tmp=abs(i[0]-i[1])
    D.append(tmp)

count=0

for i in range(len(C)):
    if C[i]==D[i]:
        count+=1
    else:
        pass
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3

def main():
    entries = int( input() )
    heights = list( map( int, input().split() ) )
    pairs = 0

    for i in range(entries):
        for j in range(i + 1, entries):
            if heights[i] + heights[j] == j - i:
                pairs += 1
    
    print(pairs)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
count = 0
Jlist = []
for j in range(2, n+1):
    if j > a_list[j-1]:
        Jlist.append(j)

for j in Jlist:
    
    for i in range(1, j):
        if j -i == a_list[i-1] + a_list[j-1]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
A = list(map(int, input().split()))
ans = 0

for i in range(N-1):
  wa = i + A[i]
  for j in range(i+1,N):
    sa = j - A[j]
    if wa == sa:
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

max = max(l) * 2

ans = 0

for i in range(n):
    j = i + 1
    if l[i] < n:
        while(j < n and j <= i+max):
    
            if abs(j- i) == l[i]+l[j]:
                ans = ans + 1
                #print(abs(j-i),l[i]+l[j],i,j)
            j = j + 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

match = [i for i in range(N) for j in range(i+1,N) if abs(i-j) == agents[i]+agents[j]]

print(len(match))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
agents = list(map(int, input().split()))
match = 0

for i in range(N):
    for j in range(i+1,N):
        if abs(i-j) == agents[i]+agents[j]:
            match += 1

print(match)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
C = [0]*N
for i in range(N):
  B[i] = i+1+A[i]
for i in range(N):
  C[i] = i+1-A[i]
ans = 0
for i in range(N):
  del C[0]
  ans += C.count(B[i])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

F = []
G = []
for i in range(1, N + 1):
    F.append(i + A[i - 1])
    G.append(i - A[i - 1])
F.sort()
G.sort()
J = 0
for i in range(N):
    j = J + 1
    for j in range(N):
        if F[i] == G[j]:
            ans += 1
            J = j
        if G[j] > F[j]:
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(a) for a in input().split()]#n個のリスト

cnt=0

L=[j-A[j] for j in range(N)]
R=[A[i]+i for i in range(N)]

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

Submission status: Time Limit Exceeded

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

F = []
G = []
for i in range(1, N + 1):
    F.append(i + A[i - 1])
    G.append(i - A[i - 1])
F.sort()
G.sort()
for i in range(N):
    j = 0
    for j in range(N):
        if F[i] == G[j]:
            ans += 1
        if G[j] > F[j]:
            break

print(ans)

Submission status: Time Limit Exceeded

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

F = []
G = []
for i in range(1, N + 1):
    F.append(i + A[i - 1])
    G.append(i - A[i - 1])

for i in range(N):
    for j in range(N):
        if F[i] == G[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
sys.setrecursionlimit(10**7)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
b = a.copy()
for i in range(n):
    a[i] += i+1
    b[i] -= i+1
ans = 0
for i in range(n):
    ans += b[i+1:].count(-a[i])
print(ans)