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:
def intlist(x):
    y = []
    for i in range(len(x)):
        y.append(int(x[i]))
    return y

N = int(input())
height = intlist(input().split())

count = 0
for i in range(N):
    for k in range(N):
        if i == k:
            continue
        if height[i] + height[k] == abs((i+1)-(k+1)):
            count += 1
print(int(count/2))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as dd
n = int(input())
A = list(map(int, input().split()))

dic = dd(lambda: set())
for index, val in enumerate(A):
    if val < 2 * 10**5:
        dic[val].add(index)

counter = 0
for index, val in enumerate(A):
    for val_cand in dic.keys():
         if index + val + val_cand in dic[val_cand]:
             counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from collections import defaultdict

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main(A, N):
    d1 = defaultdict(int)
    d2 = defaultdict(int)

    for i, a in enumerate(A):
        d1[i+a] += 1
    
    for i, a in enumerate(A):
        d2[i-a] += 1

    mn_x = min(min(d1.keys()), min(d2.keys()))
    mx_x = max(max(d1.keys()), max(d2.keys()))

    cnt = 0
    for x in range(mn_x, mx_x+1):
        cnt += d1[x]* d2[x]

    print(cnt)
    pass

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from math import comb
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main(A, N):
    d1 = defaultdict(int)
    d2 = defaultdict(int)

    for i, a in enumerate(A):
        d1[i+a] += 1
    
    for i, a in enumerate(A):
        d2[i-a] += 1

    mn_x = min(min(d1.keys()), min(d2.keys()))
    mx_x = max(max(d1.keys()), max(d2.keys()))

    cnt = 0
    for x in range(mn_x, mx_x+1):
        cnt += d1[x]* d2[x]

    print(cnt)
    pass

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
def ans(lis):
  k = len(lis)
  if k <= 1:
    return 0
  else:
    t = 0
    l1 = lis[:(k//2)]
    l2 = lis[(k//2):]
    m1 = [i + l1[i] for i in range(len(l1))]
    m2 = [len(l1) + i - l2[i] for i in range(len(l2))]
    m1.sort()
    m2.sort()
    while(len(m1) and len(m2)):
      a,b = 0,0
      if m1[0] == m2[0]:
        c = m1[0]
        while(len(m1) and m1[0] == c):
          a += 1
          del(m1[0])
        while(len(m2) and m2[0] == c):
          b += 1
          del(m2[0])
        t += a*b
      else:
        if m1[0] > m2[0]:
          del(m2[0])
        else:
          del(m1[0])
    return ans(lis[:(k//2)])+ans(lis[(k//2):])+t
print(ans(li))

Submission status: Time Limit Exceeded

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

L = []
R = []
for i, A in enumerate(A_list):
    L.append(i+A)
    R.append(i-A)

ans = 0
for l in L:
    ans += R.count(l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import collections
# c = collections.Counter()
#import itertools as it
#import math
#import numpy as np
#import sys 
#sys.exit()
 
#  = input()
n  = int(input())
#a, b  = map(int, input().split())
 
a = list(map(int, input().split()))

'''
n = input()
a = [int(input()) for i in range(n)]
'''
'''
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
'''
#print(n,a,b)
#-------------------------------#
count=0
for i in range(0,n):
    for j in range(0,n):
        if j+1-a[j]==abs(a[i]+i+1):
            #print(abs(j+1-a[j]),j)
            #print(abs(a[i]+i+1),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):
    if A[i]>N-2: continue
    for j in range(i+A[i]+1,N):
        s=A[i]+A[j]
        if s==j-i:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a1=[]
a2=[]
for i in range(n):
  a1.append(i+1-a[i])
for i in range(n):
  a2.append(i+1+a[i])
count=0
p=0
q=1
while q<n:
  if a1[q]==a2[p]:
    count+=1
  p+=1
  if p==q:
    p=0
    q+=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-1):
    for k in range(A[i] + i, N):
        if i + A[i] == k - A[k] :
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
a=list(map(int,input().split()))
ind=list(itertools.combinations(range(1,n+1), 2))

cnt=0
for i in range(len(ind)):
    if ind[i][1]-ind[i][0]==a[ind[i][1]-1]+a[ind[i][0]-1]:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a1=[]
a2=[]
for i in range(n):
  a1.append(i+1-a[i])
for i in range(n):
  a2.append(i+1+a[i])
count=0
for k in range(n):
  for l in range(k-1):
    if a1[k]==a2[l]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a1=[]
a2=[]
for i in range(n):
  if i+1-a[i]>0:
    a1.append(i+1-a[i])
for i in range(n):
  a2.append(i+1+a[i])
count=0
for k in a1:
  for l in a2:
    if k==l:
      count+=1
print(count)

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

print(int(cnt/2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    for y in c.items():
        if x[0] == y[0]:
            count += x[1] * y[1]
print(count)

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):
    comp = [abs(j-i) == a[i] + a[j] for j in range(n)]
    for j in range(i, n):
        if comp[j] == True:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

dicplus = {}
dicmins = {}
for i in range(n):
	b = a[i] + i
	c = a[i] - i
	if b not in dicplus:
		dicplus[b] = 1
	else:
		dicplus[b] += 1
	if c not in dicmins:
		dicmins[c] = 1
	else:
		dicmins[c] += 1

ans = 0
for i in dicplus:
	for j in dicmins:
		if i + j == 0:
			ans += dicplus[i] * dicmins[j]
print (ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
dtype = [('number',int),('height',int)]
A = np.array(list(enumerate(list(map(int, input().split())))),dtype=dtype)
count = 0
B = np.sort(A,order='height')
mem = [i+1 for i in range(N-1)]
Min = B[0][1] + B[1][1]
Max = B[-1][1] + B[-2][1]
for i in range(max(2,Min),min(N,Max+1)):
    for j in range(N-1):
        c = B[j][1]
        d = i - c
        for k in range(mem[j],N):
            e = B[k][1]
            if e == d:
                if abs(B[j][0]-B[k][0]) == i:
                    count += 1
            elif e > d:
                mem[j] = k
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
values = list(map(int, input().split()))
keys = list(range(1, N + 1))
A = dict(zip(keys, values))

count = 0
for i in range(N):
    for j in range(i + 1, N):
        if abs(i - j) == values[i] + values[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
h = [x[1] for x in B]
mem = [i+1 for i in range(N-1)]
Min = h[0] + h[1]
Max = h[-1] + h[-2]
for i in range(max(2,Min),min(N,Max+1)):
    for j in range(N-1):
        c = h[j]
        if c >= i:
            break
        else:
            d = i - c
            for k in range(mem[j],N):
                if h[k] == d:
                    if abs(B[j][0]-B[k][0]) == i:
                        count += 1
                elif h[k] > d:
                    mem[j] = k
                    break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
h = [x[1] for x in B]
mem = [i+1 for i in range(N-1)]
Min = h[0] + h[1]
Max = h[-1] + h[-2]
for i in range(2,N):
    if Min > i:
        continue
    elif Max < i:
        break
    else:
        for j in range(N-1):
            c = h[j]
            if c >= i:
                break
            else:
                d = i - c
                for k in range(mem[j],N):
                    if h[k] == d:
                        if abs(B[j][0]-B[k][0]) == i:
                            count += 1
                    elif h[k] > d:
                        mem[j] = k
                        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
h = [x[1] for x in B]
mem = [i+1 for i in range(N-1)]
for i in range(2,N):
    if h[0] + h[1] > i:
        continue
    elif h[-1] + h[-2] < i:
        break
    else:
        for j in range(N-1):
            c = h[j]
            if c >= i:
                break
            else:
                d = i - c
                for k in range(mem[j],N):
                    if h[k] == d:
                        if abs(B[j][0]-B[k][0]) == i:
                            count += 1
                    elif h[k] > d:
                        mem[j] = k
                        break
print(count)

Submission status: Time Limit Exceeded

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

import sys

def main():
    N = int(input())
    A = list(map(int, input().split()))
    dic_Lg = {}
    dic_Lw = {}
    for i in range(N):
        x = i - A[i]
        if x in dic_Lg:
            dic_Lg[x]+=1
        else:
            dic_Lg[x]=1
        y = i + A[i]
        if y in dic_Lw:
            dic_Lw[y]+=1
        else:
            dic_Lw[y]=1
        LP = list(dic_Lw.keys()) + list(dic_Lg.keys())
        LP = set(LP)

    ret = 0
    for i in LP:
        if i in dic_Lg and i in dic_Lw:
            ret += dic_Lg[i] * dic_Lw[i]
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
b = list(enumerate(a))

cnt = 0
for i,j in itertools.combinations(b,2):
	if abs(i[0]-j[0]) == i[1] + j[1]:
		cnt += 1
print (cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def pop2(li):
	c=1
	i=li.pop(0)
	while 1:
		j=li.pop(0)
		if j==i:
			c+=1
		else:
			break
	return i,c,[j]+li

n = readInt()
a = readInts()

li = []
ri = []

for i in range(n):
	li.append(i+a[i])
	ri.append(i-a[i])

li.sort()
ri.sort()

res = 0

tar = list(set(li)&set(ri))

for i in tar:
	res+=li.count(i)*ri.count(i)

print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
P = []
H = defaultdict(list)
for i, v in enumerate(A):
    H[i+v].append(i)
    P.append((i, i-v))
ans = 0

for i, v in P:
    for j in H[v]:
        if i > j:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    l_dic = {}
    r_dic = {}
    i = 0
    for a in map(int, input().split()):
        ld = l_dic.setdefault(i + a, [])
        ld.append(i)
        rd = r_dic.setdefault(i-a, [])
        rd.append(i)
        i += 1

    count = 0
    for rk, rv_list in r_dic.items():
        if rk not in l_dic:
            continue
        lv_list = l_dic[rk]
        for rv in rv_list:
            # count += len([lv for lv in lv_list if lv < rv])
            for lv in lv_list:
                if lv < rv:
                    count += 1
                else:
                    break

    print(count)


main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    l_dic = {}
    r_dic = {}
    i = 0
    for a in map(int, input().split()):
        ld = l_dic.setdefault(i + a, [])
        ld.append(i)
        rd = r_dic.setdefault(i-a, [])
        rd.append(i)
        i += 1

    count = 0
    for rk, rv_list in r_dic.items():
        if rk not in l_dic:
            continue
        lv_list = l_dic[rk]
        for rv in rv_list:
            # count += len([lv for lv in lv_list if lv < rv])
            for lv in lv_list:
                if lv < rv:
                    count += 1

    print(count)


main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

Ap = [i+1 + A[i] for i in range(len(A))]
Am = [(i, i+1 - A[i]) for i in range(len(A))]
Am.sort(key=lambda x: x[1])

#print([Am[i][1] for i in range(len(Am))], Ap)
#print(Am, Ap)

ans = 0


def is_ok(idx, key):
    # 検索対象に関する条件を書く
    if Am[idx][1] < key:
        return True
    else:
        return False


def binary_search(ok, ng, key):
    # Trueすぎるidx, Falseすぎるidx
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid, key):
            ok = mid
        else:
            ng = mid
    return ok


for i in range(len(A)):
    # print(Ap[i])
    l = binary_search(-1, len(A), Ap[i])
    r = binary_search(-1, len(A), Ap[i]+1)
    #print("Api, l, r :", Ap[i], l, r)
    for j in range(l+1, r+1):
        if Am[j][0] > i:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res

n = readInt()
a = readInts()

li = []
ri = []

for i in range(n):
	li.append(i+a[i])
	ri.append(i-a[i])

li.sort()
ri.sort()

res = 0

while 1:
	if len(li)==0:
		break
	i = li.pop(0)
	c=1
	try:
		while 1:
			li.remove(i)
			c+=1
	except:
		pass
	finally:
		res+=ri.count(i)*c

print(res)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
setL=set(L)  
setR=set(R)
for i in range(N):
  if i in setL and i in setR:
    ans+=L.count(i)*R.count(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
listA=list(map(int,input().split()))
ans=0
L=[]
R=[]
for i in range(N):
  L+=[i+listA[i]]
  R+=[i-listA[i]]
setL=set(L)  
setR=set(R)
for i in R:
  if i in setL:
    ans+=L.count(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
listA=list(map(int,input().split()))
ans=0
index=[]
for i in range(N):
  index+=[[listA[i],i]]
index.sort()
for i in range(N):
  if index[i][0]<N:
    for k in range(i+1,N):
      if index[k][0]<N:
        if abs(index[k][1]-index[i][1])==index[k][0]+index[i][0]:
          ans+=1
      else:
        break
  else:
    break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L, R = [0] * n, [0] * n
i = 0
for ipt in input().split():
    L[i] = i + int(ipt)
    R[i] = i - int(ipt)
    i += 1
def make_dic(L):
    L_set = set(L)
    return dict([(i, L.count(i)) for i in L_set])
L_dic, R_dic = make_dic(L), make_dic(R)
cnt = 0
for Lk, Lv in L_dic.items():
    try:
        cnt += R_dic[Lk] * Lv
    except KeyError:
        pass
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
L, R = [0] * n, [0] * n
for i in range(n):
    L[i] = i + a[i] 
    R[i] = i - a[i] 
def make_dic(L):
    L_set = set(L)
    return dict([(i, L.count(i)) for i in L_set])
L_dic, R_dic = make_dic(L), make_dic(R)
cnt = 0
for Lk, Lv in L_dic.items():
    try:
        cnt += R_dic[Lk] * Lv
    except KeyError:
        pass
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N = int(readline().rstrip())
A = list(map(int, readline().split()))

import itertools
pairs = list(itertools.combinations(range(0, N), 2))

ans = 0
for pair in pairs:
    x1, x2 = pair
    if abs(x1 - x2) == A[x1] + A[x2]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
L = [i + a[i] for i in range(n)]
R = [i - a[i] for i in range(n)]
def make_dic(L):
    L_set = set(L)
    return dict([(i, L.count(i)) for i in L_set])
L_dic, R_dic = make_dic(L), make_dic(R)
cnt = 0
for Lk, Lv in L_dic.items():
    try:
        cnt += R_dic[Lk] * Lv
    except KeyError:
        pass
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L_i=[i+1 for i in range(len(L))]

cnt=0
for i in range(N):
    X= sum([(L[i:][x]+L[i])==x for x in range(N-i)])
    cnt = cnt + X
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L_i=[i+1 for i in range(len(L))]

cnt=0
for i in range(N):
    X= sum([m+L[i]==x for (m,x) in zip(L[i:],range(N-i))])
    cnt = cnt + X
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L_i=[i+1 for i in range(len(L))]

cnt=0
for i in range(N):
    P_L= [m+L[i] for m in L[i:]]
    P_L_i = [x for x in range(N-i)]
    cnt = cnt + sum([P_L[w]==P_L_i[w] for w in range(N-i)])
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L_i=[i+1 for i in range(len(L))]

cnt=0
for i in range(N):
    P_L= [m+L[i] for m in L[i:]]
    P_L_i = [x for x in range(N-i)]
    cnt = cnt + sum([w==z for (w, z) in zip(P_L,P_L_i)])
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L_i=[i+1 for i in range(len(L))]

cnt=0
for i in range(N):
    P_L= [m+L[i] for m in L[i:]]
    P_L_i = [x - y for (x, y) in zip(L_i[i:],[L_i[i]] * len(L_i[i:]))]
    cnt = cnt + sum([w==z for (w, z) in zip(P_L,P_L_i)])
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L_i=[i+1 for i in range(len(L))]

cnt=0
for i in range(N):
    P_L= [m+L[i] for m in L[i:]]
    P_L_i = [x - y for (x, y) in zip(L_i[i:],[L_i[i]] * len(L_i[i:]))]
    X = sum([int(w==z) for (w, z) in zip(P_L,P_L_i)])
    cnt = cnt + X
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
hs = list(map(int, input().split()))
jh = [j - hs[j] for j in range(n)]
hi = [i + hs[i] for i in range(n)]

dic = {}
arr = []
for i in range(0, len(jh)):
    if jh[i] in arr:
        dic[jh[i]].append(i)
    else:
        dic[jh[i]] = [i]
        arr.append(jh[i])

count = 0
for i in range(0, len(hi)):
    if hi[i] in arr:
        count += len(dic[hi[i]])
    else:
        pass
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
A_i = {}
A_j = {}
for i, a in enumerate(A):
    A_i[i] = a + i
    A_j[i] = i - a

r = 0
for i in range(n):
    for j in range(i + 1, n):
        if A_i[i] == A_j[j]:
            r += 1

print(r)

Submission status: Time Limit Exceeded

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

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

x = [i + li[i] for i in index]
y = [i - li[i] for i in index]

r = 0
for i in x:
    r += y.count(i)
print(r)

Submission status: Time Limit Exceeded

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

for i in range(0, n-1):
    for j in range(i+1, n):
        if heights[i] + heights[j] == j - i:
            count += 1
        else:
            pass
print(count)

Submission status: Time Limit Exceeded

Solution code:
# 常にi < jを考える

N = int(input())
H = [0]
H.extend(list(map(int, input().split())))

plus = [H[i] + i for i in range(1,N+1)]
minus = [i - H[i] for i in range(1, N+1)]

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if plus[i] == minus[j]:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# 常にi < jを考える

N = int(input())
H = [0]
H.extend(list(map(int, input().split())))

plus = [H[i] + i for i in range(1,N+1)]
minus = [i - H[i] for i in range(1, N+1)]

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if plus[i] == minus[j]:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
li =  list(map(int, input().split()))

index_ = [i for i in range(n)]
r = 0
for v in itertools.combinations_with_replacement(index_, 2):
    if v[0] == v[1]:
        continue
    
    if abs(v[0] - v[1]) == li[v[0]] +  li[v[1]]:
        r += 1
        
print(r)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
wa = defaultdict(list)
sa = {}
ans = 0

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

for k, v in sa.items():
    for i in wa.get(v, [k]):
        if i < k:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
wa = defaultdict(list)
sa = {}
ans = 0

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

for k, v in sa.items():
    for i in wa.get(v, [k]):
        if i < k:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
l = input().split(' ')

count = 0


for i in list(range(len(l)-1)):
    for j in list(range(i,len(l))):
        if abs(i-j)==int(l[i])+int(l[j]):
            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-1):
  for j in range(i+1,N):
    if j-i==A[i]+A[j]:
      sum=sum+1
print(sum)

Submission status: Time Limit Exceeded

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


N = int(input())

a = list(map(int, input().split()))
A = np.array([a for i in range(N)])
B = np.array([[a[i]] * N for i in range(N)])
C = A + B
d = [i for i in range(N)]
D = np.array([d for i in range(N)])
E = np.array([[i] * N for i in range(N)])

#print(D)
#print(E)
ind = D - E
#print(ind)
ans = C - ind
#print(ans)
cnt = np.count_nonzero(ans == 0)
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-1):
    for j in range(i, n):
        if i != j and abs(i-j) == a[i] + a[j]:
            count += 1
print(count)
"""
# idxとa[idx]で別々にループ回すからO(n**2)になってしまう
# 前処理としてidxとa[idx]の二つの情報をまとめた何かがつくれれば、、ってとこまでは気付けた

a_plus = [0]*n
a_minus = [0]*n
for i in range(n):
    a_plus[i] = i + a[i]
    a_minus[i] = i - a[i]
ans = 0
already_count = []
for i in a_plus:
    if i in already_count:
        continue
    else:
        ans += a_plus.count(i)*a_minus.count(i)
        already_count.append(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
l = input().split(' ')

count = 0

tcount = 0

while tcount<len(l)-1:
    scount = tcount+1
    while scount<len(l):
        if abs(scount-tcount)==int(l[scount])+int(l[tcount]):
            count += 1
        scount += 1
    tcount += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
num_participants = int(input(' '))

heights = [int(h) for h in input().split(' ')]

num_valid_pairs = 0

diff_in_idx = num_participants - 1
min_sum_of_height = 2 * min(heights)

"""
j - i = Ai + Aj
i + Ai = j - Aj
if i + Ai = X ,then j - Aj = X
"""

while (diff_in_idx >= min_sum_of_height):
  for i in range(num_participants - diff_in_idx):
    j = i + diff_in_idx
    if (i + heights[i]) == (j - heights[j]): 
      num_valid_pairs += 1
  diff_in_idx -= 1
      
print(num_valid_pairs)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
l = input().split(' ')
for i in list(range(len(l))):
    l[i] = int(l[i])
count = 0

tcount = 0

while tcount<len(l):
    scount = tcount+1
    while scount<len(l):
        if abs(scount-tcount)==l[scount]+l[tcount]:
            count += 1
        scount += 1
    tcount += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x>0 and x in dt:
    y=dr[x]
    z=dt[x]
    for w in y:
      for ww in z:
        if w>ww:
          ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
l = input().split(' ')
for i in list(range(len(l))):
    l[i] = int(l[i])
count = 0

tcount = 0

while tcount<len(l):
    scount = 0
    while scount<len(l):
        if scount!=tcount and abs(scount-tcount)==l[scount]+l[tcount]:
            count += 1
        scount += 1
    tcount += 1
print(int(count/2))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int, input().split()))
D={}
E={}
for i in range(N):
  a=i+A[i]
  b=i-A[i]
  D.setdefault(a,0)
  E.setdefault(b,0)
  D[a]+=1
  E[b]+=1
ans=0
for i in D.keys():
  for j in E.keys():
    if i==j:
      ans+=D[i]*E[i]
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i ,Ai in enumerate(A,1):
  for j ,Aj in enumerate(A[i:],i+1):
    if i+Ai==j-Aj:
      #print(i,j)
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
r=[0]*(n-1)
t=[0]*(n)
dr={}
dt={l[0]:[0]}
for i in range(1,n):
  x=i-l[i]
  y=i+l[i]
  if x in dr:
    dr[x].append(i)
  else:
    dr[x]=[i]
  if y in dt:
    dt[y].append(i)
  else:
    dt[y]=[i]
ans=0
for x in dr.keys():
  if x in dt:
    y=dr[x]
    z=dt[x]
    for w in y:
      for ww in z:
        if w>ww:
          ans+=1
print(ans)