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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    tmpa = list(map(int, input().split()))
    a2 = [[0]*n for _ in range(n)]
    for i1 in range(n):
        for i2 in range(i1+1,n):
            if tmpa[i1] + tmpa[i2] == (i2 - i1):
                a2[i1][i2] = 1
    r = 0
    for row in a2:
        r += sum(row)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def countPairs(arr, n): 
	mp = dict() 
	for i in range(n): 
		mp[arr[i] - i] = mp.get(arr[i] - i, 0) + 1
	res = 0
	for x in mp: 
		cnt = mp[x] 
		res += ((cnt * (cnt - 1)) // 2) 

	return res 


def main():
    n = I()
    a = LI()
    c=0
    d= dict()
    for i in range(n):
        for j in range(i+1,n):
            if i!=j:
                x = abs(i-j)
                s = a[i]+a[j]
                if x==s:
                    ls = [i,j]
                    ls.sort()
                    if tuple(ls) not in d:
                        d[tuple(ls)]=1
                        c+=1
    print(c)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
h = np.array(list(map(int, input().split())))
ans = 0
loc = 0
for i in range(n-1):
    if h[i] > n - i - 1:
        continue
    diff = h[i]
    num = min(n, i + h[i] + 1)
    length = n - num
    t = np.count_nonzero((np.array(h[num:]) - np.arange(n - num) - 1))
    ans += length - t
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

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

checked = {}
cnt = 0

# checked_me = [False] * N

# 最大200k
for i in range(N):
    for j in range(i + 1, N):
        # if checked_me[j] == False:
        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})

    # checked_me[i] = True

# print(checked)
print(cnt)

Submission status: Time Limit Exceeded

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


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

s = 0
for k in set(wa):
    s += wa.count(k)*sa.count(k)

print(s)

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
alist=list(map(int,input().split()))
blist=copy.deepcopy(alist)

sum=0
for i,a in enumerate(alist):
    for j in range(i+a,n):
        if j-i ==a+blist[j]:
            sum+=1

print(sum)

Submission status: Time Limit Exceeded

Solution code:



def solve(N:int,A:list) -> int:
    total = 0
    ans = 0
    for n,a in enumerate(A):
        i = n
        for j in range(i-1,-1,-1):
            if(A[j] + a == i - j):
                total += 1
    return total
def main():
    N = int(input())
    A = list(map(int,input().split()))
    # solve()
    print(solve(N,A))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

map_li = [[0 for i in range(n)] for j in range(n)]
ans = 0
for i in range(1,n+1):
    for j in range(i,n+1):
        if abs(a_inputs[i-1]+a_inputs[j-1])==(abs(i-j)):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split(" ")
compte = 0
B=[0]*N
C=[0]*N
for i in range(N):
  A[i] = int(A[i])
  B[i] = [A[i]+i,i]
  C[i] = -A[i]+i
B.sort()
for j in range(N):
  k = 0
  while B[k][0]<=C[j]:
    if B[k][0]==C[j] and B[k][1]<C[j]:
      compte+=1
    k+=1
print(compte)

Submission status: Time Limit Exceeded

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

temp_list = sorted([(a, i) for i, a in enumerate(a_list)])

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if temp_list[i][0] + temp_list[j][0] >= n:
            break
        if temp_list[i][0] + temp_list[j][0] == abs(temp_list[i][1] - temp_list[j][1]):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
for i in range(N):
  count+=s.count(w[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = sorted(((v, i) for i, v in enumerate(map(int, input().split()))))

ans = 0
for i in range(n):
    for j in range(i, n):
        hi, ki = A[i]
        hj, kj = A[j]
        if abs(kj - ki) == hi + hj:
            ans += 1
        if hi >= n:
            break
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
  if A[i] < (10**5)*2:
    l_1.append(A[i]+i)
    l_2.append(i-A[i])
  
for num in l_1:
  ans += l_2.count(num)
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ns = list(itertools.combinations(range(1,n+1), 2))
combs = list(itertools.combinations(a, 2))

cnt = 0
for comb, n in zip(combs, ns):
    if abs(n[0]-n[1]) == (comb[0]+comb[1]):
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

import itertools

a = list(itertools.combinations(range(len(A)), 2))
for i in range(len(a)):
    if a[i][0] == a[i][1]:
        del a[i] 

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
key = set(A)
keymax = max(key)
keymin = min(key)
ans = 0
for i,a in enumerate(A):
    for j in range(i+a,n):
        if keymax+a < abs(i-j):
            continue
        if abs(j-i) == A[i]+A[j]:
            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 + a[i], n):
        if j - i == a[i] + a[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

N = int(input())
A = list(map(int, input().split(' ')))
sum_list = [0 for _ in range(N)]

for idx in range(len(A)):
    if idx == 0:
        continue
    sum_list[idx] = sum_list[idx-1] + (A[idx] - A[idx-1])

ans = 0
for shift in range(1, len(A)):
    for idx in range(N - shift):
        if abs(sum_list[idx] + sum_list[idx + shift] + (2 * A[0])) == shift:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
N = int(input())
A = list(map(int,input().split()))
 
comb = itertools.combinations(range(N), 2)
ans = 0
 
for c in comb:
  if A[c[0]]+A[c[1]] == abs(c[0]-c[1]):
    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()])
 
arr = []
count = 0
for i, a in enumerate(A):
    lis = A + a
    count += np.count_nonzero((lis - range(N) - np.array([-i] * N))==0)
    #count += N - np.count_nonzero((lis - range(N) - np.array([-i] * N)))
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = sorted(((v, i) for i, v in enumerate(map(int, input().split()))))

ans = 0
for i in range(n):
    for j in range(i, n):
        hi, ki = A[i]
        hj, kj = A[j]
        if abs(kj - ki) == hi + hj:
            ans += 1
        if hi >= n:
            break
print(ans)

Submission status: Time Limit Exceeded

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

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 A[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:
n = int(input())
a = list(map(int,input().split()))

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

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) if j+1-A[j]>0]
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:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
N = int(input())
#開業されたN個要素を受け付ける
#list = [input() for i in range(N)]
list = list(map(int, input().split()))
#print(list)

ans=0
i=0
while i < N:
    j=i+list[i]+min(list)
    while j < N:
        #print(i+1, j+1)
        if j-i == list[i] + list[j]:
            ans=ans+1
            #print("ans")
        j = j+1
    i = i+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

    print(result)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    lst = list(map(int, input().split()))
    A = [l + i for i, l in enumerate(lst)]
    B = [i - l for i, l in enumerate(lst)]
    setA = set(A)
    setB = set(B)
    seki = setA & setB
    ans = 0
    for s in seki:
        numa = 0
        numb = 0
        for a in A:
            if a == s:
                numa += 1
        for b in B:
            if b == s:
                numb += 1
        ans += numa*numb
    print(ans)
main()

Submission status: Time Limit Exceeded

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

import sys
import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
#        for line in sys.stdin:
#            lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    (n,) = [int(e) for e in lines[0].split(" ")]
    a = [int(e) for e in lines[1].split(" ")]

    return (n, a)

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


    return count

def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r)
    else:
        print("%s" % result)

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

que = []

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

count = 0

for i in range(n):
    for a in que:
        if a == A[i]:
            count += 1

    que.append(-A[i])
    que = list(map(lambda x: x + 1, que))

print(count)

Submission status: Time Limit Exceeded

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

ans=0
for x in range(N):
    for y in range(x+1, N):
        delta = y-x
        sum = A[x]+A[y]
        if delta == sum:
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from sys import setrecursionlimit
from itertools import accumulate

setrecursionlimit(10 ** 7)

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
point = 0

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

print(point)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
A=np.array(list(map(int,input().split())))
C=np.array([i+1 for i in range(n)])
cnt=0
for i in range(n-1):
    cnt+=(n-1-i)-np.count_nonzero((A[:n-i-1]+A[i+1:])-(C[i+1:]-C[:n-i-1]))
print(cnt)

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

sumN = sorted(sumN)

newA = sorted(da , key = lambda x:(x[1]))
ans = 0

for s in sumN :
    if s > 200000:
        break

    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:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))

n = II()
a = LI()

ans = 0
for i in range(1,n):
	tmp = 0
	for j in range(n-i):
		if a[j]+a[j+i]==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-1):
    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:
from collections import deque

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

def func(lst1,lst2):
    lst3=deque()
    for i in range(len(lst1)):
        lst3.append(lst1[i]-lst2[i])
    lst3 = list(lst3)
    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=deque()
    for j in list(range(0,i)):
        lst.append(i-j-A[i])
    B=deque(A[:i])
    ans += func(B,lst)

print(ans)

Submission status: Time Limit Exceeded

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

import itertools
high = list(map(lambda x: x[0]+x[1] ,list(itertools.combinations(a, 2))))
b = list(map(lambda x: abs(x[0]-x[1]) ,list(itertools.combinations(range(1,n+1), 2))))
diff=[high[x]-b[x] for x in range(len(high))]

import collections
c = collections.Counter(diff)

print(c[0])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())
A = deque(list(map(int, input().split())))
ans=0
while len(A)>1:
  al = A.popleft()
  for i,a in enumerate(A):
    if i+1 == al + a:
      ans +=1
        
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
cnt = int(input())
heights = [int(x) for x in input().split(' ')]

output = 0
for i in range(cnt - 2):
    h_1 = heights[i]
    for j in range(i + 2, cnt):
        if h_1 + heights[j] == j - i:
            output += 1

print(output)

Submission status: Time Limit Exceeded

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

c = [0]*n
d = [0]*n
for i, j in enumerate(a):
    c[i] = j-i

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = []
count = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
count = 0

for i in range(N):
  if (int(A[i]) // 200000) > 0:
    A[i] = 0

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

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

Submission status: Time Limit Exceeded

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

for i in range(N):
  l_1.append(A[i]+i)
  l_2.append(i-A[i])
  
for num in l_1:
  ans += l_2.count(num)
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

s = 10000
for i in range(-s, s):
    flag = False
    for j in range(-s, s):
        tmp = i ** 5 - j ** 5
        if tmp == x:
            print('{} {}'.format(i, j))
            flag = True
            break
    if flag:
        break

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A = list(map(int, input().split()))
# L = [(i, i + v, v - i) for i, v in enumerate(A)]
Ai = dict()
Aj = dict()
for i, v in enumerate(A):
    ans = 0
    ai = i + v
    aj = i - v
    if ai in Ai:
        Ai[ai].append(i)
    else:
        Ai[ai] = [i]
    if aj in Aj:
        Aj[aj].append(i)
    else:
        Aj[aj] = [i]
ans = 0
intersection_keys = Ai.keys() & Aj.keys()
for key in intersection_keys:
    L = itertools.product(Ai[key], Aj[key])
    ans += len([True for i, j in L if j > i])

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
NUMS = list(range(N))
A = list(map(int, input().split()))
cnt=0
for a in itertools.combinations_with_replacement(NUMS, 2):
    if A[a[0]] + A[a[1]] == abs(a[0]-a[1]):
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import array

if __name__ == "__main__":
    N = int(sys.stdin.readline().strip())
    A = array.array('i', [int(a) for a in sys.stdin.readline().strip().split(" ")])

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
goukei = 0

N = int(input()) * (-1)
Ai = list(map(int, input().split()))
array_Ai = np.array(Ai)
number = np.array([j for j in range(0, N, -1)])
number_1 = np.array([1 for k in range(-N)])
new_ai = number + array_Ai
new_ai = new_ai - number_1
for i in range(len(Ai)):
    new_ai = new_ai + number_1
    goukei += np.count_nonzero(new_ai == -Ai[i])
print(goukei)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
from itertools import combinations

def file_input():
    f = open('../Beginner_Contest_166/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    N=int(input())  #人数
    A=list(map(int, input().split()))   #身長

    ans=0
    # A_set=set(A)
    sum=set()
    for c in list(combinations(A,2)):
        sum.add(c[0]+c[1])
        # print(c)
        # print(str(c[0]-1)+str(c[1]-1)+" : "+str(A[c[0]-1])+str(A[c[1]-1]))
        # print(str(abs(A[c[0]-1]-A[c[1]-1]))+" : "+str(abs(c[0]-1-(c[1]-1))))
        # if abs(A[c[0]-1]+A[c[1]-1])==abs(c[0]-1-(c[1]-1)):
        #     ans+=1
    # print(sum)
    for s in sum:
        # print("sum : "+str(s))
        for i in range(N-s):
            if A[i]+A[i+s]==s:
                # print("h : "+str(i)+","+str(i+s))
                ans+=1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

print(count)

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] = A[i]-i-1
    C[i] = -A[i]-i-1

cnt = 0
for i in B:
    if i in C:
        cnt += C.count(i)
print(cnt)

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] < n-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())
an = map(int,input().split())
A = list(an)
y=0
for i in range(n-1):
    for j in range(i+1, n):
        if(A[i] + A[j] == j -i):
            y=y+1
print(y)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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


a_sum = []
for i in itertools.combinations_with_replacement(a_list, 2):
    a_sum.append(sum(list(i)))
a_sum = list(set(a_sum))
a_sum.sort


cnt = 0
for i in a_sum:
    for a in range(0,n-i):
        b = a + i
        if a_list[a] + a_list[b] == i:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as comb

n = int(input())
al = tuple(int(x) for x in input().split())
# A[n] + A[m] = abs(n - m)
p = comb(range(n), 2)
ans = 0
for x in p:
    a1, a2 = x
    if al[a1] + al[a2] == abs(a1 - a2):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

counts = 0

for i in range(N):
    for j in range(i):
        if talls[i]+talls[j] == abs(i-j):

            counts += 1

print(counts)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
  N = int(input())
  AA = list(map(int,input().split()))

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

solve()

Submission status: Time Limit Exceeded

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

spy_dict = {}
for i in range(0,N):
    spy_dict[i+1] = height_list[i]


counter = 0
for v in itertools.combinations_with_replacement(range(1,N+1),2):
    if spy_dict[v[0]] + spy_dict[v[1]] == abs(v[0] - v[1]):
        counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

count = 0
for i in range(len(A)):
    for j in map(lambda x: x+i, range(len(A)-i)):
        if abs(i - j) == A[i] + A[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
r = np.array(range(N))
#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+r-i)==0)
  ans += sum((X-r+i)==0)
  #ans += (sum((X-X[i]*(1))==0)-1)
  #ans += (sum((Y-Y[i]*(1))==0)-1)
print(ans//2)