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: Runtime Error

Solution code:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
const long long INF = 1LL << 60;
const int MOD = 1e9 + 7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
    
    ll N;
    cin >> N;
    std::vector<ll> A(N);

    rep(i,N){
        cin >> A.at(i);
    }

    std::vector<ll> init(N);

    rep(i,N){
        init.at(i) = -A.at(i)-i;
    }

    sort(init.begin(),init.end());

    ll ans = 0;
    rep(i,N){
        rep(j,N){
            if(A.at(i)-i == init.at(j)){
                ans++;
            }else if(A.at(i)-i < init.at(j)){
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
C = [0]*N
for i in range(N):
    B[i] = i + 1 - A[i]
    C[i] = i + 1 + A[i]
K = [0]*200001
L = [0]*200001
for i in B:
    K[i] += 1
for i in C:
    L[i] += 1
M = [0]*200001
for i in range(200001):
    M[i] = K[i]*L[i]
print(sum(M))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])

arr = []
count = 0
for a in A:
    arr.append(A + a)

for i, lis in enumerate(arr):
    for j, x in enumerate(lis[i:]):
      if x == j:
        count += 1

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
goukei = 0

N = int(input()) * (-1)
Ai = list(map(int, input().split()))
array_Ai = np.array(Ai)
for i in range(len(Ai)):
    number = np.array([j + i for j in range(0, N, -1)])
    new_ai = number + array_Ai
    goukei += np.count_nonzero(new_ai == -Ai[i])

print(goukei)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
h = list(map(int, input().split()))
not_good = []
for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] > h[b - 1]:  # bはダメ
        not_good.append(b)
    elif h[a - 1] == h[b - 1]:
        not_good.append(a)
        not_good.append(b)
    else:
        not_good.append(a)
ans = 0
not_good = list(set(not_good))
not_good.sort()
# print(not_good)
idx = 0
for i in range(1, n + 1):
    if i < not_good[idx]:
        ans += 1
        # print(i, end=" ")
    elif i == not_good[idx]:
        idx += 1
        if idx == len(not_good):
            ans += n - i
            break
    else:
        pass
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
a=int(n)
b=list()
r=0
c=0
while(c!=a):
    c=c+1
    d=input()
    j=int(d)
    b.append(j)
    
for i in b:
    for k in b:
        g=b.index(i)-b.index(k)
        if g<0:
            g=g*(-1)
        if (i+k)==g:
            r=r+1
print(r)

Submission status: Runtime Error

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

fromLeft = [-1]*n

for i in range(n):
    fromLeft[i] = a[i] - i

ans = 0

ldList = [0]*(3*10**5)

for i in reversed(range(n)):
    if fromLeft[i] < 3*10**5-10:
        ldList[fromLeft[i]] += 1
    ans += ldList[-1*a[i]-i]

print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n=int(input())

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

needsearch=[]

for i in range(n):
    a[i]-=(i+1)
    needsearch.append(-2*(i+1)-a[i])

counter=[0]*(2*(10**5))

for i in range(n):
    if 0<a[i]+10**5<2*(10**5):
        counter[a[i]+10**5]+=1

ans = 0
for i in range(len(needsearch)):
    ans += counter[needsearch[i]+10**5]



print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = input().split()
pl = []
sb = []
for i in range(len(a)):
	pl.append(i+int(a[i])+1)
	if i - int(a[i]) > 1:
		sb.append(i-int(a[i])+1)


if len(sb) == 0:
	print('0')
else:

# spl = sorted(pl)
	ssb = sorted(sb)
	t = min(ssb)
	tl = [0] * max(pl)
	for i in ssb:
		tl[int(i)-1] += 1
	# print(pl)
	# print(sb)
	# print(tl)
	cnt = 0
	for i in pl:
		cnt += tl[int(i)-1]

	print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int, input().split()))
b=[0]*n
c=[0]*n
for i in range(n):
    b[i]=a[i]+i
    c[i]=i-a[i]
bs=sorted(b)
cs=sorted(c)
lx=[1+10**10]*n
ly=[2+10**10]*n
rx=[3+10**10]*n
ry=[4+10**10]*n

lx[0]=1
ly[0]=bs[0]
rx[0]=1
ry[0]=cs[0]

d=0
e=0
for j in range (1,n):
    if bs[j]==bs[j-1]:
        lx[d]+=1
    else:
        d+=1
        lx[d]=1
        ly[d]=bs[j]
        
for k in range (1,n):
    if cs[k]==cs[k-1]:
        rx[e]+=1
    else:
        e+=1
        rx[e]=1
        ry[e]=cs[k]
x=0
ans=0
for l in range(d):
    while ry[x]<=ly[l]:
        if ry[x]==ly[l]:
            ans+=(lx[l]*rx[x])
            x+=1
        else:
            x+=1
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
a=int(n)
b=list()
r=0
c=0
while(c!=a):
    c=c+1
    d=input()
    j=int(d)
    b.append(j)
    
for i in b:
    for k in b:
        g=b.index(i)-b.index(k)
        if g<0:
            g=g*(-1)
        if (i+k)==g:
            r=r+1
print(r)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
C = [0]*N
for i in range(N):
    B[i] = i + 1 - A[i]
    C[i] = i + 1 + A[i]
B.sort()
C.sort()
K = [1]*300000
for i in B:
    K[i] *= 2
for i in C:
    K[i] *= 5
ans = 0
for i in K:
    p = 0
    q = 0
    if i%10 == 0:
        while i%2 == 0:
            i = i//2
            p += 1
        while i != 1:
            i = i//5
            q += 1
        ans += p*q
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(input().split(), np.int32)
B = np.arange(1, N + 1)
X = A[None, :] + A[:, None]
Y = B[None, :] - B[:, None]
print(np.count_nonzero(X == Y))

Submission status: Runtime Error

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

fromLeft = [-1]*n

for i in range(n):
    fromLeft[i] = a[i] - i

ans = 0

ldList = [0]*(3*10**5)

for i in reversed(range(n)):
    ldList[fromLeft[i]] += 1
    ans += ldList[-1*a[i]-i]

print(ans)

Submission status: Runtime Error

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

li = [0]*(10**6+1)

for i in range(1,n):
    if ai[i] >= 2*10**5:
        continue
    li[ai[i]-i+5*10**5] += 1

ans = 0

for i in range(1,n):
    #print(i)
    ans += li[-ai[i-1]-(i-1)+5*10**5]
    if i == n:
        #print(i,i,i)
        break
    if ai[i] < 2*10**5:
        li[ai[i]-i+5*10**5] -= 1
        
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

n1,n2=np.meshgrid(np.arange(1,N+1),np.arange(1,N+1))
t1,t2=np.meshgrid(np.array(A),np.array(A))
ans=(np.abs(n2-n1)==t1+t2)

print(np.count_nonzero(ans)//2)

Submission status: Runtime Error

Solution code:
import copy
import numpy as np

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



A_tile = np.tile(A,(N,1))
A_tile_T = A_tile.T
X = np.array([[j - i for j in range(N)]for i in range(N)])
output_ = X+A_tile+A_tile_T
print(np.count_nonzero(output_ == 0) - A.count(0))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=[0 for i in range(2*10**5)]
r=[0 for i in range(2*10**5)]
c=1
a=0
if n!=0:
  k=[int(i) for i in input().split()]
for i in range(n):
  if k[i]+c<=2*10**5:
    l[k[i]+c]+=1 
  if -k[i]+c>=0 and -k[i]+c<=2*10**5:
    r[-k[i]+c]+=1
  c+=1
for i in range(n):
  a+=l[i]*r[i]
print(a)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
A= list(map(int, input().split()))
a=[]
for i,v in enumerate(A):
    if v<n:
        a.append([i+1,v])
a.sort(key=lambda x: x[1])
ans=0
for i,v in enumerate(a):
    for j in range(i+1,n):
        tmp=a[j][1]+v[1]
        if tmp>=n:
            break
        if tmp==abs(v[0]-a[j][0]):
            ans+=1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=[0 for i in range(2*10**5)]
r=[0 for i in range(2*10**5)]
c=1
a=0
if n!=0:
  k=[int(i) for i in input().split()]
for i in range(n):
  l[k[i]+c]+=1 
  if -k[i]+c>=0 and -k[i]+c<=2*10**5:
    r[-k[i]+c]+=1
  c+=1
for i in range(n):
  a+=l[i]*r[i]
print(a)

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
idList = [i for i in range(1, n+1)]
temp = 0
for i in range(n):
    tar = a[temp]
    if (tar >= n):
        del a[i]
        del idList[i]

    else:
        temp += 1

com = list(itertools.combinations(idList, 2))

num = len(com)
ans = 0
for i in range(num):
    aa = com[i]
    # print(aa)
    idA = aa[0]
    idB = aa[1]
    dif = abs(idA - idB)
    indexA = idList.index(idA)
    indexB = idList.index(idB)

    height = a[indexA] + a[indexB]

    if (height == dif):
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
A = np.array(list(map(int, input().split())))
X = A+np.arange(N)+1
S = A*(-1)+np.arange(N)+1
Ans=0
for i in range(N):
    Ans += np.count_nonzero(S[i:] == X[i])
print(Ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
pl = []
dic_mn = {}
for i in range(-n,n):
    dic_mn[i] = 0

for i in range(n):
    pl.append(a[i] + i)
    dic_mn[i - a[i]] += 1
ans = 0
for i in range(n):
    try:
        ans += dic_mn[pl[i]]
    except:
        ans = ans
print(ans)
#print(pl)
#print(dic_mn)

Submission status: Runtime Error

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

count = 0

def dfs(x, y):
    global count
    if x >= N or y >= N:
        return
    
    if (A[x]+A[y]) == y-x:
        count += 1
    
    if y+1 >= N:
        dfs(x+1, x+2)
    else:
        dfs(x, y+1)


dfs(0, 1)

print(count)

Submission status: Runtime Error

Solution code:
s=int(input())
alist=input()
list1=list(alist)
count=0
for i in range(0,s-1):
	for j in range(i+1,s-1):
    	if(j-i=list1[i]+list[j]):
        	count+=1
print(count)

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
idList = [i for i in range(1, n+1)]
temp = 0
for i in range(n):
    tar = a[temp]
    if (tar >= n):
        del a[i]
        del idList[i]

    else:
        temp += 1

com = list(itertools.combinations(idList, 2))

num = len(com)
ans = 0
for i in range(num):
    aa = com[i]
    # print(aa)
    idA = aa[0]
    idB = aa[1]
    dif = abs(idA - idB)
    height = a[idA - 1] + a[idB - 1]

    if (height == dif):
        ans += 1

print(ans)

Submission status: Runtime Error

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

pear = 0

for i in range(N, 1, -1):
  for j in range(i):
    if int(A[i]) >= (i - j):
      break
    if (i - j) == (int(A[i]) + int(A[j])):
      pear += 1
      
print(pear)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
R = np.array(range(N)).reshape(1,N)

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

mat1 = R-R.reshape(N,1)

mat2 = A+A.reshape(N,1)

s = np.count_nonzero(mat1==mat2)

print(s)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])

arr = []
count = 0
for a in A:
    arr.append(A + a)

for i, lis in enumerate(arr):
    count += N - np.count_nonzero(lis - range(N) - np.array([-i] * N))

print(count)

Submission status: Runtime Error

Solution code:
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    l = [0]*(10**6)
    used = []
    for i in range(n):
        if 0<=i+1-a[i]<n:
            l[i+1-a[i]] += 1
            used.append(i+1-a[i])
    cnt = 0
    for i in range(n):
        if 0<=i+1-a[i]<n:
            l[used[cnt]] -= 1
            cnt += 1
        b = i+1+a[i]
        res += l[b]
    print(res)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

count = 0

def dfs(x, y):
    global count
    if x >= N or y >= N:
        return
    diff = abs(x - y)
    if (A[x]+A[y]) == diff:
        count += 1
    
    if y+1 >= N:
        dfs(x+1, x+2)
    dfs(x, y+1)


dfs(0, 1)
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
h = list(map(int,input().split()))
table={}
count = 0
for i in range(n):
  table[i+h[i]] = True
  if table[i-h[i]] == True:
    count+=1
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
l = [0]*(2*10**5+10)
for i in range(1,len(A)):
  x = i-A[i]
  if x<0:
    continue
  else:
    l[x]+=1

ans+=l[A[0]]
for i in range(1,N):
  x = i+A[i]
  if x<0:
    continue
  if x>2*10**5:
    continue
  
  l[i-A[i]]-=1
  ans+=l[x]
  
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
cnt=0
for i in range(n-1):
    if a[i] > 2*(10**5):
        continue
    for j in range(i+2,n):
        if a[j] > 2*(10**5):
        continue
        if j-i == a[i]+a[j]:
            cnt += 1
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect

N = int(input())

border = N * 2

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

b = [A[0] + 1]

C = [0] * (border + 1)

ans = 0

for i, a in enumerate(A, 1):
    ans += C[i - a]
    if i + a <= border:
        C[i + a] += 1
    #br = bisect.bisect_right(b, i - a)
    #bl = bisect.bisect_left(b, i - a)
    #ans += br - bl
    #b.index(bl, i + a)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
h = list(map(int,input().split()))
table={}
count = 0
for i in range(n):
  table[i+h[i]] = True
  if table[i-h[i]] == True:
    count+=1

Submission status: Runtime Error

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


def solve(N,A):
    ans = 0
    lis = [0]*(2*10**5)
    for i,a in enumerate(A):
        lis[-a-i]+=1
    for i,a in enumerate(A):
        ans += lis[a-i]
    return ans
print(solve(N,A))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations as com
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i, j in com(a, 2):
    if abs(i-j) == a[i-1]+a[j-1]:
        cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
R = np.array(list(range(N)))

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

mat1 = R-R.reshape(N,1)

mat2 = A+A.reshape(N,1)

s = np.count_nonzero(mat1==mat2)

print(s)

Submission status: Runtime Error

Solution code:
N = int(input())
A_list = [int(input().split()) for i in range(N)]
x = 0

for i in range(1, N+1):
  p = i + A_list[i]
  for j in range(i+1, N-i-1):
    if j - A_list[j] == p:
      x = x + 1
print(x)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations as com
n = int(input())
a = [-1]+list(map(int, input().split()))
cnt = 0
for i, j in com(a, 2):
    if abs(i-j) == a[i]+a[j]:
        cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
#include <cstdio>
#include <map>
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN];
int main() {
    int n;
    scanf("%d", &n);// don't forget &
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);// don't forget &
    }
    map<int, int> mmp;
    for (int i = 2; i <= n; i++) {
        a[i] -= i - 1;
        mmp[a[i]]++;
    }
    long long ans = 0;
    for (int i = 1; i < n; i++) {
        int x = a[i] + i - 1;
        int y = 1 - i - x;
        ans += mmp[y];
        if (i != 1) {
            mmp[a[i]]--;
        }
    }
    printf("%lld", ans);
    return 0;
}

Submission status: Runtime Error

Solution code:
import bisect as bi
import collections as cc
I=lambda:list(map(int,input().split()))
f=cc.defaultdict(int)
n,=I()
l=I()
ans=0
for i in range(n):
    d[l[i]+i]+=1
    ans+=d[i-l[i]]
print(ans)

Submission status: Runtime Error

Solution code:

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
lmii = lambda: list(map(int, input().split()))
lmsi = lambda: list(map(str, input().split()))
smii = lambda: sorted(map(int, input().split()))


# ----------

N = ii()
A = lmii()

bd = defaultdict(int)
ac = defaultdict(int)
for i in range(N):
    a = b = i + 1
    c = d = A[i]
    bd[b-d] += 1
    ac[a+c] += 1

ans = 0
for k, v in bd.items():
    ans += v * ac[k]

print(ans)

Submission status: Runtime Error

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

L = [0]*max(S)
for i in range(N):
    if (S[i]-1>=0)and(len(L)-1>=S[i]-1):
        L[S[i]-1]+=1

out = 0
for i in range(N):
    if (T[i]-1>=0)and(len(L)-1>=T[i]-1):
        out += L[T[i]-1]
        if T[i]==S[i]:
            out += -1
print(out)

Submission status: Runtime Error

Solution code:
N = int(input())
A_ = list(map(int, input().split()))
A = list()
for i in range(len(A_)):
    if A_[i] < N - 1:
        A.append([i + 1, A_[i]])
ret = 0
for i in range(len(A)-1, -1, -1):
    ind, val = A[i][0], A[i][1]
    B = [a for a in A if a[1] < N - 1 - val]
    for b in B:
        if abs(b[0] - ind) == val + b[1]:
            ret += 1
return ret

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    l = [0]*(10**6)
    used = []
    for i in range(n):
        if a[i] >= n:
            continue
        l[i+1-a[i]] += 1
        used.append(i+1-a[i])
    for i in range(n):
        if a[i] >= n:
            continue
        l[used[i]] -= 1
        b = i+1+a[i]
        res += l[b]
    print(res)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n):
    b[i]= i-a[0]-a[i]
d = defaultdict(int)
for i in range(1,n):
    d[b[i]] += 1
ans = 0
x = 0
for i in range(n-1):
    ans+=d[x]
    d[b[i+1]]-=1
    x -= -1+(a[i]-a[i+1])
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
R = np.array(list(range(N)))-1

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

mat1 = np.abs(R-R.reshape(N,1))

mat2 = A+A.reshape(N,1)

s = int(np.count_nonzero(mat1==mat2)/2)

print(s)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(input().split(), np.float32)
B = np.arange(1, N + 1)
X = A[None, :] + A[:, None]
Y = np.abs(B[None, :] - B[:, None])
print(np.count_nonzero(X == Y) // 2)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;
#define sd(x) scanf("%d",&x);
#define sdl(x) scanf("%lld",&x);
#define pr(x) printf("%d\n",x);
#define prl(x) printf("%lld\n",x);


   long long int gcd(long long int a,long long int b)
{
    if (b<a)return gcd(b,a);
    else if (b%a==0)return a;
    else return gcd(b%a,a);
 
}

long long fast_exp(long long a,long long n,long long mod1)
    {

    if (n==0)return 1;
    else if (n==1)return a;
    if (n%2==0)return fast_exp((a*a)%mod1,n/2,mod1);
    else return (a*fast_exp((a*a)%mod1,n/2,mod1))%mod1;
    }
bool is_square(long long  a)
{
    long long int b=sqrt(a);
    if (b*b==a)return true;
    else return false;
}


void solve()
{
   int n;
   cin >> n;
   vector<int>arr(n);
   unordered_map<int,int>maps;
   for (int c=0;c<n;c++)
    cin >> arr[c],maps[c+1-arr[c]]++;

    long long total=0;
    for (int c=0;c<n;c++)
        total+=maps[arr[c]+c+1]-((c+1-arr[c])==(arr[c]+c+1)?1:0);
    cout << total << endl;
    
}



int main ()
{
      
     int t;
     //cin >> t;
     t=1;
     for (int tt=1;tt<=t;tt++)
     {
         solve();

     }

    return 0;
     
     
     
     
 }

Submission status: Runtime Error

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

L = [0]*max(S)
for i in range(N):
    L[S[i]-1]+=1

out = 0
for i in range(N):
    if (T[i]-1>=0)and(len(L)-1>=T[i]-1):
        out += L[T[i]-1]
        if T[i]==S[i]:
            out += -1
print(out)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array(input().split(), np.int64)
B = np.arange(1, N + 1)
X = A[None,:] + A[:,None]
Y = B[None,:] - B[:,None]
print(np.count_nonzero(X == Y))

Submission status: Runtime Error

Solution code:
import numpy as np

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

ans = 0
for i in range(N):
    tmp_A = A + A[i]
    tmp_B = np.concatenate([np.zeros(i),np.arange(N-i)])
    C = tmp_B - tmp_A
    ans += np.count_nonzero(C == 0)

print(ans)

Submission status: Runtime Error

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

po = [0 for i in range(2*(10**5)+1)]
if n-1-a[0] >= 0:
    po[n-1-a[0]] = 1
ans = 0
for i in range(1,n):
    ppo = n-1-i + a[i]
    
    if ppo >= 0:
        ans += po[ppo]
    if n-i-1 - a[i] >= 0:
        po[n-i-1 - a[i]] += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
t1 = []
t2 = []
for i in range(n):
    t1.append(l[i] + i)
    t2.append(i - l[i])
# print(t1, t2)
count = [0] * (2 * 100005)
for i in t1: count[i] -= -1
ans = 0
for i in t2:
    if i > 0:
        if count[i] != 0:
            ans += count[i]
print(ans)

Submission status: Runtime Error

Solution code:
                                                                               │➜  typical
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

def main():
  N = int(input())

  height = [i for i in list(map(int, input().split()))]

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

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    l = [0]*(10**6)
    used = []
    for i in range(n):
        l[i+1-a[i]] += 1
        used.append(i+1-a[i])
    for i in range(n):
        l[used[i]] -= 1
        b = i+1+a[i]
        res += l[b]
    print(res)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
l=[0 for i in range(2*n)]
r=[0 for i in range(2*n)]
c=1
a=0
if n!=0:
  k=[int(i) for i in input().split()]
for i in range(n):
  l[abs(c-k[i])]+=1
  r[c+k[i]]+=1
  c+=1
for i in range(2*n):
  a+=l[i]*r[i]
print(a)

Submission status: Runtime Error

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import copy

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

cnt = 0
for i,a in enumerate(A):
  del B[i]
  for j,b in enumerate(B):
    if abs(i-(j+i+1)) == A[i]+B[j]:
        cnt += 1
print(cnt)

Submission status: Runtime Error

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

L = [0]*max(S)
for i in range(N):
    L[S[i]-1]+=1

out = 0
for i in range(N):
    if T[i]>0:
        out += L[T[i]-1]
        if T[i]==S[i]:
            out += -1
print(out)

Submission status: Runtime Error

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

L=[0]*(10**6)
for i in range(N):
    if i-A[i]>=0:
        L[i-A[i]]+=1
ans=0
for i in range(N):
    tall=A[i]
    ans+=L[tall+i]
print(ans)
#print(L[:10])

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=[]
ans=0
for i in range(n):
  print(l)
  l=list(map(lambda x: x+1,l))
  ans+=l.count(a[i])
  l.append(-a[i])
print(ans)

Submission status: Runtime Error

Solution code:
x = int(input())
def ans(x):
    for a in range(0, 1000)[::-1]:
        for b in range(-1000, 1000)[::-1]:
            if a**5 - b**5 == x:
                return a, b
a,b = ans(x)
print(a,b)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

CNT = [0] * (10 ** 6)

ans = 0
for i in range(N):
    a = A[i]
    p = i - a

    if p > 0:
        ans += CNT[p]

    CNT[i + a] += 1

print(ans)