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 numpy as np

def resolve():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    ok_count = 0
    for i in range(N):
        index_ary = np.arange(i+1, N)
        tall_list = A[index_ary]
        ok_count += np.where((tall_list + A[i]) == (index_ary - i))[0].size
    print(ok_count)

resolve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
height = list(map(int,input().split()))
y = min(height)
count = 0
for x in range(1+y,n-y+1):#とりうる
    counti = 0
    countj = 0
    for i in range(n):
        if i+1+height[i] == x:
            #print(i,height[i],x)
            counti += 1
        if i+1-height[i] == x:
            #print(i,height[i],x)
            countj += 1
    count += counti * countj
    #print(count,counti,countj)

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())

a = list(map(int,input().split()))
ans = 0
for seq in itertools.combinations(range(n),2):
    if abs(seq[0]-seq[1]) == a[seq[0]] + a[seq[1]]:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
H = list(map(int, input().split()))
L = [None]*N
R = [None]*N

for i in range(N):
    L[i] = i+1 + H[i]
    R[i] = i+1 - H[i]

cnt = 0

for i in range(N):
    for j in range(N):
        if i < j:
            if L[i] == R[j]:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A1 = [[-a-i,i] for i, a in enumerate(A)]
A2 = [[a-i,i] for i, a in enumerate(A)]
A1.sort()
A2.sort()
i = j = 0
cnt = 0
while i < N and j < N:
    if A1[i][0] == A2[j][0]:
        buf1 = 1
        for k in range(i+1, N):
            if A1[k][0] != A1[i][0]:
                break
            buf1 += 1
        buf2 = 1
        for k in range(j+1, N):
            if A2[k][0] != A2[j][0]:
                break
            buf2 += 1
        for i_ in range(i, i+buf1):
            for j_ in range(j, j+buf2):
                if A1[i_][1] < A2[j_][1]:
                    cnt += 1
        i += buf1
        j += buf2
    elif A1[i][0] < A2[j][0]:
        i += 1
    else:
        j += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
ans=0
l=[]
r=[]
for i,j in enumerate(a):
    l.append(i+j)
    r.append(i-j)

#ref = dict(Counter(r))
#ans = 0
#for i in l:
#    ans += ref.get(i, 0)
#print(ans)

for i in l:
    ans+=r.count(i)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys
import bisect
from operator import itemgetter


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n = _i()
    a = tuple(_ia())
    l = {}
    for i, ai in enumerate(a):
        aip = ai + i + 1
        l[aip] = l.get(aip, 0) + 1
    r = tuple(sorted(i+1-ai for i, ai in enumerate(a)))
    li = 0
    ans = 0
    for k, v in sorted(l.items(), key=itemgetter(0)):
        r = r[li:]
        li = bisect.bisect_right(r, k)
        ans += v * (li - bisect.bisect_left(r[:li], k))
        if li >= n:
            break
    return ans


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

l2=list(range(n))

import itertools
l3=list(itertools.combinations(l2, 2))

count=0
for i in l3:
    x=abs(i[0]-i[1])
    y=l[i[0]]+l[i[1]]
    if x==y:
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = int(sys.stdin.readline())
a = inpl()
count = 0
for i in range(n):
    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=input()
l=list(map(int,input().split()))
x=0
d=max(l)*2
for i in range(len(l)):
  z=[len(l),i+d+1]
  for j in range(i+1,min(z)):
    s=l[i]+l[j]
    t=i-j
    if s+t==0:
      x+=1
    if s-t==0:
      x+=1
print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
s = [i+j for i,j in enumerate(a)]
sub = [i-j for i,j in enumerate(a)]
res = 0
for x in s:
    if x in sub:
        res += sub.count(x)

print(res)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    A = LI()
    ans = 0


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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import itertools
 
 
# 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():
    N = int(input())
    A = [int(x) for x in input().split()]
    c = itertools.combinations_with_replacement(range(1, N + 1), 2)
    cnt = 0
    for i in c:
        x = i[0]
        y = i[1]
        if y - A[y - 1] == x + A[x - 1]:
            cnt += 1
    print(cnt)
    return
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
    N = int(input())
    A = tuple(int(c) for c in input().split(' '))
    l = []
    for i, a in enumerate(A):
        l.append((i+1, a))
    l.sort(key=lambda x: x[1])
    #print(l)
    cnt = 0
    for a, b in itertools.combinations(l, 2):
        if abs(a[0] - b[0]) == a[1] + b[1]:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
minus=[]
res=0
for i in range(0,n):
  minus.append(i-a[i])
for i in range(0,n):
  res+=minus.count(i+a[i])
print(res)

Submission status: Time Limit Exceeded

Solution code:
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys
import bisect
from operator import itemgetter


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n = _i()
    a = tuple(_ia())
    l = {}
    for i, ai in enumerate(a):
        aip = ai + i + 1
        l[aip] = l.get(aip, 0) + 1
    r = tuple(sorted(i+1-ai for i, ai in enumerate(a)))
    li = 0
    ans = 0
    for k, v in sorted(l.items(), key=itemgetter(0)):
        r = r[li:]
        li = bisect.bisect_right(r, k)
        ans += v * (li - bisect.bisect_left(r, k))
        if li >= n:
            break
    return ans


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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
L = defaultdict(list)
R = defaultdict(list)
for i in range(N):
    L[i + A[i]].append(i)
    R[i - A[i]].append(i)

# print(L)
# print(R)
ans = 0
for k in L.keys():
    l = L[k]
    r = R[k]
    cnt = 0
    for i in l:
        for j in r:
            if i < j:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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



def main():
    a_added = [a[i] + i for i in range(n)]
    a_substracted = [j - a[j] for j in range(n)]
    c = 0
    
    for i in range(n-1):
        for j in range(i+1, n):
            if a_added[i] == a_substracted[j]:
                c += 1 

    print(c)
main()

Submission status: Time Limit Exceeded

Solution code:


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

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

    print(count)



main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import itertools


# 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():
    N = int(input())
    A = [int(x) for x in input().split()]
    c = itertools.combinations_with_replacement(range(1, N + 1), 2)
    cnt = 0
    for i in c:
        x = i[0]
        y = i[1]
        if y - A[y - 1] == x + A[x - 1]:
            cnt += 1
    print(cnt)
    return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

wa = []
sa = []

for i in range(n) :
    wa.append(i+1+a[i])
    sa.append(i+1-a[i])

for i in range(n) :
    ans += sa.count(wa[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
count=0
x=[0]*n
y=[0]*n
for i,j in enumerate(num_list):
    x[i]=i+j
    y[i]=i-j
for i in x:
    for j in y:
        if i==j:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = [i+1 + a[i] for i in range(n)]
r = [i+1 - a[i] for i in range(n)]
c = 0
for i in range(2, n):
    c += l.count(i)*r.count(i)
print(c)

Submission status: Time Limit Exceeded

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

for i in range(n):
    ru.append(int(i+a[i]))
    tmp = i - a[i]
    ans += ru.count(tmp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
pl = [0]*n
nl = [0]*n
ans = 0

for i in range(n):
    pl[i] = i + 1 + a[i]
    nl[i] = i + 1 - a[i]

for i in range(n - 1):
    ans += nl[i + 1:].count(pl[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

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

comb = np.array(list(itertools.combinations(Al, 2))).sum(axis = 1)
comb_i = np.array(list(itertools.combinations(np.arange(1, N+1), 2)))
comb_i = abs(comb_i[:, 1] - comb_i[:, 0])

print((comb == comb_i).sum())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

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

D = C - ind
cnt = np.count_nonzero(D == 0)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(N):
  for j in range(i,N):
    L = i + A_list[i]
    R = j - A_list[j]
    if L == R:
      cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
pluslist=[]
minuslist=[]
res=0
for i in range(0,n):
  pluslist.append(a[i]+i)
  minuslist.append(i-a[i])
for i in range(0,n):
  res+=minuslist.count(pluslist[i])
print(res)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
K = list(range(1, n + 1))
A = list(map(int, input().split()))
K_A = list(zip(K, A))
C = list(itertools.combinations(K_A, 2))
ans = 0
for c in C:
    if abs(c[0][0] - c[1][0]) == c[0][1] + c[1][1]:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[0]*n
ans2=[0]*n
ans1=[0]*n
a=list(map(int,input().split()))
List=[i for i in range(1,n+1)]

ans1=[List[i]+a[i] for i in range(n)]
ans2=[List[i]-a[i] for i in range(n)]

#print(ans1)
#print(ans2)
al1=max(ans1)
al2=max(ans2)
al=max(al1,al2)
ans=0
for i in range(al):
  if (ans1.count(i)>0 and ans2.count(i)>0):
    ans+=ans1.count(i)*ans2.count(i)
print(ans)

Submission status: Time Limit Exceeded

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

ai_li = [a_inputs[i]+(i+1) for i in range(n)]
aj_li = [(j+1)-a_inputs[j] for j in range(n)]

ans=0
for a in ai_li:
    if a in aj_li:
        ans+=aj_li.count(a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
AI = tuple(i + a for i, a in enumerate(A))
AJ = tuple(i - a for i, a in enumerate(A))

count = 0
for k in range(0, max(AI)):
    ci = AI.count(k)
    cj = AJ.count(k)
    count += ci * cj
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def main():
    a_added = [a[i] + i for i in range(n)]
    a_substracted = [j - a[j] for j in range(n)]
    c = 0
    for i in range(n):
        c += a_substracted.count(a_added[i])
            
    print(c)
main()

Submission status: Time Limit Exceeded

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

for i in range(n):
    ru.append(int(i+a[i]))
    #print(ru)
    for j in range(len(ru)-1):
        if ru[j] == i - a[i]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections


def main():
    N = int(input())
    
    An = list(map(int, input().split(' ')))
    
    X = N * (N - 1) // 2
    
    # y - Ay == Ax + x
    L = [i - An[i-1] for i in range(1, len(An)+1)]
    R = [i + An[i-1] for i in range(1, len(An)+1)]
    
    
    cL = collections.Counter(L)
    cR = collections.Counter(R)

    c = 0
    for i in range(1, X+1):
        c += cL[i] * cR[i]
    print(c)
    
    
    
    
    
    


main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import collections
n = int(input())
A = np.array(list(map(int,input().split())))
B = np.array([i+1 for i in range(n)])
C,D = A+B,B-A
x = max(max(C),1)
ans = 0

c = collections.Counter(C)
d = collections.Counter(D)
ans = 0
for i in range(x):
    ans += c[i]*d[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
x=0
for i in range(n):
    b.append(a[i]+i)
    c.append(-a[i]+i)
for p in b:
    for q in c:
        if p==q:
            x+=1
print(x)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(_) for _ in input().split()]
l=[a[i]+i for i in range(n)]
r=[i-a[i] for i in range(n)]
ans=0
for i in range(n):ans+=r.count(l[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
an = list(map(int, input().split()))
check1 = []
check2 = []
ans = 0
for i, a in enumerate(an):
    check1.append(i+a)
    check2.append(i-a)
    if i-a in check1:
        ans += check1.count(i-a)
    if i+a in check2:
        ans += check2.count(i+a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline().rstrip())
As = list(map(int, sys.stdin.readline().rstrip().split()))

ll = [0] * N
lr = [0] * N
for i in range(N):
    ll[i] = i + 1 + As[i]
    lr[i] = i + 1 - As[i]

ans = 0
for l in ll:
    ans += lr.count(l)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())

que = []

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

R = copy.deepcopy(A)
L = copy.deepcopy(A)

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

count = 0
for i in range(min(A),max(A)+n):
    s = 0
    t = 0
    s = R.count(i)
    t = L.count(i)

    count += s*t

print(count)

Submission status: Time Limit Exceeded

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

spy = 0
l = []
r = []
for i in range(N):
  l.append(i - A[i])
  r.append(i + A[i])

mini_l = [i for i in l if i > 0]
mini_r = [i for i in r if i < N]
for i in mini_l:
  spy += mini_r.count(i)
  
print(spy)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(1000000)


def main():
    n = int(input())
    l_dic = {}
    r_dic = {}
    i = 0
    for a in map(int, input().split()):
        ld = l_dic.setdefault(i + a, [])       
        ld.append(i)
        rd = r_dic.setdefault(i-a, [])
        rd.append(i)
        i += 1
    
    count = 0
    for rk, rv_list in r_dic.items():
        if rk not in l_dic:
            continue
        lv_list = l_dic[rk]
        for rv in rv_list:
            count += len([lv for lv in lv_list if lv < rv])
    
    print(count)



main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
an = list(map(int, input().split()))
check1 = []
check2 = []
ans = 0
for i, a in enumerate(an):
    check1.append(i+a)
    check2.append(i-a)
    ans += check1.count(i-a)
    ans += check2.count(i+a)
print(ans)

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)]
C=[i-A[i]+1 for i in range(N)]
ans=0
D=set(C)
for a in D:
  ans+=B.count(a)*C.count(a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(map(int, input().split()))
AI = [i + a for i, a in enumerate(A)]
AJ = [i - a for i, a in enumerate(A)]

count = 0
for k in range(0, max(A)+2*10**5):
    ci = AI.count(k)
    cj = AJ.count(k)
    count += ci * cj
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())

que = []

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

R = copy.deepcopy(A)
L = copy.deepcopy(A)

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

count = 0
for i in range(max(A)+n):
    s = 0
    t = 0
    s = R.count(i)
    t = L.count(i)

    count += s*t

print(count)

Submission status: Time Limit Exceeded

Solution code:
# 32:35
n = int(input())

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

values = dict()

for invI, h in enumerate(heights):
    c1 = invI - h
    if (c1) in values:
        values[c1].append((invI, h))
    else:
        values[c1] = [(invI, h)]
    c2 = -invI - h
    if (c2) in values:
        values[c2].append((-invI, h))
    else:
        values[c2] = [(-invI, h)]

count = dict()
for j, h in enumerate(heights):
    if (j + h) in values:
        for i, ai in values[j + h]:
            if i > 0 and i > j and not (j, i) in count:
                count[(j, i)] = True
    if (h - j) in values:
        for invI, ai in values[h - j]:
            i = -invI
            if invI < 0 and j > i and not (i, j) in count:
                count[(i, j)] = True

print(len(count))

Submission status: Time Limit Exceeded

Solution code:
from math import ceil #切り上げ
import numpy as np
import sys
 
def inp(): return int(input()) #一個だけ読み取り
def inpm(): return map(int,input().split()) #mapオブジェクトで呼び出し
def inpl(): return list(map(int, input().split())) #数字リストをintで
def inpls(): return list(input().split()) #リストをstrで
 
N = inp()
A = inpl()
all = []
count = 0
for i in range(N):
  for j in range(i+1,N):
    if abs(i-j) == A[i]+A[j]:
      count += 1
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

l = {}
r = {}

for i in range(n):
    x = i + an[i]
    if x not in l:
        l[x] = [i]
    else:
        l[x].append(i)

    x = i - an[i]
    if x not in r:
        r[x] = [i]
    else:
        r[x].append(i)

sum = 0
for k in l:
    if k in r:
        for i in range(len(l[k])):
            for j in range(len(r[k])):
                if l[k][i] != r[k][j]:
                    sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
list = list(map(int, input().split()))
i=1
j=1
res=0

while(i<N+1):
  j=1
  while(j<N+1):
    if(j-i==list[i-1]+list[j-1]):
      res+=1
    j+=1
  i+=1
print(res)

Submission status: Time Limit Exceeded

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

def binp(arr, val):
    left,right = 0,len(arr)-1
    while left <= right:
        mid = (left+right)//2
        if val==arr[mid]: return 1
        elif val>=arr[mid]: left = mid+1
        else: right = mid-1
    return 0

ap = [a[i] + i for i in range(1,n+1)]
an = [i - a[i] for i in range(1,n+1)]
an.sort()

ans = 0
for ele in ap:
    if binp(an,ele): ans += an.count(ele)

print(ans)

Submission status: Time Limit Exceeded

Solution code:

def main():
    N = int(input())
    
    An = list(map(int, input().split(' ')))
    
    X = N * (N - 1) / 2
    
    # y - Ay == Ax + x
    L = [i - An[i-1] for i in range(1, len(An)+1)]
    R = [i + An[i-1] for i in range(1, len(An)+1)]
    
    c = 0
    for l in L:
        for r in R:
            if l == r:
                c += 1
    print(c)
    


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

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 = N**2-np.count_nonzero(co)
print(ans//2)

Submission status: Time Limit Exceeded

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

spy = 0
l = []
r = []
for i in range(N):
  l.append(i - A[i])
  r.append(i + A[i])

for i in l:
  spy += r.count(i)
  
print(spy)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n=int(input())
idx=np.arange(1,n+1)
a=np.array(list(map(int,input().split())))
l=idx+a
r=idx-a
mi=max(l.min(),r.min())
ma=min(l.max(),r.max())
ans=0
for x in range(mi,ma+1):
    ll=np.count_nonzero(l==x)
    rr=np.count_nonzero(r==x)
    ans+=ll*rr
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A = list(map(int,input().split()))
I = list()
J = list()
ans = 0

for i in range(N):
  I.append(A[i]+i)
  J.append(i-A[i])
for i in I:
  ans += J.count(i)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
x = int(input())
height = list(map(lambda x: int(x), input().split()))  
cands = []


count = 0
for i in range(len(height)):
  tmp = []
  cands.append(tmp)
  
  
for i in range(len(height)):
  if i-height[i] >= 0:
    for j in cands[i-height[i]]:
      count += 1
      
  if i+height[i] < len(height):
    cands[i+height[i]].append(i)

print(count)

Submission status: Time Limit Exceeded

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

max1 = max(A)
A_ = A.copy()
A_.remove(max1)
max2 = max(A_)
ln = max1 + max2
ret = 0
for i in range(len(A)-1):
    for j in range(i+1, min(i + ln + 1, len(A) )):
        if A[j] + A[i] == j - i:
            ret += 1
print(ret)

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]
    n_aa = i + a_height + 1000000000 + 1
    if n_aa > n:
        n_aa = n
    for k in range(i + 1 + a_height, n_aa):
        b_height = h_list[k]
        if k - i == a_height + b_height:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
B=[]
for i in range(N):
    B.append(i+1)

l=[]
count=0
import itertools
A=list(map(int,input().split()))
for i in itertools.combinations(B, 2):
    l.append(i)
l=list(l)
for j in range(len(l)):
    if A[l[j][0]-1]+A[l[j][1]-1]==abs(l[j][0]-l[j][1]):
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
x=0
for i in range(n):
    for j in range(i,n):
        if i!=j:

            if abs(i+1-(j+1))==(a[i]+a[j]):
                x+=1
print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

N = int(input().strip())
# A = [a for a in enumerate([int(x) for x in input().strip().split(" ")])]
A = [int(x) for x in input().strip().split(" ")]

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
ans=0
for i in range(N):
  B.append(i+1+A[i])
for i in range(N):
  C.append(i+1-A[i])
D=set(C)
for a in D:
  ans+=B.count(a)*C.count(a)
print(ans)

Submission status: Time Limit Exceeded

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

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

def main(kwargs):
    n = kwargs["n"]
    A = kwargs["A"]
    res = 0
    m1 = min(A) * 2
    m2 = max(A) * 2

    for i in range(n):
        for j in range(i + m1, min(i + m2 + 1, n)):
            if j - i == A[i] + A[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:
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


N = readint()
A = list(readnums())

L = [i + x for i, x in enumerate(A)]
R = [i - x for i, x in enumerate(A)]

x1 = min(max(L), max(R))
x2 = max(min(L), min(R))

ans = 0
for i in range(x2, x1 + 1):
    ans += L.count(i) * R.count(i)

print(ans)