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

N = int(input())
A = np.array([int(i) for i in input().split()])
A = A[A<=2*(10**5)]

H = [0]*(5*(10**5))
L = [0]*(5*(10**5))

for i in range(N):
    H[A[i]+i] += 1
    if i-A[i] >= 0:
        L[i-A[i]] += 1

ans = 0

for i in range(N):
    ans += H[i]*L[i]

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
A = A[A<=2*(10**5)]

H = [0]*(4*(10**5))
L = [0]*(4*(10**5))

for i in range(N):
    H[A[i]+i] += 1
    if i-A[i] >= 0:
        L[i-A[i]] += 1

ans = 0

for i in range(N):
    ans += H[i]*L[i]

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
A = A[A<=2*(10**5)]

H = [0]*(3*(10**5))
L = [0]*(3*(10**5))

for i in range(N):
    H[A[i]+i] += 1
    if i-A[i] >= 0:
        L[i-A[i]] += 1

ans = 0

for i in range(N):
    ans += H[i]*L[i]

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=[0]*(10**10)
res=0

for i in range(n):
	B[A[i]+i]+=1
for i in range(n):
	if i-A[i]>0:
		res+=B[i-A[i]]

print(res)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
input = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = [i+A[i] for i in range(N)]
Adif = [i-A[i] for i in range(N)]

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

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
s=0
L=[i for i in range(N)]
A=list(map(int,input().split()))
dic1={i:i+a for i,a in zip(L,A)}
dic2={i:i-a for i,a in zip(L,A)}
for p in range(N)
    z=[k for k,v in dic1.items() if v==p ]
    w=[k for k,v in dic2.items() if v==p ]
    for i,j in zip(z,w):
        if j>i:
            s+=1
print(s)

Submission status: Runtime Error

Solution code:
N=int(input())
s=0
L=[i for i in range(N)]
A=list(map(int,input().split()))
dic1={i:i+a for i,a in zip(L,A)}
dic2={i:i-a for i,a in zip(L,A)}
for p in range(N)
    z=[k for k,v in dic1.items() if v==p ]
    w=[k for k,v in dic2.items() if v==p ]
    for i,j in zip(z,w)
        if j>i:
            s+=1
print(s)

Submission status: Runtime Error

Solution code:
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])
from collections import Counter
zisyo=R.Counter(R)
ans=0
for i in L:
  ans=ans+get(i,0)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
plus_lis = [A[i] + i for i in range(N)]
minus_lis = [k - A[k] for k in range(N)]
plus_lis.sort()
minus_lis.sort()

ans_lis = [0] * 10 ** 6
for x in plus_lis:
    if x < 10 ** 6:
        ans_lis[x-1] += 1
for y in minus_lis:
    if y > 0:
        ans += ans_lis[x-1]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections

input()
p = list(map(int, input().split()))
map1 = collections.defualtdict(lambda:0)
map2 = collections.defaultdict(lambda:0)

for i, v in enumerate(p):
  map1[i+v] += 1
  map2[i-v] += 1

ans = 0
for i in map1:
  if i in map2:
    ans += map2[i]
print(i)

Submission status: Runtime Error

Solution code:
n = int(input())
L, R = [0] * n, [0] * n
i = 0
for ipt in input().split():
    L[i] = i + ipt 
    R[i] = i - ipt
    i += 1
def make_dic(L):
    L_set = set(L)
    return dict([(i, L.count(i)) for i in L_set])
L_dic, R_dic = make_dic(L), make_dic(R)
cnt = 0
for Lk, Lv in L_dic.items():
    try:
        cnt += R_dic[Lk] * Lv
    except KeyError:
        pass
print(cnt)

Submission status: Runtime Error

Solution code:
from collections import Counter

N,*A = map(int,open(0).read().split())
#j - i = Aj + Ai
#j - Aj = Ai + i
#L = i + Ai, R = j - Aj とおく
L = []
R = []
for i in range(N):
    L.append(i+1 + A[i])
    R.append(i+1 - A[i])
l = Counter(L)
r = Counter(R)
 
cnt = 0
for i in range(1,N+1):
    if i in l and i in r:
        cnt += l[i] * r[i]
        a.append(i)
print(cnt)

Submission status: Runtime Error

Solution code:
    from collections import Counter
    N = int(input())
    A = list(map(int, input().split()))

    Y = [int(i + A[i - 1]) for i in range(1, N + 1)]
    Y = Counter(Y)

    cnt = 0
    for i in range(1, N+1):
        X = i - A[i - 1]
        if X in Y.keys():
            cnt += Y[X]
    print(cnt)

Submission status: Runtime Error

Solution code:
def main():
 n,*a=map(int,open(0).read().split());d,s=[0]*n,0
 for i,x in enumerate(a):
  if i+x<n:d[i+x]+=1
  s+=d[i-x]
 print(s)
main()

Submission status: Runtime Error

Solution code:
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define ld long double
#define int long long
#define mp make_pair

mt19937 rnd(51);

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, ans = 0;
	cin >> n;
	vector<int> v(n);
	map<int,int> mp;
	for (int i = 0; i < n; i++){
        cin >> v[i];
        mp[v[i] - (i + 1)]++;
	}
	for (int i = 0; i < n; i++){
        ans += mp[-(v[i] + i + 1)];
	}
	cout << ans;
	return 0;
}

Submission status: Runtime Error

Solution code:
def main():
 n,a=map(int,open(0).read().split());d,s=[0]*n,0
 for i,x in enumerate(a):
  if i+x<n:d[i+x]+=1
  if i-x>=0:s+=d[i-x]
 print(s)
main()

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
input = sys.stdin.readline


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
d = [i for i in range(N)]
D = np.array([d for i in range(N)])
E = np.array([[i] * N for i in range(N)])

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

Submission status: Runtime Error

Solution code:
def main():
 n,a,d = int(input()),list(map(int, input().split())),[0]*n
 for i,x in enumerate(a):
  if i+x < n: d[i+x] += 1
 print(sum([d[i-x] for i,x in enumerate(a) if i-x>=0]))
main()

Submission status: Runtime Error

Solution code:
num_participants = int(input(' '))

heights = [int(h) for h in input().split(' ')]

num_valid_pairs = 0

diff_in_idx = num_participants - 1
min_sum_of_height = 2 * min(heights)

"""
j - i = Ai + Aj
i + Ai = j - Aj
if i + Ai = X ,then j - Aj = X
"""

while (diff_in_idx >= min_sum_of_height):
  for i in range(num_participants - diff_in_idx):
  	j = i + diff_in_idx
    if (i + heights[i]) == (j - heights[j]): 
      num_valid_pairs += 1
  diff_in_idx -= 1
      
print(num_valid_pairs)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = [0 for i in range(int(2*1e5+1))]
ans = 0

for i, x in enumerate(A, 1):
    ans += cnt[max(0,i - x +1)]
    cnt[x + i + 1] += 1

print(ans)

Submission status: Runtime Error

Solution code:
import itertools

input_line = int(input())

input_list = input().split()
combination_list = []
for i in range(input_line):
  input_list[i] = int(input_list[i])

for i in itertools.combinations(input_list,2):
    combination_list.append(i)

combination_num = list(itertools.combinations(range(1,33),2))
count = 0
for i in range(len(combination_list)):
    if(sum(combination_list[i]) == abs (combination_num[i][0]- combination_num[i][1])):
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())

A = [int(i) for i in input().split()]

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

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input()) #1行目のNを取得する
S = list(range(1,N+1))
A = [input() for i in range(1,N+1)] #複数行の数値の入力を取得
K = 0
dict(zip(S,A))
for i in range(1,N+1):
  for m in range(1,N+1):
    if abs(i-m) = S[i]+A[m]:
      K = K + 1
      
print((K-N)/2)

Submission status: Runtime Error

Solution code:
N = int(input()) #1行目のNを取得する
S = list(range(1,N+1))
A = [input() for i in range(N+1)] #複数行の数値の入力を取得
K = 0
dict(zip(S,A))
for i in range(1,N+1):
  for m in range(1,N+1):
    if abs(i-m) == S[i]+A[m]:
      K = K + 1
      
print((K-N)/2)

Submission status: Runtime Error

Solution code:
N = int(input()) #1行目のNを取得する
S = list(range(1,N+1))
A = [input() for i in range(N+1)] #複数行の数値の入力を取得
K = 0
dict(zip(S,A))
for i in range(1,N+1):
  for m in range(1,N+1):
    if abs(i-m) = S[i]+A[m]:
      K = K + 1
      
print((K-N)/2)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*100000000
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  if 1+i+a[i]<N:
    num[1+i+a[i]]+=1
for i in range(N):
  count+=num[s[i]]
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
L = [i+x for i, x in enumerate(A)]
R = [i-x for i, x in enumerate(A) if i-x > 0]

P = collections.Counter(L)
Q = collections.Counter(R)
 
ans = 0
for k, v in P.item():
    if k in Q:
        ans += v*Q[k]
print(ans)

Submission status: Runtime Error

Solution code:
n, *A = map(int, open(0).read().split())
ans = 0
for i, a in enumerate(A, 1):
    x, y = i+a, i-a
    d[x] = d.get(x, 0)+1
    ans += d.get(y, 0)
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*100000000
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i+a[i]]+=1
for i in range(N):
  count+=num[s[i]]
print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*100000000
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+(maxi+N)]+=1
for i in range(N):
  count+=num[w[i]+(maxi+N)]
print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*100000000
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+(maxi-mini+N+N)//2]+=1
for i in range(N):
  count+=num[w[i]+(maxi-mini+N+N)//2]
print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*(maxi-mini+N+N)
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+(maxi-mini+N+N)//2]+=1
for i in range(N):
  count+=num[w[i]+(maxi-mini+N+N)//2]
print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*(maxi-mini+N+N)
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+(maxi-mini+N+N)//2]+=1
for i in range(N):
  count+=num[w[i](maxi-mini+N+N)//2]
print(count)

Submission status: Runtime Error

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

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*100000000
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]]+=1
for i in range(N):
  count+=num[w[i]]
print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*100000000
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+maxi//2]+=1
for i in range(N):
  count+=num[w[i]+maxi//2]
print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*100000000
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+maxi/2]+=1
for i in range(N):
  count+=num[w[i]+maxi/2]
print(count)

Submission status: Runtime Error

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

Solution code:
from collections import Counter

def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = 0
    l1 = []
    for ea in a:
        l1.append(cnt - ea)
        cnt += 1
    l1c = Counter(l1)
    r = 0
    for ea2 in a:
        r += l1c[ea2 + a[ea2]]
    print(int(r))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*150000000
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+maxi]+=1
for i in range(N):
  count+=num[w[i]+maxi]
print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
maxi=max(a)
mini=min(a)
num=[0]*200000000
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+maxi]+=1
for i in range(N):
  count+=num[w[i]+maxi]
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(inputs[0])
*A, = (map(int, inputs[1].split()))
B = Counter([a+i for i, a in enumerate(A, 1)])
C = Counter([i-a for i, a in enumerate(A, 1)])
ans = 0
for k, v in B.items():
    if k in C:
        ans += C[k]*v
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

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

l = collections.Counter(L)
r = collections.Counter(R)

for i in l.keys():
    ans += l[i]*r[i]

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*100000000
maxi=max(a)
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+maxi]+=1
for i in range(N):
  count+=num[w[i]+maxi]
print(count)

Submission status: Runtime Error

Solution code:
import collections
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 collections

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

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

l = collections.Counter(L)
r = collections.Counter(L)

for i in l.keys():
    ans += l[i]*r[i]

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*100000000

for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+max(a)]+=1
for i in range(N):
  count+=num[w[i]+max(a)]
print(count)

Submission status: Runtime Error

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))).average(axis = 1)

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

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*100000000

for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+50000000]+=1
for i in range(N):
  count+=num[w[i]+50000000]
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
L = [0] * 2 * N
R = [0] * 2 * N
for i in range(N):
    l = i + A[i]
    if l < N: L[l] += 1
    r = i - A[i]
    R[r] += 1
ans = 0 
for i in range(N):
    ans += L[i] * R[i]
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*100000000

for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]+50000000]+=1
for i in range(N):
  count+=num[w[i]]
print(count)

Submission status: Runtime Error

Solution code:
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))).sum(axis = 1)

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(list(map(int,input().split())))
ma=max(a)
l,r=[0]*(ma+n+1),[0]*(ma+n+1)
for i,a in enumerate(a):
    l[i+a]+=1
    if i-a<0:
        continue
    else:
        r[i-a]+=1
ans=0
for a,b in zip(l,r):
    ans+=a*b
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
L = [0] * 2 * N
R = [0] * 2 * N
for i in range(N):
    l = i + A[i]
    L[l] += 1
    r = i - A[i]
    R[r] += 1
ans = 0 
for i in range(N):
    ans += L[i] * R[i]
print(ans)

Submission status: Runtime Error

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

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


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


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


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


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


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

    from collections import defaultdict
    l = defaultdict(0)
    r = defaultdict(0)
    for i, h in enumerate(a):
        no = i + 1
        l[no + h] += 1
        r[no - h] += 1

    ret = 0
    for i in range(1, n + 1):
        ret += (l.get(i, 0) * r.get(i, 0))

    return ret


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

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A = A.reshape(-1, 1)
B = A + A.T - np.arange(1, N+1) + np.arange(1, N+1).reshape(-1, 1)
print(np.sum(B == 0))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
X=[]
for i in range(1,N+1):
  X.append(i+A[i-1])
for j in range(1,N+1):
  X.append(i-A[i-1])
Y=set(X)
Z=list(Y)
print(len[Z])

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
X=[]
for i in range(1,N):
  X.append(i+A[i-1])
for j in range(1,N):
  X.append(i-A[i-1])
Y=set(X)
Z=list(Y)
print(len[Z])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=input()
l=list(map(int,input().split()))
x=0
d=max(l)-min(l)
for i in range(len(l)):
  for j in range(i+1,i+d):
    s=l[i]+l[j]
    t=i-j
    if s+t==0:
      x+=1
    if s-t==0:
      x+=1
print(x)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
enu = enumerate
def input(): return sys.stdin.readline()[:-1]

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

cnt = 0
d = defaultdict(int)
for i, a in enu(A):
    l = (i+1) + a
    r = (i+1) - a
    cnt += d[r]
    d[l] += 1

print(cnt)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*100000000

for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]]+=1
for i in range(N):
  count+=num[w[i]]
print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*(1+N+max(a)+1)

for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]]+=1
for i in range(N):
  count+=num[w[i]]
print(count)

Submission status: Runtime Error

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

def numberofpairs(k):#1からkまでの中のペア数を返す
    if k==2:
        return 0
    else:
        newpair = 0
        if height[k-1] < k:
            for x in range(1,k):
                if height[k-1] + height[k-x-1] == x:
                    #print(height[k-1],height[k-x-1],k,x)
                    newpair += 1
        num = numberofpairs(k-1) + newpair
        return num

print(numberofpairs(n))

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*(1+N+max(a))

for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]]+=1
for i in range(N):
  count+=num[w[i]]
print(count)

Submission status: Runtime Error

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

def numberofpairs(k):#1からkまでの中のペア数を返す
    if k==2:
        return 0
    else:
        newpair = 0
        if height[k-1] < k:
            for x in range(1,k):
                if height[k-1] + height[k-x-1] == x:
                    print(height[k-1],height[k-x-1],k,x)
                    newpair += 1
        num = numberofpairs(k-1) + newpair
        return num

print(numberofpairs(n))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*10000000

for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]]+=1
for i in range(N):
  count+=num[w[i]]
print(count)

Submission status: Runtime Error

Solution code:
A = list(map(int,input().split()))
ans = 0
r = [[] for i in range(5*(10**3))]
for i in range(N):
    p = A[i]//(2*(10**5))
    r[p].append([i,A[i]])


def s(p,q,ans):
    t = p+q
    for k in range(len(t)-1):
        for l in range(k+1,len(t)):
            if abs(t[k][0]-t[l][0]) == t[k][1] + t[l][1]:
                ans += 1
    return ans

for i in range(len(r)-1):
    ans = s(r[i],r[i+1],ans)
print(ans)

Submission status: Runtime Error

Solution code:
X = int(input())

B = [i for i in range(-10000,10001)]

ans = []

for b in B:
    a = (X+(b**5))**(1/5)
    if type(a) == float or type(a) == int:
        if a.is_integer():
            ans.append(a)
            ans.append(b)
            break;

for i in range(2):
    ans[i] = int(ans[i])
    ans[i] = str(ans[i])

print('\t'.join(ans))

Submission status: Runtime Error

Solution code:
import math
import itertools
N = map(int,input().split())
H = list(map(int,input().split()))
cnt = 0
def comb(arr, len, n, r):
  global cnt

  if r - n == math.fabs(arr[r] + arr[n]):
    cnt+=1
  if len > r:
    comb(arr, len, n, r+1)

leng = len(H) - 1
for i in range(leng):
  comb(H, leng, i, i+1)

print(cnt)

Submission status: Runtime Error

Solution code:
import itertools

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

for i in range(N):
  A[i] = [i, A[i]]

for i in range(N):
  if A[i][1] > 2 * 10**5:
    del A[i]

if len(A) < 2:
  print(0)
  continue
  
for p in itertools.combinations(A, 2):
  if abs(p[0][0]-p[1][0]) == p[0][1]+p[1][1]:
    cnt += 1

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools

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

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

for i,j in list_:
  if A[i] + A[j] == max(i - j, j - i):
    ans += 1;
  
print(ans)

Submission status: Runtime Error

Solution code:
import itertools

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

for i in range(N):
  A[i] = [i, A[i]]

for i in range(N):
  if A[i][1] > 2 * 10**5:
    del A[i]
    
if len(A) < 2:
  print(0)
  continue
  
for p in itertools.combinations(A, 2):
  if abs(p[0][0]-p[1][0]) == p[0][1]+p[1][1]:
    cnt += 1

print(int(cnt))

Submission status: Runtime Error

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

height0=[]
number0=[]

minh=min(h)

for i in range(0,n):
  if (h[i] < n-minh):
    height0.append(h[i])
    number0.append(i)

ans=0
for i in number0:
  for j in number0:
    if (abs(i-j) == (height0[i-1]+height0[j-1])):
      ans=ans+1

print (ans)

Submission status: Runtime Error

Solution code:
import numpy as np

n=int(input())
a=list(map(int,input().split()))
z=0
for i in range(n-1):
    if n-1-i>a[i]:
        x=np.array([i+1-a.pop(0) for i in range(n-1-i)])
        y=np.array(a)-x
        z+=y.count(0)
print(z)

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*(1+N+max(a))

for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i+a[i]]+=1
for i in range(N):
  count+=num[w[i]]
print(count)

Submission status: Runtime Error

Solution code:
n,a,b,c = [int(j) for j in input().split()]
l = []
for i in range(n):
	s = input()
	l.append(s)
d = {"A":[0]*n, "B":[0]*n, "C":[0]*n}
# for j in l[-1]:
	# d[j].append(1)
for i in range(n-1, -1, -1):
	for j in l[i]:
		d[j][i] = 1
for i in range(n-2, -1, -1):
	for j in ["A", "B", "C"]:
		d[j][i]+=d[j][i+1]
ct = {"A":a, "B":b, "C":c}
ans = []
flag = True
# print(ct, d)
for i in range(n):
	# print(ct)
	if flag==False:
		break
	tmp = min([(ct[j]-d[j][i], ct[j]) for j in l[i]])
	# print(tmp, "tmp")

	tflag = True
	for j in l[i]:
		if (ct[j]-d[j][i], ct[j]) == tmp and tflag:
			ans.append(j)
			tflag = False
			ct[j]+=1
		else:
			# print(ct[j], j)
			ct[j]-=1
			if ct[j]<0:
				flag = False
				print("No")
				break

else:
	if flag:
		print("Yes")
		for i in ans:
			print(i)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = A[0::2]
C = A[1::2]
l = len(A)
a = []
b = []
a = [[i,j] for i in range(l) for j in range(i+1,l) if (j - i)==B[i]+B[j]]
b = [[i,j] for i in range(l) for j in range(i+1,l) if (j - i)==C[i]+C[j]]
print(len(a) + len(b))