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())
As = list(map(int, input().split()))

ans = 0
for i in range(len(As)):
    for j in range(i+1, len(As)):
        if (abs(i - j ) == As[i] + As[j]):
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().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 = [int(x) for x in input().split(" ")]

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

Submission status: Time Limit Exceeded

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

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

n = I()
a = LI()
ans = 0
li = [0]
a = li+a
for i in range(1,n+1):
    for j in range(i,n+1):
        if j-i == a[i] + a[j]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L_A = [int(s) for s in input().rstrip().split(' ')]
[M,m] = [0,10**9]
ans = 0
a = 0
for k in range(N,0,-1):
    p = L_A[k-1]
    if p+m <= a:
        for i in range(1,a+1):
            if p + L_A[k-1+i] == i:
                ans += 1
    M = max(M,p)
    m = min(m,p)
    a += 1
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
import itertools
for i, j in itertools.combinations(range(N), 2):
    if (As[i] + As[j]) == abs(i - j):
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    A_arr_sort = sorted(A_arr)
    height_range = [sum(A_arr_sort[:2]),sum(A_arr_sort[-2:])]
    cnt = 0
    for height in range(height_range[0],height_range[1]+1):
        for i in range(N-height):
            j = i+height
            if A_arr[j]+A_arr[i]==j-i:
                cnt += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i 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:
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 >=2 :
  a = i+1 - A[i]
  b = i+1 +A[i]
  K = B[0:i-1]
  if  a <=0:
    i =i- 1
  else:
    t += K.count(a)
    i =i-1
print(t)

Submission status: Time Limit Exceeded

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

import itertools

a = list(itertools.combinations(range(len(A)), 2))

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
Asort = sorted(A)
Amin = sum(Asort[:2])
Amax = min(sum(Asort[-2:]), N - 1)

cnt = 0
for i in range(N):
    for j in range(Amin, Amax + 1):
        if i + j <= N - 1 and j == A[i] + A[i + j]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for s in range(1, n+1):
    for t in range(s+A[s-1]+1, n+1):
        if A[s-1] + A[t-1] == t-s:
            pn += 1

print(pn)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())

l = np.array([int(i) for i in input().split()])
ans = 0

for i in range(n-1):
    arr = np.arange(n-i,dtype = np.int64)
    m = l[i:] + l[i]
    m = (m == arr)
    ans += np.count_nonzero(m)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
A=list(map(int,input().split()))
l=list(itertools.combinations([i for i in range(1,n+1)],2))
cnt=0
for p,q in l:
    if q-p==A[q-1]+A[p-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+1,n):
    if j-i == A[i] + A[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
hgts = list(map(lambda x:int(x),input().split()))
susp = 0
for i in range(n-1):
  curhgt = hgts[i]
  if i+curhgt<n:
    for j in range(i+curhgt,n):
      if j-i==curhgt+hgts[j]:
        susp += 1
print(susp)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from itertools import accumulate

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


b=[]
for i in range(1,n):
  b.append(a[i]+a[0])

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

b=np.array(b)
c=np.array(c)
c=c[1:]

ans=0
ans+=np.sum(b==c)
for i in range(1,n):
  b-=a[i-1]
  b+=a[i]
  b=b[1:]

  c-=1
  c=c[1:]

  ans+=np.sum(b==c)

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(len(a)):
  for j in range(i+1,len(a)):
    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())
aa = np.array(list(map(int, input().split())))

cnt = 0
for i in range(n-2):
    bb = np.array(range(-aa[0], len(aa)-aa[0]))
    cnt += (aa==bb).sum()
    aa = np.delete(aa, 0)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import bisect


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

    j_minus_aj_ = sorted([(j - A[j], j) for j in range(N)])
    j_minus_aj, j_minus_aj_j = [None] * N, [None] * N
    for j in range(N):
        j_minus_aj[j], j_minus_aj_j[j] = j_minus_aj_[j]

    j_plus_aj_ = sorted([(j + A[j], j) for j in range(N)])
    j_plus_aj, j_plus_aj_j = [None] * N, [None] * N
    for j in range(N):
        j_plus_aj[j], j_plus_aj_j[j] = j_plus_aj_[j]

    ans = 0

    for i in range(N):
        # i <= j
        i_plus_ai = i + A[i]

        left = bisect.bisect_left(j_minus_aj, i_plus_ai)
        right = bisect.bisect_right(j_minus_aj, i_plus_ai)

        for j in range(left, right):
            if j_minus_aj_j[j] >= i:
                ans += 1
        
        i_minus_ai = i - A[i]

        left = bisect.bisect_left(j_plus_aj, i_minus_ai)
        right = bisect.bisect_right(j_plus_aj, i_minus_ai)

        for j in range(left, right):
            if j_plus_aj_j[j] < i:
                ans += 1
    
    return ans // 2

    # for i in range(N):
    #     # i <= j
    #     i_plus_ai = i + A[i]
    #     # left = geq_search(j_minus_aj, i_plus_ai-1)
    #     # dif = 0
    #     # while left+dif+1 < N and j_minus_aj[left+dif+1] != i_plus_ai:
    #     #     dif += 1
    #     # left = left + dif
    #     left = bisect.bisect_left(j_minus_aj, i_plus_ai)

    #     # right = leq_search(j_minus_aj, i_plus_ai+1)
    #     # dif = 0
    #     # while 0 <= right-dif-1 and j_minus_aj[right-dif-1] != i_plus_ai:
    #     #     dif += 1
    #     # right = right - dif
    #     right = bisect.bisect_left(j_minus_aj, i_plus_ai)

    #     for j in range(left, right):
    #         if j_minus_aj_j[j] >= i:
    #             ans += 1
        
    #     i_minus_ai = i - A[i]
    #     # left = geq_search(j_plus_aj, i_minus_ai-1)
    #     # dif = 0
    #     # while left+dif+1 < N and j_plus_aj[left+dif+1] != i_minus_ai:
    #     #     dif += 1
    #     # left = left + dif
    #     left = bisect.bisect_left(j_plus_aj, i_minus_ai)

    #     # right = leq_search(j_plus_aj, i_minus_ai+1)
    #     # dif = 0
    #     # while 0 <= right-dif-1 and j_plus_aj[right-dif-1] != i_minus_ai:
    #     #     dif += 1
    #     # right = right - dif
    #     right = bisect.bisect_left(j_plus_aj, i_minus_ai)

    #     for j in range(left, right):
    #         if j_plus_aj_j[j] < i:
    #             ans += 1
    
    # return ans


print(main())

Submission status: Time Limit Exceeded

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


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

print(retval)

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+a[i],n):
    if j-i==a[j]+a[i]:
      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=np.array([])
C=np.array([i+1 for i in range(n)])
D=np.array([])
for i in range(n-1):
    B=np.append(B,A[:n-i-1]+A[i+1:])
    D=np.append(D,C[i+1:]-C[:n-i-1])
print(len(B)-np.count_nonzero(B-D))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for i in range(1, n+1):
    if n > a[i-1]:
        for j in range(max(a[i-1], i+1), n+1):
            if abs(i - j) == a[i-1] + a[j-1]:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a_=list(map(int,input().split()))
from collections import defaultdict
a=[[i,ai] for i,ai in enumerate(a_)]
sa=defaultdict(lambda:0)
# sa[(i,j)]:i番目の人までで自分の番号-身長がjの人
d=defaultdict(lambda:0)
# 自分の番号-身長の累計
mt=0
for i,ai in a:
  d[i-ai]+=1
  for k,v in d.items():
    sa[(i+1,k)]=v
ans=0
for i,ai in a:
  c=sa[(n,i+ai)]-sa[(i+1,i+ai)]
  ans+=c
print(ans)

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):
    a2_idx = tmp
    a1 = a1_list[a1_idx]
    while a2_idx <= n-1 and  a1 >= a2_list[a2_idx]:
        if a1 == 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 = [int(i) for i in input().split()]
cnt = 0
for i in range(n):
    for j in range(2, n-i):
        if a[i] + a[i+j] == j:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:


def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())
    a_list = []
    a_dict = {}
    i = 0
    count = 0

    for a in map(int, input().split()):
        if i - a >= 1:
            for height, nums in a_dict.items():
                hit_num = i - (a + height)
                if hit_num < 0:
                    continue
                else:
                    if hit_num in nums:
                        count += 1

        a_list.append(a)
        if a in a_dict:
            a_dict[a].add(i)
        else:
            a_dict[a] = set()
            a_dict[a].add(i)

        i += 1


    print(count)


# x = list(map(int, input().split()))

if __name__ == "__main__":
    resolve()

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
        if j0+j != N-j and N-j0-j == As[N-j]:
            c += 1
        j+=1
        l-=2
print(c)

Submission status: Time Limit Exceeded

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

cnt = 0
for org in range(N-1):
    for i in range(org+A[org],N):
        if A[org]+A[i]==i-org:
            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:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())

b = []
c = []
for i in range(n):
    # b.append([i,a[i],i-a[i]])
    c.append(i-a[i])
# print(b)
# print(c)

ans = 0
for i in range(n):
    m = i + a[i]
    ans += c.count(m)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

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

def agent(a,i,j):
  return abs(i-j)==abs(a[i-1]+a[j-1])

count=0
X=list(range(1,N+1))
for c in itertools.combinations(X,2):
   if agent(A,*c):
      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-1):
  if a[i]>n-1:
    continue
  else:
    for h in range(i+1, n):
      if a[h]>n-1:
        continue    
      else:
        d=h-i
        g=a[i]+a[h]
        if d==g:
          count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools

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

mydict = {}
for i in range(1, N+1):
    mydict[i] = A[i-1]


cnt = 0
for v in itertools.combinations(range(1, N+1), 2):
#    print(v, mydict[v[0]], A[v[0]-1])
    if mydict[v[0]] + mydict[v[1]] == abs(v[0] - v[1]):
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(1, N):
    if i <  m+A[i]:
        m = min(m, A[i])
    else:
        for j in range(0, i):
            if A[i] + A[j] == i - j:
                c += 1
        m = min(m, A[i])

print(c)

Submission status: Time Limit Exceeded

Solution code:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


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

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

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

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

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

n = II()
a = LI()
ma = max(a)

ans = 0
for i in range(1,n):
	tmp = 0

	while(tmp<n):
		if tmp+i>=n:
			break
		else:
			if a[tmp]+a[tmp+i]==i:
				ans+=1
			tmp+=1
print(ans)

Submission status: Time Limit Exceeded

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

from itertools import combinations

count = 0

for i,j in combinations(range(N),2):
    if A[i] + A[j] == abs(i - 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(0,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()))
counter=0
for i in range(n-1):
    if(a[i]<200000):
        for j in range(i+1,n):
            if(a[j]<200000):
                if(a[i]+a[j]==j-i or a[j]+a[i]==j-i):
                    counter+=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
H = list(map(int, input().split()))
A = {}
t = 0
for i in range(1, N+1):
    A[i] = H[i-1]
for x in range(0, len(A)):
    for y in range(x + 1, len(A)):
        o = A[x + 1]
        p = A[y + 1]
        if abs((x + 1) - (y + 1)) == o + p:
            t += 1
print(t)

Submission status: Time Limit Exceeded

Solution code:
def solve(n, elements):
    count = 0

    for i in range(n):
        for j in range(i+1, n):
            diff = j - i
            if diff < 0:
                break
            value = elements[i] + elements[j]
            if diff == value:
                count += 1

    return count


if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    result = solve(n, arr)
    print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())

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

c = 0
for a in reversed(range(1,N+1)):
    if A[a-1] - a > 0:
        for b in reversed(range(1, a-A[a-1])):
            if abs(b-a) == A[a-1] + A[b-1]:
                c+=1
    else:
        for b in reversed(range(1, a)):
            if abs(b-a) == A[a-1] + A[b-1]:
                c+=1


print(c)

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 = [[A[i] + A[j] for j in range(n)] for i in range(n)]

    for i in range(n):
        for j in range(i + m1, min(i + m2 + 1, n)):
            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()))

cnt=0
for i in range(0, N-1):
    for j in range(i+1, N):
        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):
  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())
A = list(map(int, input().split()))
Asort = sorted(A)
Amin = sum(Asort[:2])
Amax = min(sum(Asort[-2:]), N - 1)

cnt = 0
for i in range(N):
    for j in range(Amin, Amax + 1):
        if i - j >= 0 and j == A[i - j] + A[i]:
            cnt += 1
        if i + j <= N - 1 and j == A[i] + A[i + j]:
            cnt += 1
print(cnt // 2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
m = max(li) #最大値
ans = 0

for i in range(n):
    li[i] = [i+1, li[i]]

for i in range(n-1):
    for j in range(i+1, min(n, i+1+m*2)):
        x = li[j][0]-li[i][0]
        y = li[j][1]+li[i][1]
        if x == y:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
c = itertools.combinations(range(n), 2)
count = 0

for row in c:
    if abs(row[0]-row[1]) == a[row[0]]+a[row[1]]:
        count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
A = list(map(int,input().split()))
comb = list(combinations(A,2))
num = list(range(1,len(A)+1))
comb_num = list(combinations(num,2))

ans = 0

for i in range(len(comb)):
    if comb[i][0] + comb[i][1] == abs(comb_num[i][0] - comb_num[i][1]):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

#A = [(i, a) for i, a in enumerate(map(int, input().split()), start=1)]
A = np.array(list(map(int, input().split())))
ind = [i for i in range(N)]
cnt = 0
for i in range(N):
    B = ind - np.array([i] * N)#マイナスは気にせず
    C = A + np.array(A[i])
    D = B - C
    cnt += np.count_nonzero(D == 0)
    #print(A,B,C,D)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
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:
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+A[i]+1 < n:
            saigo = i+m+A[i]+1
        if i+a > n:
            ato = n
        for j in range(ato,saigo):
            if j-i == A[i]+A[j]:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
 
a_dict = {}
for i, a in enumerate(a_list):
    if not a in a_dict:
        a_dict[a] = set([i])
    else:
        a_dict[a].add(i)
a_set = set(a_dict.keys())
max_a = max(a_set)
res = 0
while len(a_set)>0:
    a_i = a_set.pop()
    for i in a_dict[a_i]:
        res += sum([a_i+a_j+i in a_dict[a_j] for a_j in a_dict.keys()])
    a_set -= set([a_i])
print(res)

Submission status: Time Limit Exceeded

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

import math

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = set()
mins = set()
for a in A:
    if a not in S:
        mins.add(a)
    elif a in mins:
        mins.remove(a)
    S.add(a)
T = set({s1+s2 for s1 in S for s2 in S if s1+s2 < N})
# print(S)
ans = 0
for s in T:
    for i in range(N-s):
        ans += (A[i] + A[i+s] == s)
print(ans)

Submission status: Time Limit Exceeded

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

count=0

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

print(count)

Submission status: Time Limit Exceeded

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

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

ans = 0

for i in range(n-1):
  index = a[i] + i
  if index >= n-1:
    continue
  else:
    for j in range(index+1, n):
      if j == index + a[j]:
        ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = list(map(int,input().split()))
a = np.array([],dtype = int)

ans = 0
for i in range(N-1):
    a = np.append(a,1-A[i])
    a = np.sort(a)
    ans += np.count_nonzero(a==A[i+1])
    a = a + 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

num_pair = 0

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
c=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:
import itertools
from collections import defaultdict
d = defaultdict(int)
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    d[i+1] = a[i]

d = dict(sorted(d.items(),key=lambda x: x[1]))

cnt = 0
for i in range(1,n+1):
    now = d[i]
    for key,val in d.items():
        if key == i:
            continue
        total = val + now
        if total < n:
            if total == abs(i-key):
                cnt += 1
        else:
            break
    d.pop(i)
print(cnt)