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

def func(lst1,lst2):
    lst3=[]
    for i in range(len(lst1)):
        lst3.append(lst1[i]-lst2[i])

    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=[]
    for j in list(range(0,i)):
        lst.append(i-j-A[i])

    ans += func(A[:i],lst)

print(ans)

Submission status: Time Limit Exceeded

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

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
# E - This Message Will Self-Destruct in 5s

N = int(input())
A = list(int(x) for x in input().split())

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

c = 0

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

print (c)

Submission status: Time Limit Exceeded

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

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)
for i in range(len(Ai)):
    number = np.array([j + i for j in range(0, N, -1)])
    new_ai = number + array_Ai
    goukei += np.count_nonzero(new_ai == -Ai[i])
print(goukei)

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+1+a[i],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:
N = int(input())
A = [int(a) for a in input().split()]
cnt = 0
for i in range(N):
    for j in range(i):
        if 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()))
b=[i+a[i]+1 for i in range(n)]
count=0
for i in range(n-1,0,-1):
    for j in range(n-2,-1,-1):
        if i+1-a[i]==b[j]:
            count+=1
print(count)

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):
  if A_values[i]<2*10**5:
    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 j-i==A_values[i]+A_values[j]:
        temp+=1
print(temp)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n):
    if A[i] <= 2*10**5-i:
        a = A[i]
        ato = i+a
        saigo = n
        if i+m < n:
            saigo = i+m
        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())
H=input().split()
H=list(map(int,H))
count=0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
mA = max(A)
max_long = min(N,max(A)*2)
count = 0
for i in range(N-1):
  m = min(N,i+max_long+1)
  for j in range(i+1,m):
    if j-i == A[i]+A[j]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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


# 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():
    # Failed to predict input format
    N = int(input())
    A = input().split(" ")
    A = [int(A[i]) for i in range(N)]

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split(" ")))
A_set = set(As)
count = 0
for i, v in enumerate(As, 1):
    for x in A_set:
        # 考えられる身長パターンを順番につくる
        height = v + x
        # height - i のindexが
        idx = height + i
        if idx > N:
            continue
        if As[idx - 1] == x:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
N = int(input())
M = list(map(int, input().split()))
result = 0
for i in range(N):
  x = M[i]
  #print(i, x)
  result += len([1 for m,n in enumerate(range(i+x+1, N)) if m+1 == M[n]])
print(result)

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

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+1,n+1):
        if j-i == 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()))
b1 = []
b2 = []
answer = 0

for i in range(n):
  b1.append(i + 1 + a[i])
  b2.append(i + 1 - a[i])
  
for i in range(n - 1):
  answer += b2[i + 1: n].count(b1[i])
  
print(answer)

Submission status: Time Limit Exceeded

Solution code:
def mws5(lookup, hs):
    ans = 0
    for i in range(len(hs)):
        h = hs[i]
        for k in lookup.keys():
            if lookup[k][k+i+h]:
                ans += 1
    print(ans)

if __name__ == "__main__":
    import sys
    from collections import defaultdict as DD
    lookup = DD(lambda:DD(bool))
    n = int(input())
    hs = [int(_) for _ in input().split()]
    for i, h in enumerate(hs):
        lookup[h][i] = True
    mws5(lookup, hs)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
	N = int(input())
	ls = [int(a) for a in input().split()]
	c = 0
	for i in range(N):
		h = ls[i]
		r = i+h+1
		if r < N:
			for j in range(r,N):
				H = ls[j]
				if h+H == abs(j-i):
					c += 1	

	print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
data = [int(i) for i in input().split()]
count = 0
 
for i in range(N):
    for j in range(i + 1, N):
            h_order = i + 1
            o_order = j + 1
            x = abs(h_order - o_order)
            y = data[i] + data[j]
            if (x == y):
                count += 1
            else:
                continue
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):
    ans+=len([n for n in range(N) if abs(i-n)==A[i]+A[n]])
print(ans//2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect_right, bisect_left

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    T = [i + 1 - A[i] for i in range(N)]
    idx = sorted(range(N), key=lambda k: T[k])
    T.sort()

    ans = 0
    for i in range(N):
        target = A[i] + i + 1
        left = bisect_left(T, target)
        if left > N - 1:
            continue
        if T[left] != target:
            continue
        else:
            right = bisect_right(T, target)
            for k in range(left, min(right, N)):
                j = idx[k]
                if i < j:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()

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

cnt = 0
for i in range(len(high)):
    if high[i] == b[i]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

for k in range(N):
  if A[k] < (10**5)*2:
    l.append([k, A[k]])
    
for i in range(len(l)):
  for j in range(i+1, len(l)):
    if l[j][0]-l[i][0] == l[j][1]+l[i][1]:
      ans += 1
      
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

INF = 10**18

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
hgts = input().split()
susp = 0
hgtdic = {}
for i in range(n):
  hgtdic[i] = int(hgts[i])
for i in range(n-1):
  for j in range(i+1,n):
    if j-i==hgtdic[i]+hgtdic[j]:
      susp += 1
print(susp)

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]
    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:
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:
import itertools

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

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

Submission status: Time Limit Exceeded

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

import itertools

def main():
     n = int(input())
     height = list(map(int, input().split()))

     ans = 0

     for i in range(n):
          i_height = height[i]
          for j in range(i+1, n):
               sub = j - i
               height_sum = i_height + height[j]
               if sub == height_sum:
                    ans += 1
     
     print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt

_ = int(input())
count = 0
l = list(map(int,input().split()))
for i in range(len(l)):
    for j in range(i+1,len(l)):
        if(j-i == l[i]+l[j]):
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
Hs = list(map(int, input().split()))
As = np.array([Hs for _ in range(N)])
h = np.array([[Hs[i]]*N for i in range(N)])
co = As + h - np.array([[abs(n-i) for i in range(N)] for n in range(N)])
ans = np.sum(co==0)
print(ans//2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
agents = [int(m) for m in input().split(" ")]
l = [1 for i in range(1,n+1) for j in range(i+1,n+1) if j - i == agents[i-1] + agents[j-1]]
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  h_list = list(map(int, input().split()))
  len_list = len(h_list)
  res = 0
  for i, h in enumerate(h_list):
    len_j = len_list-i-h
    if len_j <= 0:
      continue
    else:
      for j in range(len_j):
        use_index = j + i + h
        use_h = h_list[use_index]
        if (h + use_h) == (use_index - i):
          res += 1
  print(res)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = [(int(index),int(i)) for index,i in enumerate(input().split(" "))]

def combinations(iterable, r):
    pool = tuple(iterable)
    n = len(pool)
    if r > n:
        return
    indices = list(range(r))
    a = tuple(pool[i] for i in indices)
    p1 = a[0]
    p2 = a[1]
    if abs(p1[0]-p2[0]) == (p1[1]+p2[1]):
        yield a
        
    while True:
        for i in reversed(range(r)):
            if indices[i] != i + n - r:
                break
        else:
            return
        indices[i] += 1
        for j in range(i+1, r):
            indices[j] = indices[j-1] + 1
        a = tuple(pool[i] for i in indices)
        p1 = a[0]
        p2 = a[1]
        if abs(p1[0]-p2[0]) == (p1[1]+p2[1]):
            yield a
            
count=0
c = combinations(As, 2)
for i in c:
    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-1):
    for j in range(i+A[i]+1, N):
        if j-i == A[i] + A[j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def main():
	n=int(input())
	A=list(map(int,input().split()))
	res=0

	for i in range(n):
		for j in range(i+A[i]+1,n):
			if abs(i-j)==A[i]+A[j]:
				res+=1
	print(res)
	
if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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


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

print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

# -- submit ----

import itertools
import numpy as np

# --- fetch input ---
n = 0
is_first = True
candidate_info = {}

while True:
    try:
        if is_first:
            n = int(input())
            is_first = False
        else:
            candidate_info = {n+1: int(height) for n, height in enumerate(input().split())}
    except EOFError:
        break

# --- write code below ---

pair_list = itertools.combinations(range(1, n + 1), 2)

counter = 0

for a, b in pair_list:
    if np.abs(a - b) == candidate_info[a] + candidate_info[b]:
        counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(N):
  a = A[i]+(i+1)
  B.append(a)
i = N-1
t = 0
while i >=0 :
  a = i+1 - A[i]
  b = i+1 +A[i]
  if  a <=0:
    i =i- 1
  else:
    if a == b:
      t += B.count(a)-1
    else:
      t += B.count(a)
    i =i-1
print(t)

Submission status: Time Limit Exceeded

Solution code:
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:
    Ai_list = Ai[key]
    Aj_list = Aj[key]
    for i in Ai_list:
        ans += len([j for j in Aj_list if j > i])

print(ans)

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 = A[i] + A_min
  if i_upper < i:
    i_upper = i
  if i_upper <= N:
    for j in range(i_upper, N):
      #print(i,j)
      if abs(i - j) == (A[i] + A[j]):
        cnt = cnt + 1
        #print("cnt")
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())


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

l = []
for i in range(n):
    l.append(i)
#print(l)

M = list(itertools.combinations(l, 2))
c = 0
for i,j in M:
    if j-i == H[i] + H[j]:
        c += 1
    #print(i,j)
    #print(i+j)
    #print(c)

print(c)

Submission status: Time Limit Exceeded

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

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 j-i==A_values[i]+A_values[j]:
      temp+=1
print(temp)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
arr = list(map(int, input().split(" ")))

ret = 0
for i in range(1, len(arr)+1):
    for j in range(i+1,len(arr)+1):
        if j - i == arr[i-1] + arr[j-1]:
            ret +=1

print(ret)

Submission status: Time Limit Exceeded

Solution code:
import math

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
cnt = int(cnt/2)
print(cnt)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline().rstrip('\n')


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

N = int(input())
A = [int(s) for s in input().split()]
print(calc(N, A))

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 (j - i == 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())))
b = np.array(a)
a += np.arange(n)+1
b -= np.arange(n)+1
b *= -1
c = 0
for i in a:
    c += len(b[b==i])

print(c)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0

for i in range(n):
    a_height = h_list[i]
    for k in range(i + 1, n):
        b_height = h_list[k]
        if k <= b_height:
            continue
        elif k - i == a_height + b_height:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import itertools

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

for i in range(n):
    jc = 0
    for j in a[i+a[i]:]:
        if j == jc:
            c += 1
        jc += 1

#for i in itertools.combinations(range(n), 2):
#    if a[i[0]] + a[i[1]] == i[1] - i[0]:
#        c += 1

print(c)

Submission status: Time Limit Exceeded

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n = int(input())
    a = input_to_int_tuple()

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

    return ret


if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
S=[]
for i in range(n):
    S.append([A[i],i])
S=list(reversed(sorted(S)))
#print(S)
F=[0]*n

ans=0
C=[0]*n
for i in range(n):
    s=S.pop(0)
    d=s[0] #距離
    x=s[1] #座標
    F[x]=1
    L1=max(x-2*d,0)
    L2=max(x-d,-1)
    R1=min(x+d,n)
    R2=min(x+2*d,n-1)
    if L1<=L2:
        for j in range(L1,L2+1):
            if F[j]==1:
                continue
            if x-j==d+A[j]:
                ans+=1
                #print(s,j)
    if R1<=R2:
        for j in range(R1,R2+1):
            if F[j]==1:
                continue
            if j-x==d+A[j]:
                ans+=1
                #print(s,j)
print(ans)

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+1
    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 numpy as np
n = int(input())
a = [i for i in map(int, input().split())]
a = np.array(a)
num = np.arange(n) + 1
ans = 0
for i in range(n):
    s = np.sum(num - num[i] == a + a[i])
    #print(s)
    ans += s
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans=0
a=list(map(int,input().split()))
now=max(a)
noww=now
matc=list(0 for i in range(n+2*now))
mat2=list(0 for i in range(n+2*now))
for i in range(n):
  matc[now-a[i]]+=1
  mat2[now+a[i]]+=1
  now+=1
#print(matc)
for j in range(noww,noww+n+1):
  ans+=matc[j]*mat2[j]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A = list(map(int, input().split()))
S = list(itertools.combinations(range(1, N + 1), 2))
result = 0
for s in S:
    if abs(s[0] - s[1]) == A[s[0]-1] + A[s[1]-1]:
        result += 1
print(result)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math


def main():
    N = int(input())
    A = list(map(int, input().split()))
    minus_A_plus_i = tuple([- A[i] + (i+1) for i in range(N)])
    A_plus_i = tuple([A[i] + (i+1) for i in range(N)])

    c = 0

    for item in minus_A_plus_i:
        c += A_plus_i.count(item)

    print(c)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools

# 標準入力の取得
N = int(input())
A = list(map(int, input().split()))

# 求解処理
# A_i + i = -A_j + j (i < j)
left = [A[i] + i for i in range(N)]
right = [-A[j] + j for j in range(N)]
result = 0
for i in range(N):
    result += right[i+1:].count(left[i])

# 結果出力
print(result)

Submission status: Time Limit Exceeded

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