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()))
b=[0]*n
for i , j in enumerate(a):
    b[i]=j+i+1
c=[0]*n
q=[]
ans=0
for i , j in enumerate(a):
    c[i]=1+i-j
from collections import Counter
def combination(n, r):
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
    return a // b
cc=Counter(c)
bb=Counter(b)
for i,j in bb.items():
    for k,l in cc.items():
        if i==k:
            ans+=j*l

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
diff_i = [A[i] + i + 1 for i in range(N)]
diff_j = [i + 1 - A[i] for i in range(N)]
diff = set(diff_i) & set(diff_j)
ans = 0
for d in diff:
    ans += diff_i.count(d) * diff_j.count(d)
print(ans)

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

print(p)

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8

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

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

Submission status: Time Limit Exceeded

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

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	# a_ext = {}
	b_sum_ext = {}
	b_ext = []
	# ai + aj = (j+1) - (i+1)
	# ai + i + 1 = -aj + j + 1

	for i, ai in enumerate(a):
		# a_ext[a[i] + i + 1] = 1
		log.print(a[i]+i+1, -a[i]+i+1)
		b_sum_ext[-a[i]+i+1] = b_sum_ext.get(-a[i]+i+1, 0)+1
	# log.print(b_sum_ext)
	for i in range(n):
		b_sum_ext[-a[i]+i+1] = b_sum_ext.get(-a[i]+i+1, 0)-1
		b_ext.append(dict(b_sum_ext))
	# log.print(b_ext)
	cnt = 0
	log.print(cnt)
	cnt = 0
	for i, ai in enumerate(a):
		if b_ext[i].get(a[i] + i + 1, 0) != 0:
			log.print(i+1, a[i] + i + 1)
			cnt += b_ext[i].get(a[i] + i + 1, 0)
	print(cnt)

	


main()

Submission status: Time Limit Exceeded

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

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:
sum=int(input())
people_list=list(map(int,input().split()))
count=0
for i in range(len(people_list)):
    for j in range(i+1,len(people_list)):
        if(people_list[i]+people_list[j]==abs(j-i)):
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

del_n = [abs(x - y) for x, y in itertools.combinations(range(1, n+1), 2)]
sum_a = [x + y for x, y in itertools.combinations(a, 2)]
# print(del_n)
# print(sum_a)
cnt = 0

for d, s in zip(del_n, sum_a):
    if d == s:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l = list(range(1, n + 1))
# print(l)
# print(al)

count = 0
for v in itertools.combinations(l, 2):
    
    v0_no = v[0]
    v1_no = v[1]
    v0_a = al[v[0] - 1]
    v1_a = al[v[1] - 1]
    
    if abs(v0_no - v1_no) == (v0_a + v1_a):
        # print(v)
        # print(abs(v0_no - v1_no))
        # print(v0_a + v1_a)
        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(i, N):
    if abs(i-j) == A[i]+A[j]:
      cnt+=1
      
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
P = np.zeros((N), dtype='i')

INF = 10**18

ans = 0
for i in range(N):
    v = A[i]
    A[i] = INF
    P[i:] = np.arange(0, N - i)
    P[:i] = np.arange(1, i + 1)[::-1]
    # print('P', P)
    ans += np.count_nonzero(A + v == P)
    # if i >= 3:
    #     break
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):
    if A[i] <= 2*10**5-i:
        a = A[i]
        ato = i+a
        if i+a > n:
            ato = n
        for j in range(ato,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()]
ans = 0
for i in range(n):
    if a[i] < n:
        for j in range(i+2,n):
            if abs((i+1) - (j+1)) == (a[i] + a[j]):
                ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
an = list(map(int, input().split()))
diff = itertools.combinations(list(range(1, n+1)), 2)
li = itertools.combinations(an, 2)
ans = 0
for d, l in zip(diff, li):
    if abs(d[0]-d[1]) == l[0]+l[1]:
        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):
    numbers = [abs(j-i) for j in range(n)]
    heights = [a[i]+ j for j in a]
    for j in range(i, n):
        if numbers[j] == heights[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
*A, = map(int, input().split())
count = 0
for i, a in enumerate(A):
    for j, b in enumerate(A[i + 1:]):
        if abs(i + 1 - (j + 1 + (i + 1))) == a + b:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    lst = list(map(int, input().split()))
    interval = 2
    cnt = 0
    while interval != N:
        for i in range(N-interval):
            a = lst[i]
            b = lst[i+interval]
            if a+b == interval:
                cnt += 1
        interval += 1
    print(cnt)
main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0
for l in itertools.combinations(range(n), 2):
    diff = abs(l[0] - l[1])
    total = lst[l[0]] + lst[l[1]]
    if diff == total:
        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(i, n):
    if abs(i-j) == a[i] + a[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def readInt():
    return list(map(int,input().split()))
d = deque([])
n = int(input())
# 身長
a = readInt()
ans = 0
for i in range(n):
    # print(a[i]+1,n-1-i,'/')
    if a[i]+1 <= n-1-i:
        for j in range(i+a[i]+1,n):
            # print(i,j)
            if a[i]+a[j] == j-i:
                # print(i,j)
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = [int(n) for n in input().split()]
# len(As) = N
# Ai = 身長
c = 0
for i, ai in enumerate(As):
    # i + ai = 最低これだけ先が無いとダメ
    j0 = i + ai
    if j0 >= N-1:
        continue
    j = 1
    l = N - j0 - 1
    while l > 0:
        if j == As[j0+j]:
            c += 1
        j+=1
        l-=1
print(c)

Submission status: Time Limit Exceeded

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


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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(a)

Submission status: Time Limit Exceeded

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

print(res)

Submission status: Time Limit Exceeded

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

def main():
    res = 0
    N = int(input())
    a = list(map(int, input().split()))
    for k in itertools.combinations([i for i in range(1, N+1)], 2):
        if abs(k[0] - k[1]) == a[k[0]-1] + a[k[1]-1]:
            res += 1

    print(res)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

ans = 0
for l in range(N-1):
    for r in range(l+2, N):
        if A[l] > N-l:
            break
        if r-l == A[l] + A[r]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

#import itertools
#print(list(itertools.combinations(A, 2)))
s = -1
ans = 0
for i in range(len(A)):
    s +=1
    
    for j in range(s,len(A)):
        #print(j)
        if abs(i-j) == A[i] + A[j]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    j_Aj = [j-Aj for j, Aj in enumerate(A, start=1)]
    ans = 0
    for i, a in enumerate(A[:-1], start=1):
        if a > N:
            continue
        api = a + i
        temp = Counter(j_Aj[i:])
        ans += temp[api]

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    A = kwargs["A"]
    res = 0
    m1 = min(A) * 2
    m2 = max(A) * 2
    R = [[0 for j in range(n + 1)] for i in range(n + 1)]

    for i in range(1, n + 1):
        R[0][i] = A[i - 1]

    for i in range(1, n + 1):
        for j in range(i + m1, min(i + m2 + 1, n + 1)):
            R[i][j] = R[0][i] + R[0][j]

            if j - i == R[i][j]:
                res += 1

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    kwargs["n"] = [int(i) for i in cin][0]
    #kwargs["n"], kwargs["k"] = [int(i) for i in cin]

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    kwargs["A"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
n = int(input())
a = []
s = input().split()

for i in range(n):
    a.append(int(s[i]))

res = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

A=[int(i) for i in input().split()]
i=0

ans=0
for i in range(N-1):
	ans+=len(list(filter(lambda x:x-A[x]==i+A[i],range(i+A[i],N))))
print(ans)

Submission status: Time Limit Exceeded

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

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

print(n)

Submission status: Time Limit Exceeded

Solution code:
#import itertools

N=int(input())
A_values=list(map(int,input().split()))
#A_keys=[i+1 for i in range(N)]
#A_dict=dict(zip(A_keys,A_values))
l=[i for i in range(N)]

temp=0

#for i,j in itertools.combinations(l, 2):

for i in range(N-2):
  temp_min=max(i+A_values[i],i+2)
  #temp_max=min(i-A_values[i],N)
  for j in range(temp_min,N):
    #print(i,j)
    if abs(i-j)==A_values[i]+A_values[j]:
      temp+=1
print(temp)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
Am = sorted(A, reverse = True)
m = Am[0] + Am[1]
ct = 0
for i in range(n):
    for j in range(i, n):
        if j - i > m:
            break
        elif j - i == A[i] + A[j]:
            ct += 1
print(ct)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N-1):
  if A[i] < (10**5)*2:
    for j in range(i+1, N):
      if (j > A[j]) and (A[i] < (10**5)*2):
        if j-i == A[i]+A[j]:
          ans += 1
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = []
a += list(map(int, input().strip().split()))

count = 0

for i in range(n):
  for j in range(i, n):
    if abs(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()))
NL = list(range(N))
X = [A[i]+i+1 for i in NL]
S = [A[i]*(-1) + i + 1 for i in NL]
Ans=0
for i in range(N):
    Ans += S[i:].count(X[i])
print(Ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
for ai,a in enumerate(A):
    if a >= 2*10**5:
        continue
    for aj in range(ai+a,N):
        if A[aj] + A[ai] == aj - ai:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

A1 = [0]*N
A2 = [0]*N

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

cnt = 0
for i in range(N):
    c = Counter(A2[i+1:])
    cnt += c[A1[i]]

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

name_list=np.arange(n)

count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

count=0

for i in range(2,n):
    #番号の差がiの場合
    #print('------ '+ str(i) +' ------')

    #容疑者の選定（身長i未満のみ）
    suspect=[]
    for j in range(n):
        if h[j]<i:
            suspect.append(j)

    n_suspect=len(suspect)
    #print(suspect)

    #数え上げ
    for s1 in range(n_suspect-1):
        for s2 in range(s1+1,n_suspect):
            if h[suspect[s1]]+h[suspect[s2]]==i and suspect[s2]-suspect[s1]==i:
                count +=1
                #print(s1, s2)

#print('------------')
print(count)

Submission status: Time Limit Exceeded

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

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	# a_ext = {}
	b_sum_ext = {}
	b_ext = []
	# ai + aj = (j+1) - (i+1)
	# ai + i + 1 = -aj + j + 1

	for i, ai in enumerate(a):
		# a_ext[a[i] + i + 1] = 1
		log.print(a[i]+i+1, -a[i]+i+1)
		b_sum_ext[-a[i]+i+1] = b_sum_ext.get(-a[i]+i+1, 0)+1
	# log.print(b_sum_ext)
	for i in range(n):
		b_sum_ext[-a[i]+i+1] = b_sum_ext.get(-a[i]+i+1, 0)-1
		b_ext.append(dict(b_sum_ext))
	# log.print(b_ext)
	cnt = 0
	for i in range(n):
		for j in range(i, n):
			if a[i] + a[j] == j - i:
				log.print(i+1, j+1, a[i], a[j], b_ext[i].get(-a[j]+j+1, 0))
				cnt += 1
	log.print(cnt)
	cnt = 0
	for i, ai in enumerate(a):
		if b_ext[i].get(a[i] + i + 1, 0) != 0:
			log.print(i+1, a[i] + i + 1)
			cnt += b_ext[i].get(a[i] + i + 1, 0)
	print(cnt)

	


main()

Submission status: Time Limit Exceeded

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


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


main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

from itertools import combinations

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

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

print(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n=ii()
    a=lmis()
    mm=max(a)
    cnt=0
    for i in range(len(a)-2):
        dis=a[i]+mm+1
        for j in range(i+2,min(i+dis,len(a))):
            if j-i==a[i]+a[j]:
                cnt+=1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
A=list(map(int,input().split()))
ans=0
for i,j in itertools.combinations(range(n),2):
    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 = np.array(list(map(int, input().split())))
B = A.copy()
P = np.zeros((N), dtype='i')

INF = 10**18

ans = 0
for i in range(N):
    B[i] = INF
    P[i:] = np.arange(0, N - i)
    P[:i] = np.arange(1, i + 1)[::-1]
    # print('P', P)
    ans += np.count_nonzero(B + A[i] == P)
    # if i >= 3:
    #     break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy

n = int(input())
a = [int(x) for x in input().split(' ')]

count = 0
for i in range(n-1):
    A = numpy.array(a[i+a[i]:])
    B = numpy.arange(n-(i+a[i]))
    
    if(len(A) > 0):
        count += (A-B).tolist().count(0)

print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
dp = [0]*N
for i in range(N-1):
    t = A[i]
    if t > 2 * 10**5:
        continue
    for j in range(i+t, N):
        if j-i == t+A[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
tmp = input().split()

count = 0

A = []
for i in tmp:
  A.append(int(i))
  
for i in range(N):
  for k in range(i+1,N):
    if A[i]+A[k] == abs(i-k):
      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(n):
    if abs(i-j) == a[i] + a[j]:
      ans += 1
print(int(ans/2))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from itertools import combinations
n = int(input())
arr = list(map(int , input().split()))
dic = defaultdict(int)
u = list(set(arr))
s = set()
for i in combinations(u + u, 2):
	s.add(i[0]+i[1])
#print(s)
ans = 0
for i in s:
	if 1 <= i <= n-1:
		for j in range(i+1,n+1):
			#print( j , j - i , i)
			if abs(arr[j-1] + arr[j-i-1]) == 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):
    for j in range(n):
        if a[i]+a[j]== abs(j-i) :
             ans += 1
print(int(ans/2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

from pprint import pprint
from collections import deque, defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float("inf")

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

min_diff = 1
max_diff = N - 1

count = 0
for diff in range(min_diff, max_diff + 1):
    pairs = []
    i = 1
    while True:
        j = i + diff
        if j <= N:
            pairs.append([i, j])
        else:
            break
        i += 1
    # pprint(pairs)
    for i, j in pairs:
        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()))
count = 0
for i in range(1, N):
  for j in range(i):
    if i - j == A[i] + A[j]:
      count += 1
      
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int, input().split()))
count=0
for i in range(N):
  for j in range(i+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 = 0

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

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

Submission status: Time Limit Exceeded

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

print(c)

Submission status: Time Limit Exceeded

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

cnt = 0

table = [None]*N

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
A_max = max(A)
A_min = min(A)
#print("min", A_min)
for i in range(N):
  i_upper = i + A_min * 2
  if i_upper <= N:
    for j in range(i_upper, N):
      #print("upper",i,j)
      if abs(i - j) == (A[i] + A[j]):
        cnt = cnt + 1
print(cnt)

Submission status: Time Limit Exceeded

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

def main():
    N = int(input())
    height_list = list(map(int,input().split()))
    # print(height_list)

    match_count = 0
    for a_i, a_height in enumerate(height_list) :
        for b_i in range(a_i,N) :
            b_height = height_list[b_i]
            height_sum = a_height + b_height
            no_diff = b_i - a_i
            if (height_sum == no_diff) :
                match_count += 1
    
    print(match_count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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