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:
# -*- coding: utf-8 -*-

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

m=max(A)
for i in range(N):

    for j in range(N-i-A[i]):
        k=i+j+A[i]

        if A[i]+A[k]==k-i:
            count = count+1
            #print("{} {}".format(i+1,k+1))
        if A[i]+m+i<k:
            break


print("{}".format(count))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

for i in range(N):
    m=max(A[i:])
    for j in range(N-i-A[i]):
        k=i+j+A[i]

        if A[i]+A[k]==k-i:
            count = count+1
            #print("{} {}".format(i+1,k+1))
        if A[i]+m+i<k:
            break


print("{}".format(count))

Submission status: Time Limit Exceeded

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

result=0

for j in range(N-1):
    for k in range(j+2,N):
        if k-j==A[k]+A[j]:
            result +=1

print(result)

Submission status: Time Limit Exceeded

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

result=0

for j in range(N-1):
    for k in range(j+1,N):
        if k-j==A[k]+A[j]:
            result +=1

print(result)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

for i in range(N):
    for j in range(N-i-A[i]):
        k=i+j+A[i]
        if A[i]+A[k]==abs(i-k):
            count = count+1
            #print("{} {}".format(i+1,k+1))



print("{}".format(count))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

for i in range(N):
    for j in range(N-i):
        k=i+j
        if A[i]+A[k]==abs(i-k):
            count = count+1
            #print("{} {}".format(i+1,k+1))



print("{}".format(count))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
i_list = [a + i + 1 for i, a in enumerate(A)]

ans = 0
for j in range(N):
    ans += i_list[:j+1].count(j+1-A[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
l=0
for i in range(N):
    if A[i]<2*100000:
        for k in range(i+1 , N):
            if A[i]+A[k]==k-i or A[i]+A[k]==i-k:
                l+=1
print(l)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
count=0
for i1,r1 in enumerate(A):
    for i2,r2 in enumerate(A[i1+1:]):
        if i2+1==r1+r2:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    n = 0
    L = list(itertools.combinations(range(N),2))
    for i in range(int(N*(N-1)/2)):
        if abs(L[i][0] - L[i][1]) == A[L[i][0]] + A[L[i][1]]:
            n += 1
    print(n)
main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
l_min = min(l)
counter = 0
for p in range(n):
  if l[p] < n - l_min:
    for q in range(p):
      if p - q  == l[p] + l[q]:
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
l = [int(x) for x in input().split()]
counter = 0
for p in range(x):
  if l[p] < x:
    for q in range(p):
      if p - q  == l[p] + l[q]:
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

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

A_n = [a + b + 1 for a, b in enumerate(A)]

ret = 0
for n in range(len(A)):
    #print(A_n[:n], n + 1 - A[n])
    ret += A_n[:n].count(n + 1 - A[n])
print(ret)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
l = [int(x) for x in input().split()]
counter = 0
for p in range(x):
  for q in range(p):
    if p - q  == l[p] + l[q]:
      counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = input().split()
H = []
for i in range(N):
  H.append(int(l[i]))
r = 0
for i in range(N):
  for j in range(i, N):
    if i > j and i - j == H[i] + H[j]:
      r += 1
    elif j > i and j - i == H[i] + H[j]:
      r += 1
print(r)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))

r = []
l = []

for i,j in enumerate(a):
    r.append(i+j)
    l.append(i-j)
    
ans = 0
for i in l:
    ans += r.count(i)
    
print(ans)

Submission status: Time Limit Exceeded

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

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

com = combinations(range(1, N+1), 2)

ct = 0
for i in com:
    if abs(i[0] - i[1]) == A[i[0]-1] + A[i[1]-1]:
        ct += 1
print(ct)

Submission status: Time Limit Exceeded

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

from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

com = combinations(range(1, N+1), 2)

ct = 0
for i in com:
    if abs(i[0] - i[1]) == A[i[0]-1] + A[i[1]-1]:
        ct += 1
print(ct)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
p = [0] * n
m = [0] * n
e = [0]*n
for i in range(n):
    p[i] = i + a[i]
    m[i] = i - a[i]

p = sorted(p)+[p[n - 1] + 1]
m = sorted(m)
pp = p[0]
pi = 1
mp = 0
mi = 0
total = 0
# print(p)
# print(m)
for i in range(1, n+1):
    # print("#", i, pp, pi, " t:", total)
    if (p[i] == p[i - 1]):
        pi += 1
        continue
    for j in range(mp, n):
        #print("-- ", j, mp, mi, "[", p[i-1], m[j], "]", " t:", total)
        if (p[i - 1] > m[j]):
            continue
        elif (p[i - 1] == m[j]):
            total += pi
            continue
        else:
            mp = j
            break
    pp = p[i]
    pi = 1
    mi = 0
print(total)

Submission status: Time Limit Exceeded

Solution code:
def get_answer():
  N = int(input())
  
  list_n = range(1, N+1, 1)
  list_A = list(map(int, input().split(" ")))
  
  max_A = max(list_A)
  
  num_pair = 0
  for i in range(N, 1, -1):
    min_j = i - max_A*2 - 1
    if min_j <= 1:
      min_j = 1
    for j in range(i-1, min_j-1, -1):
      sum_A = list_A[i-1] + list_A[j-1]
      if sum_A == abs(i - j):
        num_pair += 1
        
  print(num_pair)
 
 
if __name__ == "__main__":
  get_answer()

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
  N = int(input())
  
  list_n = range(1, N+1, 1)
  list_A = list(map(int, input().split(" ")))
  
  num_pair = 0
  for i in range(N, 1, -1):
    for j in range(i-1, 0, -1):
      sum_A = list_A[i-1] + list_A[j-1]
      if sum_A == abs(i - j):
        num_pair += 1
        
  print(num_pair)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools


def input_int_list_with_length(length=None):
    if length == None:
        length = int(input())
    return list(map(int, input().split()))[:length]


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


def main():
    A = input_int_list_with_length()
    solve(len(A), A)


if __name__ == '__main__':
    main()

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+1,n):
        if A[i]+A[j]==i-j or A[i]+A[j]==j-i:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

B = {}
for i, a in enumerate(A):
    aa1 = i + 1 - a
    if aa1 > 0:
        if aa1 not in B:
            B[aa1] = []
        B[aa1].append((i + 1, a))

count = 0
for i, a in enumerate(A):
    aa1 = i + 1 + a
    if aa1 in B:
        for b in B[aa1]:
            if b[0] > i + 1:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

b = [j - i for i, j in enumerate(a, start=1)]
c = [-j - i for i, j in enumerate(a, start=1)]
result = sum([c.count(i) for i in b])
print(result)

Submission status: Time Limit Exceeded

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

left = []
right = []

for i in range(n):
    left.append(a[i]+i)
    right.append(i-a[i])
    
ans = 0

for i in range(n):
    for j in range(i+1, n):
        #print(i,j)
        if left[i]==right[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

diffMax = 2 * max(heights)
diffMin = 2 * min(heights)

cnt = 0

for i in range(diffMin, max([diffMax, n]) + 1):
    for j in range(n - i):
        if (heights[j] + heights[j + i]) == i:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

person = int(input())
longs = list(map(int, input().split(" ")))
longs2 = [j - longs[j] for j in range(len(longs))]

sum = 0
for i in range(person):
    sum += longs2.count(longs[i] + i)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

L = [0]*N
R = [0]*N

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

l = collections.Counter(L)
r = collections.Counter(R)

#print(l,r)
#print(l.items(),l.keys())

count = 0
for i in l.keys():
    for j in r.keys():
        #print(i,j)
        if i == j:
            count += l[i] * r[j]

print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

person = int(input())
longs = list(map(int, input().split(" ")))

sum = 0
for i in range(person):
    if i + longs[i] < person:
        for j in range(i + longs[i], person):
            if (j - i) == longs[i] + longs[j]:
                sum += 1
print(sum)

Submission status: Time Limit Exceeded

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


L = [0]*N
R = [0]*N

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

count = 0
for i in range(N):
    for j in range(i,N):
        if L[i] == R[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

person = int(input())
longs = list(map(int, input().split(" ")))

sum = 0
for i in range(person):
    for j in range(i, person):
        if (j - i) == longs[i] + longs[j]:
            sum += 1
print(sum)

Submission status: Time Limit Exceeded

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

diffMax = 2 * max(heights)
diffMin = 2 * min(heights)

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

N = int(input())
Hs = [int(h) for h in input().split()]

cnt = 0
r = 0
combinations_ = itertools.combinations(range(N), 2)
for COMB in combinations_:
  r+=1
  if Hs[COMB[0]] + Hs[COMB[1]] == np.abs( COMB[0] - COMB[1] ):
    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):
    if i + a[i] + 1 < n:
        for j in range(i + a[i] + 1, 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()))
Ans = []
for i in range(1, N):
  #B = [A[j] + A[j + i] for j in range(N-i)]
  b = [i for j in range(N-i) if A[j] + A[j+i] == i]
  Ans.extend(b)
ans = len(Ans)
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    for j in range(i, n):
        if i == j:
            continue
        if abs(i - j) == A[i] + A[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(v) for v in input().split()]
count = 0
for i in range(len(A)-1):
  for j in range(i+1,len(A)):
    a1,a2 = A[i],A[j]
    diff = j-i
    if diff == a1+a2:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

n = int(input())

a = input().split()

count = 0

r = [(n - int(m)) for n,m in enumerate(a)]
l = [(n + int(m)) for n,m in enumerate(a)]

r.remove(r[0])
l.remove(l[-1])

mar = max(r)
mir = min(r)
mal = max(l)
mil = min(l)

R = {i:0 for i in range(mir,mar + 1)}
L = {i:0 for i in range(mil,mal + 1)}

for n,m in zip(r,l):
    R[n] += 1
    L[m] += 1

for i in range(max(mir,mil),min(mar,mal)+1):
    count += R[i] * L[i]

print("{}".format(count))

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    # from collections import deque
    N = int(input())
    A = list(map(int, input().split()))

    count = 0
    for now in range(N):
        for v in range(now+1, N):
            if A[now]+A[v] == v-now:
                count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

J=[0]
j=0
while j<N:
    if j-A[j]>0:
        J.append(j-A[j])
    j+=1

ans=0
i=0
while i<N:
    ans+=J.count(i+A[i])
    i+=1

print(ans)

Submission status: Time Limit Exceeded

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

J=[0]*N
j=0
while j<N:
    J[j]=j-A[j]
    j+=1

ans=0
i=0
while i<N:
    ans+=J.count(i+A[i])
    i+=1

print(ans)

Submission status: Time Limit Exceeded

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

ans=0
i=0
while i<N:
    j=i+1+A[i]
    while j<N:
        if j-i==A[j]+A[i]:
            ans+=1
        j+=1
    i+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#E
import numpy as np
N = int(input())
A = list(map(int, input().split()))
x = 0
listi = []
listj = []
for i in range(N):
    listi.append(i + A[i])  
for j in range(N):
    listj.append(j - A[j])
for i in range(N):
    for j in range(N):
        if i < j and listi[i] == listj[j]:
            x += 1
print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#D
import numpy as np
N = int(input())
A = list(map(int, input().split()))
x = 0
for i in range(N):
    for j in range(N):
        if i < j:
            if np.abs(i-j) == A[i] + A[j]:
                x += 1
print(x)

Submission status: Time Limit Exceeded

Solution code:
import collections


n = int(raw_input())
hs = map(int, raw_input().split(' '))
def f(hs):
	#print sorted([(e,i) for i,e in enumerate(hs)])
	count =0
	for i in range(len(hs)):
		for j in range(i+1, len(hs)):
			if hs[i] + hs[j] == j-i:
				count+=1
	return count
print f(hs)

Submission status: Time Limit Exceeded

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

n = int(input())
seq = [int(x) for x in input().split()]
visited = [False for _ in xrange(n)]
ans = 0
p = set()
for i, val in enumerate(seq):
    if val > n:
        continue

    for j in xrange(min(n,i+val-2), n):
        if abs(j-i) == val + seq[j]:
            if not visited[i]:
                visited[i] = True
            if not visited[j]:
                visited[j] = True
            if (i,j) not in p:
                ans += 1
                p.add((i,j))
    for j in xrange(0, max(i-val, 0)):
        if abs(i - j) == val + seq[j]:
            if not visited[i]:
                visited[i] = True
            if not visited[j]:
                visited[j] = True
            if (j,i) not in p:
                ans += 1
                p.add((j,i))
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

la =[]
lb =[]
for i in range(n):
    la.append(i+A[i])
    lb.append(i-A[i])

for j in range(1,n,1):
    ans += la[0:j-1].count(lb[j])

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(len(A)):
    for ind in range(i+1,len(A),1):
        if ind-i == A[ind]+A[i]:
            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):
    start = i+A[i]
    if start > N-1:
        continue
    for j in range(start,N):
        if j == start + A[j]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def diff(a,b):
    if a>b:
        return(a-b)
    else:
        return(b-a)
n=int(input())
l=list(map(int,input().split()))
new=[]
count=0
for i in range(0,len(l)):
    new.append((l[i],i+1))
new.sort()
for i in range(0,len(new)):
    for j in range(i+1,len(new)):
        if new[i][0]+new[j][0]>2*10**5:
            break
        if new[i][0]+new[j][0]==diff(new[i][1],new[j][1]):
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N=int(input())
    L=list(map(int,input().split()))
    L_i,L_j=[],[]
    d, s = [0]*N, 0
    cnt=0
    
    for i, j in enumerate(L):
        if i+j<N:
            L_i.append(i+j)
        if i-j>0:
            L_j.append(i-j)

    for i in L_j:
        cnt += L_i.count(i)
        
    print(cnt)
main()

Submission status: Time Limit Exceeded

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

# i < j
# j - i = a[i] + a[j]
# a[i] + i = j - a[j]

count = 0
candidate = []
for i in range(n):
    sa = i - a[i]
    count += candidate.count(sa)
    wa = i + a[i]
    candidate.append(wa)

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N=int(input())
    L=list(map(int,input().split()))
    L_i,L_j=[],[]
    d, s = [0]*N, 0
    cnt=0
    
    for i, j in enumerate(L):
        L_i.append(i+j)
        L_j.append(i-j)

    for i in L_j:
        cnt += L_i.count(i)
        
    print(cnt)
main()

Submission status: Time Limit Exceeded

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

# i < j
# j - i = a[i] + a[j]
# a[i] + i = j - a[j]

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

print(count)

Submission status: Time Limit Exceeded

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

l = {}
r = {}
for i in range(1,n+1):
    if i-a[i-1] in l:
        l[i-a[i-1]]+=1
    else:
        l[i-a[i-1]]=1

    
    
    if i+a[i-1] in r:
        r[i+a[i-1]]+=1
    else:
        r[i+a[i-1]]=1
    

for i,v in l.items():
    for j,w in r.items():
        if i==j:
            ans+=v*w


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

n=int(input())
A=list(map(int, input().split()))
L=['null']*n
R=['null']*n
c=0

for i,a in enumerate(A):
  L[i]=i+a
  R[i]=i-a
  c+=L.count(R[i])
print(c)

Submission status: Time Limit Exceeded

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

counter = 0
for a_1 in range(len(A)):
    for a_2 in range(a_1 + 1,len(A)):
        sum_1 = a_2 - a_1
        sum_2 = A[a_1] + A[a_2]
        if sum_1 == sum_2:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
A1 = []
A2 = []
 
for i in range(N):
    A1.append(i + A[i])
    A2.append(i - A[i])
 
count = 0
for i in A1:
    count += A2.count(i)
        
print(count)

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(1,n-i):
        sum = a[i]+a[i+j]
        dif = j
        if sum==j:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

A1 = []
A2 = []

for i in range(N):
    A1.append(i + A[i])
    A2.append(i - A[i])

count = 0
for i in A1:
    for j in A2:
        if i ==j:
            count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for i, j in itertools.combinations(N, 2):
    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 pair(N,A):
  B=0
  for i in range(N):
    for j in range(i+1,N):
      if A[i]+A[j]==j-i:
        B+=1
  return B
print(pair(N,A))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

check_all = np.empty(0)
for i in range(N):
    check = A[i+1:]+A[i] - np.array(range(N-1-i))-1
    check_all = np.concatenate([check_all, check])
    #cnt += np.sum(check == 0)
#print(check_all)
print(np.sum(check_all == 0))

Submission status: Time Limit Exceeded

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

main()

Submission status: Time Limit Exceeded

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

main()

Submission status: Time Limit Exceeded

Solution code:

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

for i in range(0,n-1,2):
    if (i+1 <= n-1) and (a[i]+a[i+1] == 1):
        cnt += 1
    for o in range(i+1,n,2):
        if a[i]+a[o] == o-i:
            cnt += 1
        if (o+1 <= n-1) and (a[i]+a[o+1] == o-i+1):
            cnt += 1
        if a[i+1]+a[o] == o-i-1:
            cnt += 1
        if (o+1 <= n-1) and (a[i+1]+a[o+1] == o-i):
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

def make_diag_indexes(size = 5):
    target = np.asarray([j-i for i in range(size) for j in range(size)])
    target = target.reshape(size,size)
    return target

mdi = make_diag_indexes(size = N)
check = np.add.outer(A,A) - np.triu(mdi)

print(np.sum(check == 0))

Submission status: Time Limit Exceeded

Solution code:

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

for i in range(0,n-1,1):
    for o in range(i+1,n,2):
        if a[i]+a[o] == o-i:
            cnt += 1
        if (o+1 <= n-1) and (a[i]+a[o+1] == o+1-i):
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:

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

for i in range(0,n-1):
    for o in range(1,n,2):
        if a[i]+a[o] == o-i:
            count += 1
        if (o+1 <= n-1) and (a[i]+a[o+1] == o+1-i):
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:

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

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

print(count)

Submission status: Time Limit Exceeded

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

AI = sorted([(a, i) for i, a in enumerate(A)])

dic = list()
tmp = 0
for i, (a, pos) in enumerate(AI):
    if a > 2 * 10**5:
        break
    if tmp != a:
        tmp = a
        dic.append((a, i))

nums = [a for (a, i) in dic]
inds = [i for (a, i) in dic]
inds.append(N)
L = len(dic)


def check(p1, p2):
    # print(p1, p2)
    sumsum = nums[p1] + nums[p2]
    ret = 0
    for i in range(inds[p1], inds[p1+1]):
        for j in range(inds[p2], inds[p2+1]):
            if sumsum == abs(AI[i][1] - AI[j][1]):
                ret += 1
    # print("return ", ret)
    return ret // 2 if p1 == p2 else ret


# print(dic)
# print(nums)
# print(inds)

ans = 0
for i in range(L):
    for j in range(i, L):
        if nums[i] + nums[j] > 2 * 10**5:
            continue
        ans += check(i, j)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input().strip())
a = list(map(int, input().split()))
left = {}
for i in range(len(a)):
    if left.get(a[i] + i):
        left[a[i] + i].append(i)
    else:
        left[a[i] + i] = [i]
ans = 0
for i in range(len(a)):
    if left.get(i - a[i]):
        ans += len(list(filter(lambda x: x < i, left[i - a[i]])))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

def main():
    input1 = input()
    N = int(input1)
    input2 = input().split()
    A = [0]*N
    A = input2

    result = 0
    for i in range(N):
        for j in range(N-i-1):
            if int(A[i])+int(A[j+i+1]) == j+1:
                result += 1

    print(result)


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):
    for j in range(i + 1, N):
        if j - i == A[i] + A[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

count = 0

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

Submission status: Time Limit Exceeded

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

from collections import defaultdict

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

    L = defaultdict(lambda: 0)
    R = defaultdict(lambda: 0)
    for i in range(1, N + 1):
        L[i] = i + A[i - 1]
        R[i] = i - A[i - 1]

    ans = 0
    for l in L.values():
        for r in R.values():
            if l == r:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

ListK = [i+1+List[i] for i in range(N)]
ListL = [i+1-List[i] for i in range(N)]

from collections import Counter 
ans = 0
for i in range(N):
  ans += (Counter(ListK)[i])*(Counter(ListL)[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
l_i = [a[i] + i + 1 for i in range(len(a))]
l_j = [i - a[i] + 1 for i in range(len(a))]

ans = 0
for i in range(n):
    for j in range(i+1, n):
        if l_i[i] == l_j[j]:
            ans += 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(0,n-1):
    f=True
    #if a[i]!=0:
    for j in range(i+1,n):
            #if a[j]!=0:
            if j-i==a[j]+a[i]:
                s+=1
                f=False
            if f==True:continue
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n]]

i_dic = {}
for i,a in enumerate(a_ls):
	val = -a+(i+1)
	if val not in i_dic: i_dic[val] = []
	i_dic[val].append(i+1)

cnt = 0
for i in range(len(a_ls)):
	val = a_ls[i] + (i+1)
	cand_ls = i_dic.get(val, [])
	ok_ls = [j for j in cand_ls if j>(i+1)]
	cnt += len(ok_ls)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

count = sum([j-i == A[i-1]+A[j-1] for i, j in itertools.combinations_with_replacement(range(1, N+1), 2)])

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
import copy

n = int(input())
#n, k = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
num = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
#s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

#a = [[0 for _ in range(n+1)] for _ in range(n+1)]
#b = [[0 for _ in range(n+1)] for _ in range(n+1)]

kotae = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        if(abs(i-j) == num[i]+num[j]):
            kotae += 1

print(kotae)