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:
import sys
import itertools
sys.setrecursionlimit(10**7)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
v = []
for i in range(n):
    v.append((a[i], i+1))
ans = 0
for a, b in itertools.permutations(v, 2):
    if abs(a[1] - b[1]) == a[0] + b[0]:
        ans += 1
print(ans//2)

Submission status: Time Limit Exceeded

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    A_i = list(map(int, input().split()))
    
    Ai_plu_i = [i + 1 + A_i[i] for i in range(N)]
    Aj_min_j = [j + 1 - A_i[j] for j in range(N)]

    counter = 0
    
    for num in Ai_plu_i:
        counter += Aj_min_j.count(num)

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
p=list(map(int,input().split()))
M=max(p)
m=min(p)
d=0
for i in range(n):
  if i+p[i]+m<=n and i+p[i]+M<n:
    for j in range(i+p[i]+m,i+p[i]+M+1):
      if j-i==p[i]+p[j]:
        d+=1
  if i+p[i]+m<=n and i+p[i]+M>=n:
    for j in range(i+p[i]+m,n):
      if j-i==p[i]+p[j]:
        d+=1
print(d)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.array(input().split(), dtype=int)
NN = np.arange(1, N+1, 1)
cnt = 0
for i in range(N):
  dA = A + A[i]
  dN = np.abs(NN - NN[i])
  cnt += np.count_nonzero(dA == dN)
print(int(cnt/2))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
p=list(map(int,input().split()))
M=max(p)
m=min(p)
d=0
for i in range(n):
  if i+2*m<=n and i+2*M<n:
    for j in range(i+2*m,i+2*M+1):
      if abs(j-i)==p[i]+p[j]:
        d+=1
  if i+2*m<=n and i+2*M>=n:
    for j in range(i+2*m,n):
      if abs(j-i)==p[i]+p[j]:
        d+=1
print(d)

Submission status: Time Limit Exceeded

Solution code:
# E
# This Message Will Self-Destruct in 5s
import numpy as np

N = int(input())
A_list = np.array([int(x) for x in input().split()])
Num_list = np.arange(1,N+1,1)

L_list = Num_list + A_list
R_list = Num_list - A_list
ans = 0
for i in range(N):
    ans += sum((R_list == L_list[i])[i+1:])

print(ans)

Submission status: Time Limit Exceeded

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

print(int(num/2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# import numpy as np
# import queue
# import heapq


def main():
    n_participants = int(input())
    heights = list(map(int, input().split()))

    """
    for j>i, j-i = Ai + Aj
    i + Ai = j -Aj
    """

    L = dict()
    R = dict()

    for i, height in enumerate(heights):
        idx = i + 1
        L[idx] = idx + height

        if idx-height not in R:
            R[idx - height] = {i}
        else:
            R[idx - height].add(i)

    count = 0
    for key, value in L.items():
        if value in R:
            for v in R[value]:
                if key < v:
                    count += 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# E
# This Message Will Self-Destruct in 5s
import numpy as np

N = int(input())
A_list = [int(x) for x in input().split()]
Num_list = np.arange(1,N+1,1)

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

# 1 ✕ 1 (int)
N = int(input().rstrip())

# N ✕ 1 (int)
A = list(map(int, input().rstrip().split()))

# print(A)
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())

height = input()
height = height.split()
height = [int(s) for s in height]

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

height = input()
height = height.split()
height = [int(s) for s in height]

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
save = [0]*n
#Ai + i
save = [a[i]+i for i in range(n)]
    
#j-Aj
ans = 0
for j in range(n):
    b = j-a[j]
    if(b<0):
        continue
    ans += save[0:j].count(b)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
save = [0]*n
#Ai + i
for i in range(n):
    save[i] = a[i]+i
#j-Aj
ans = 0
for j in range(n):
    b = j-a[j]
    if(b<0):
        continue
    for i in range(j):
        if(b==save[i]):
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
  plus = i+1 + A[i]
  AP.append(plus)
  minus = i+1 - A[i]
  AM.append(minus)
  
ans = 0 

for j in range(N):
  ans += AP.count(j) * AM.count(j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
AP = []
AM = []
for i in range(N):
  plus = i+1 + A[i]
  AP.append(plus)
  minus = i+1 - A[i]
  AM.append(minus)

ans = 0 

for j in range(N):
  for k in range(j+1, N):
    if AM[k] <= 0:
      continue
    if AP[j] == AM[k]:
      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(n-1-i):
        if j+1 == a[i] + a[i+j+1]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

amax = max(a)
amin = min(a)

max = amax * 2

'''
if amin * 2 < n:
    print(0)
'''  
    
for i in range(n):
    j = i + 1 + amin

    while(j < n and j <= i + max):
        if abs(j - i) == a[i] + a[j]:
            ans = ans + 1
        j = j + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def abs(x):
  return x if(x >= 0) else -x

n = int(input())
height = [int(x) for x in input().split()]
pair_num = 0

for i in range(1,n+1):
  for j in range(i+1,n+1):
    if(abs(i-j) == height[i-1]+height[j-1]):
      pair_num += 1
      
print(pair_num)

Submission status: Time Limit Exceeded

Solution code:
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------


n = int(input())
a = list(mapi())
mpi = defaultdict(list)
mpj = defaultdict(list)
for i in range(n):
    mpi[a[i]+i].append(i+1)
    mpj[-a[i]+i].append(i+1)
res =0
for i in mpi.keys():
    tmpi = mpi[i]
    tmpj = mpj[i]
    #print(i,tmpi,tmpj)
    for j in tmpi:
        for k in tmpj:
            if k>j:res+=1
print(res)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    d = dict()
    count = 0
    for no in a:
        d[no] = set()
    for i in range(n):
        no = a[i]
        pos = i+1
        # print(d)
        # print("> pos: "+str(pos))
        if no < pos:
            for j in range(no+1,pos,1):
                # print(">> j: "+str(j))
                if d.get(j-no) is not None and len(d.get(j-no)) > 0:
                    if pos - j in d.get(j-no):
                        count += 1
        d[no].add(pos)
    # print(d)
    print(count)

Submission status: Time Limit Exceeded

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

dic = {}
count = 0
for i in range(N):
    height = A[i]
    for h, j in dic.items():
        height_wa = height + h
        should_val1 = height_wa + i
        should_val2 = i - height_wa
        if should_val1 in j:
            count += 1
        elif should_val2 in j:
            count += 1 
    if not height in dic:
        dic[height] = [i]
    elif not i in dic[height]:
        dic[height].append(i)
    
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    max_A = max(A)
    num = tuple(range(1, N + 1))
    cand = 0
    for a in range(N):
        a_height = A[a]
        for b in range(min(a + 1 + a_height, N), N):
            diff_num = b - a
            sum_height = A[a] + A[b]
            if diff_num == sum_height:
                cand += 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(list(map(str, data))))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input  = sys.stdin.readline
N = int(input())
ka = input().split(" ")
count = 0
for z in range(N):
  for a in range(z+1,N):
    if int(ka[z]) + int(ka[a]) == abs(a - z):
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input  = sys.stdin.readline
N = int(input())
ka = [int(a) for a in input().split(" ")]
count = 0
for z in range(N):
  for a in range(z+1,N):
    if ka[z] + ka[a] == abs(a - z):
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input  = sys.stdin.readline
N = int(input())
x = [a for a in range(N)]
ka = [int(a) for a in input().split(" ")]
count = 0
for z in range(N):
  for a in range(z+1,N):
    if ka[z] + ka[a] == abs(a - z):
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    max_A = max(A)
    num = tuple(range(1, N + 1))
    cand = 0
    for a in range(N):
        a_height = A[a]
        possible_range = max_A + a_height
        for b in range(a + 1, min(a + 1 + possible_range, N)):
            diff_num = b - a
            sum_height = A[a] + A[b]
            if diff_num == sum_height:
                cand += 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(list(map(str, data))))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input  = sys.stdin.readline
N = int(input())
x = [a for a in range(N)]
ka = [int(a) for a in input().split(" ")]
count = 0
for _ in range(N-1):
  z = x[0]
  x.pop(0)
  for a in range(z,max(x)+1):
    if z != a and ka[z] + ka[a] == abs(a - z):
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

from typing import Iterable


def main() -> None:
    N = ri()
    A = rmi()
    num = tuple(range(1, N + 1))
    cand = 0
    for a in range(N):
        for b in range(a + 1, N):
            diff_num = b - a
            sum_height = A[a] + A[b]
            if diff_num == sum_height:
                cand += 1
    w(cand)


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(list(map(str, data))))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ls = []
rs = []
for i in range(len(a)):
    ls.append(-1*a[i]+i+1)
    rs.append(a[i]+i+1)

count = 0
for l in ls:
    if l in rs:
        count+=rs.count(l)
print(count)

Submission status: Time Limit Exceeded

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

ls = []
rs = []
for i, num in enumerate(a, 1):
    ls.append(-1*num+i)
    rs.append(num+i)

count = 0
for l in ls:
    if l in rs:
        count+=rs.count(l)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

ls = []
rs = []
for i, num in enumerate(a, 1):
    ls.append(-1*num+i)
    rs.append(num+i)

ls = sorted(ls)
rs = sorted(rs)

count = 0
for l in ls:
    for r in rs:
        if r == l:
            count+=1
        elif r > l:
            break
print(count)

Submission status: Time Limit Exceeded

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

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

L = []
R = []
for i in range(N):
    L.append(i+A[i])
    R.append(i-A[i])
ans = 0
for l in L:
    ans += R.count(l)
print(ans)

Submission status: Time Limit Exceeded

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

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

L = [i+A[i] for i in range(N)]
R = [i-A[i] for i in range(N)]
ans = 0
for l in L:
    ans += R.count(l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

idx = tuple(range(0, N))
idx_comb = tuple(combinations(idx, 2))
count = 0
for i, j in idx_comb:
    if abs(i-j) == (A[i] + A[j]):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

idx = list(range(0, N))
idx_comb = list(combinations(idx, 2))
count = 0
for i, j in idx_comb:
    if abs(i-j) == (A[i] + A[j]):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
assert n >= 2
a = [int(x) for x in input().split()]
assert len(a) == n
count = 0
for i in range(n-1):
    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())
l = list(map(int,input().split()))

max = max(l) * 2

ans = 0

for i in range(n):
    j = i + 1

    while(j < n and j <= i+max):

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
NUM=[i for i in range(1,N+1)]
H=list(map(int, input().split()))
L_NUM=[x+y for (x,y) in zip(NUM,H)]
R_NUM=[x-y for (x,y) in zip(NUM,H)]

ANS=0
for i in L_NUM:
    ANS+=R_NUM.count(i)
print(ANS)

Submission status: Time Limit Exceeded

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

i_minus = [0]*n
i_plus = [0]*n
for i in range(n):
    i_minus[i] = (i + 1 - a[i])
    i_plus[i] = (i + 1 + a[i])

ans = 0
low = min(i_plus)
high = max(i_minus) + 1
for i in range(low, high):
    minus = i_minus.count(i)
    plus = i_plus.count(i)
    ans += minus * plus
    
print(ans)

Submission status: Time Limit Exceeded

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

i_minus = [0]*n
i_plus = [0]*n
for i in range(n):
    i_minus[i] = (i + 1 - a[i])
    i_plus[i] = (i + 1 + a[i])

ans = 0
low = min(i_minus)
high = max(i_plus) + 1
for i in range(low, high):
    minus = i_minus.count(i)
    plus = i_plus.count(i)
    ans += minus * plus
    
print(ans)

Submission status: Time Limit Exceeded

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

i_minus = [0]*n
i_plus = [0]*n
for i in range(n):
    i_minus[i] = (i + 1 - a[i])
    i_plus[i] = (i + 1 + a[i])

ans = 0
for i in range(10**9 - 2 * 10**5 + 1):
    minus = i_minus.count(i)
    plus = i_plus.count(i)
    ans += minus * plus
    
print(ans)

Submission status: Time Limit Exceeded

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

i_minus = []
i_plus = []
for i in range(n):
    i_minus.append(i + 1 - a[i])
    i_plus.append(i + 1 + a[i])

ans = 0
for i in range(10**9 - 2 * 10**5 + 1):
    minus = i_minus.count(i)
    plus = i_plus.count(i)
    ans += minus * plus
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    plus = [A[i] + i + 1 for i in range(N)]
    minus = [j + 1 - A[j] for j in range(N)]
    L = {}
    R = {}
    X = []
    for i in range(N):
        if plus[i] not in X:
            X.append(plus[i])
            R[plus[i]] = 0
            L[plus[i]] = 0
        R[plus[i]]  += 1
        if minus[i] not in X:
            X.append(minus[i])
            R[minus[i]] = 0
            L[minus[i]] = 0
        L[minus[i]] += 1
        
    count = 0
    for x in X:
        if x > 0:
            count += L[x] * R[x]
    print(count)
    return 0

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    plus = [A[i] + i + 1 for i in range(N)]
    minus = [j + 1 - A[j] for j in range(N)]
    L = {}
    R = {}
    X = []
    for i in range(N):
        if plus[i] not in X:
            X.append(plus[i])
        if minus[i] not in X:
            X.append(minus[i])
    count = 0
    for x in X:
        if x > 0:
            count += plus.count(x) * minus.count(x)
    print(count)
    return 0

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    plus = [A[i] + i + 1 for i in range(N)]
    minus = [j + 1 - A[j] for j in range(N)]
    L = {}
    R = {}
    Count = {}
    count = 0
    X = set(plus) | set(minus)
    for x in X:
        if x > 0:
            count += plus.count(x) * minus.count(x)
    print(count)
    return 0

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    plus = [A[i] + i + 1 for i in range(N)]
    minus = [j + 1 - A[j] for j in range(N)]
    #print(plus)
    #print(minus)
    count = 0
    for i in range(N):
        max_N  = N
        count += minus[i+1:].count(plus[i])
    print(count)
    return 0

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

out = 0

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

Submission status: Time Limit Exceeded

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

out = 0

for i in range(n):
    for j in range(i):
        if(i-j == inList[i] + inList[j]):
            out += 1
print(out)

Submission status: Time Limit Exceeded

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

out = 0

for i in range(n):
    for j in range(i):
        ai = inList[i]
        aj = inList[j]
        if(abs(i-j) == ai + aj):
            out += 1
print(out)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    a=A[i]
    x1=i+1-a
    x2=i+1+a
    pair+=X2.count(x1)
    X2.append(x2)
print(pair)

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    _ = input()
    lst_a = [int(a) for a in input().strip().split(' ')]

    # build hash table
    hash_tbl = {}
    for i, a_i in enumerate(lst_a):
        n_i = i + 1
        tmp = int(n_i - a_i)
        if tmp > 0:
            if tmp in hash_tbl.keys():
                hash_tbl[tmp].append(n_i)
            else:
                hash_tbl[tmp] = [n_i]

    ans = 0
    for j, a_j in enumerate(lst_a):
        n_j = j + 1
        tmp = int(n_j + a_j)
        if tmp in hash_tbl.keys():
            ans += len([idx for idx in hash_tbl[tmp] if idx > j])
    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
	N = int(input())
	ls = [int(a) for a in input().split()]
	c = 0
	stack = []
	for i in range(N):
		h = ls[i]
		if i > 0:
			c += stack.count(i-h)
		stack.append(h+i)

	print(c)

Submission status: Time Limit Exceeded

Solution code:
def E():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = 0
    import heapq
    sum_min = sum(heapq.nsmallest(2,a))
    sum_max = sum(heapq.nlargest(2,a))
    for sum_target in range(sum_min,sum_max+1):
        for i in range(1,n-sum_target+1):
            j = i+sum_target
            if a[i-1]+a[j-1] == sum_target:
                cnt += 1
    print(cnt)
E()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = []
for i,v in enumerate(a,1):
    b.append((i,v))

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

for i in range(n-1):
    for j in range(i+1,n):
        if b[i][1]+b[j][1]==abs(b[i][0]-b[j][0]):
            ans += 1
        if b[i][1]+b[j][1] > n-1:
            break
    if b[i][1] > n-1:
        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-1):
    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:
def main():
    # n:人数, a:身長リスト
    n = int(input())
    a = list(map(int, input().split()))
    # Li=i+Ai, Ri=i-Aiを満たすL,Rを作成
    L = [0]*n
    R = [0]*n
    for i,ai in enumerate(a):
        L[i] = i+ai
        R[i] = i-ai
    # Li=X=Rj,i<jを満たす組が存在する時count+=1
    count = 0
    for i,Li in enumerate(L):
        count += len([idx for idx,x in enumerate(R[(i+1):n]) if x==Li])

    print(count)

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    # n:人数, a:身長リスト
    n = int(input())
    a = list(map(int, input().split()))
    # Li=i+Ai, Ri=i-Aiを満たすL,Rを作成
    L = [(i+a[i]) for i in range(n)]
    R = [(i-a[i]) for i in range(n)]
    # Li=X=Rj,i<jを満たす組が存在する時count+=1
    count = 0
    for i,Li in enumerate(L):
        count += len([idx for idx,x in enumerate(R[(i+1):n]) if x==Li])

    print(count)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    # n:人数, a:身長リスト
    n = int(input())
    a = list(map(int, input().split()))
    # Li=i+Ai, Ri=i-Aiを満たすL,Rを作成
    L = [(i+a[i]) for i in range(n)]
    R = [(i-a[i]) for i in range(n)]
    # Li=X=Rj,i<jを満たす組が存在する時count+=1
    count = 0
    for i,Li in enumerate(L):
        if (Li in R[(i+1):n]):
            count += len([idx for idx,x in enumerate(R[(i+1):n]) if x==Li])

    print(count)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    # n:人数, a:身長リスト
    n = int(input())
    a = list(map(int, input().split()))
    # Li=i+Ai, Ri=i-Aiを満たすL,Rを作成
    L = [(i+a[i]) for i in range(n)]
    R = [(i-a[i]) for i in range(n)]
    # Li=X=Rj,i<jを満たす組が存在する時count+=1
    count = 0
    for i,Li in enumerate(L):
        if (Li in R):
            j_list = [idx for idx,x in enumerate(R) if i<idx and x==Li]
            for j in j_list:
                 count+=1
    print(count)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    # n:人数, a:身長リスト
    n = int(input())
    a = list(map(int, input().split()))
    # Li=i+Ai, Ri=i-Aiを満たすL,Rを作成
    L = [(i+a[i]) for i in range(n)]
    R = [(i-a[i]) for i in range(n)]
    # Li=X=Rj,i<jを満たす組が存在する時count+=1
    count = 0
    for i,Li in enumerate(L):
        if (Li in R):
            j_list = [idx for idx,x in enumerate(R) if x == Li]
            for j in j_list:
                 if i<j: count+=1
    print(count)

main()

Submission status: Time Limit Exceeded

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

result=0

L_p=[j+A[j] for j in range(N)]
L_n=[j-A[j] for j in range(N)]

for j in range(N-1):
    result += L_n[j+1:].count(L_p[j])

print(result)

Submission status: Time Limit Exceeded

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

result=0

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

print(result)