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 <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  ll N;
  cin >> N;
  vll A(N);
  rep(i, N) {
    cin >> A[i];
  }
  
  unordered_map<ll, vi> v;
  rep(i, N) {
    A[i] -= i;
    if(v.find(A[i]) == v.end()) {
      v.emplace(A[i], vi());
    }
    v[A[i]].push_back(i);
  }
  
  ll ct = 0;
  rep(i, N) {
    if(v.find(-A[i] - i) != v.end()) {
      vi::iterator itr = upper_bound(v[-A[i] - i].begin(), v[-A[i] - i].end(), i);
      auto aaa = (itr - v[-A[i] - i].begin()) - 1;
      ct +=aaa;
    }
  }
  
  fin(ct);
}

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
su = dict()
sd = dict()
for i in range(n):
    if a[i] + i + 1 in su:
        su[a[i] + i + 1] += 1
    else:
        su[a[i] + i + 1] = 1
    if a[i] - i - 1 in sd:
        sd[a[i] - i - 1] += 1
    else:
        sd[a[i] - i - 1] = 1
f1 = []
for d in su:
    f1.append(d, su[d])
f1.sort()
f = []
for d in sd:
    f.append(d, su[d])
f.sort()
s = 0
i1 = n-1
j1 = 0
while (i1 > 0 and j1 < n-1):
    if (su[i1] + sd[j1] == 0):
                s+=1
                i1-=1
    elif (su[i1] + sd[j1] > 0):
                i1-=1

    elif (su[i1] + sd[j1] < 0):
                j1+=1
print(s)

Submission status: Runtime Error

Solution code:
ef main():
    from collections import Counter
    n = int(input())
    As = list(map(int,input().split(" ")))
    
    cnts = Counter()
    dp = [0]*n
    for i in range(1,n):
        dp[i] =dp[i-1] + cnts.get(i-As[i],0)
        cnts[As[i]+i]+=1
    print(dp[n-1])
main()

Submission status: Runtime Error

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
n = int(input())
As = list(map(int, input().split()))
# Ps = [0] * n
Ss = [0] * n
Ds = [0] * n
for i in range(n):
    # Ps[i] = [i + 1, As[i]]  # 番号、身長
    Ss[i] = i+1+As[i]
    Ds[i] = i+1-As[i]

# Ss = sorted(Ps, key=lambda x: x[0] + x[1])
# Ds = sorted(Ps, key=lambda x: x[0] - x[1])
Ss.sort()
Ds.sort()


def calc(s, l, r):
    m = (l+r) // 2
    if (l == m and Ds[m] != s):
        return(-1)  # 不存在
    if (Ds[m] > s):
        r = m
        calc(s, l, r)
    elif (Ds[m] < s):
        l = m
        calc(s, l, r)
    elif (Ds[m] == s):
        return (m)  # 存在


def calcStart(s, l, r):
    m = (l + r) // 2
    if (Ds[m] < s and Ds[m + 1] == s):
        return m
    elif (Ds[m] == s):
        calcStart(s, l, m)
    elif (Ds[m] < s and Ds[m + 1] < s):
        calcStart(s, m, r)


def calcGoal(s, l, r):
    m = (l + r) // 2
    if (Ds[m] > s and Ds[m - 1] == s):
        return m
    elif (Ds[m] == s):
        calcGoal(s, l, m)
    elif (Ds[m] > s and Ds[m - 1] > s):
        calcGoal(s, m, r)


ans = 0
for s in Ss:
    l = 0
    r = n - 1
    temp = calc(s, l, r)
    if(temp != -1):
        calcStart(s, 0, temp)
        calcGoal(s, 0, temp)
        ans += calcGoal - calcStart

print(ans)

Submission status: Runtime Error

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

for i in range(1,n,1):
	for j in range(min(n,i+a[i+1]), n, 1):
		if a[i-1] + a[j-1] == j-i:
			ans += 1

print(ans)

Submission status: Runtime Error

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

count = 0
for a in range(1, n + 1):
    for b in range(a + 1, n + 1):
        print(a, b)
	if abs(a - b) =	alist[a-1] + alist[b-1]:
            count += 1
print(count)

Submission status: Runtime Error

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

import itertools
high = list(map(lambda x: x[0]+x[1] ,list(itertools.combinations(a, 2))) - map(lambda x: abs(x[0]-x[1]) ,list(itertools.combinations(range(1,n+1), 2))))
import collections
c = collections.Counter(high)

print(c[0])

Submission status: Runtime Error

Solution code:
N = int(input())
arr = map(int,input().split())
_sum = []
_del = []
for i in range(N):
  _sum.append(arr[i]+i+1)
  _del.append(i+1-arr[i])

Submission status: Runtime Error

Solution code:
import numpy as np

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

counts = 0

for i in range(N):
    for j in range(i):
        if talls[i]+talls[j] == abs(i-j):

            counts += 1

print(counts)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=[]
B=[]
ans=0
for i in range(1,N):
    b=A[i]+A[0]
    a.append(b-i)
    B.append(A[i]-A[0])
ans=a.counter(0)
for i in range(N):
    b=B[i]
    a1=a[i:].copy()
    a1=a1-[b-i-1]
    ans+=a1.counter(0)
print(ans)

Submission status: Runtime Error

Solution code:
num = int(input())
height_list = [0]  # 1始まりで合わせるため
height_list.extend(list(map(int, input().split())))
num_list = list(range(1, num+1))
hiki_list = num_list - height_list
tasi_list = num_list + height_list

counta = 0
for i in hiki_list:
    counta += tasi_list.count(i)

print(counta)

Submission status: Runtime Error

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

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

print(res)

Submission status: Runtime Error

Solution code:
import numpy as np

# coding: utf-8
# Your code here!
#N, K = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)

count = 0

for d in range(1,N):
    #print(d)
    buf = A[:-d]+A[d:]
    #print(buf)
    #print(d, len(buf[buf==d]))
    #差がdのペア
    #print(A[:-d]-A[d:])
    count += len(buf[buf==d])
print(count)

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)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	# t = min(ssb)

	cnt = 0

	for i in ipl:
		for j in ssb:
			if i == j:
				cnt += 1
			if i < j:
				break

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
Hs = list(map(int, input().split()))
nHs = np.array(Hs)
h = np.tile(nHs, (N, 1))
co = h - np.array([[abs(n-i)-Hs[n] for i in range(N)] for n in range(N)])
ans = np.sum(co==0)
print(ans//2)

Submission status: Runtime Error

Solution code:
num = int(input())
height_list = [0]  # 1始まりで合わせるため
height_list.extend(list(map(int, input().split())))
num_list = range(1, num+1)
hiki_list = num_list - height_list
tasi_list = num_list + height_list

counta = 0
for i in hiki_list:
    counta += tasi_list.count(i)

print(counta)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a_l = list(map(int,input().split()))
ia = list(enumerate(a_l))
del_l = []
for j in range(n):
    if ia[j][1] >= n-1:
        del_l.append(j)
for j in del_l[::-1]:
    del ia[j]
        
count = 0
i = 0
while True:
    if i > len(ia)-1:
        break
    i1, a1 = ia[i]
    if a1 >= n-1-i1:
        del ia[i]
        continue
    for i2, a2 in ia[i1+a1+1:n]:
        if a2 >= n-1-i1:
            del ia[i2]
            continue
        if (i2-i1) == (a2+a1):
            count += 1
    i += 1

print(count)

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)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)

	cnt = 0

	for i in ipl:
		for j in ssb:
			if i == j:
				cnt += 1
			if i < j:
				break

print(cnt)

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

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()

ans=0
for i in range(n):
    h=a[i]
    B=list(range(-i,-i+n))
    C=[0]*n
    for j in n:
        C[j]=abs(B[j])-A[j]-h
    ans+=C.count(0)
print(ans//2)

Submission status: Runtime Error

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

A=list(map(int,input().split())))
B = [(A[0] + A[i] -i)   for i in range(n)]
b = collections.Counter(B)
ans =0
cnt = 0
for i in range(len(B)):
    
    ans += b[cnt]
    if i != 0:
        cnt += (B[i] - B[i-1] -1)

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)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)

	cnt = 0

	for i in pl:
		for j in ssb:
			if i == j:
				cnt += 1
			if i < j:
				break

print(cnt)

Submission status: Runtime Error

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

for i in range(N):
    A[i] -= (N - 1) - i
# print(A)
# import collections
# dct = dict(collections.Counter(A))
# print(dct)
# m = min(A)
# cnt = 0
# for check in range(m, 0):
#
#     if dct.get(check, 0):
#         print(check)
#         cnt += dct[check] * dct.get(check + 2, 0)
# print(cnt)
remove = 0
# for i in range(N-2):
#     if ori[i] != 1 and ori[i] == ori[i + 2]:
#         remove += 1
for i in range(N - 1):
    if ori[i] + 1 == ori[i + 1]:
        remove += 1
# print(ori)
# print(cnt - remove)

bucket = [0] * N
cnt = 0
for i in range(N):
    if A[i] < 0:
        bucket[-A[i]] += 1
        cnt += bucket[-A[i] + 2]
print(cnt- remove)

Submission status: Runtime Error

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

# A[0]との和 - idxの差の数
box = [0] * (n - 1)

for i in range(n - 1):
  box[A[0] + A[i + 1] - i - 1] += 1 

ans = 0
for a in A:
  ans += sum(i if itr == (A[0] - a) else 0 for itr, i in enumerate(box))

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
Hs = list(map(int, input().split()))
nHs = np.array(Hs)
h = np.tile(nHs, (N, 1))
co = h - np.array([[abs(n-i)-Hs[n] for i in range(N)] for n in range(N)])
ans = N**2-np.count_nonzero(co)
print(ans//2)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
temp=0
for i in range(len(A)):
  if A[i]>N:
    A.pop(i)

new_N=len(A)
l=[i for i in range(new_N)]

temp=0

for i in range(new_N-2):
  if i+A[i]<new_N:
    temp_min=max(i+A[i],i+2)
    for j in range(temp_min,new_N):
      if j-i==A[i]+A[j]:
        temp+=1
print(temp)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = [0]*2*10*9
ans = 0
for i in range(N):
    d[i+1+A[i]] += 1
    
for i in range(1,N+1):
    f = A[-i]+N+1-i-(2*A[-i])
    if f >= 0:
        ans += d[f]
print(ans)

Submission status: Runtime Error

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

for i in range(n-1):
  for h in range(i+1, n):
    if a[i]<n-1 and a[h]<n-1 
      d=h-i
      g=a[i]+a[h]
      if d==g:
        count+=1
print(count)

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 == abs(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:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
n = int(input())
As = list(map(int, input().split()))
# Ps = [0] * n
Ss = [0] * n
Ds = [0] * n
for i in range(n):
    # Ps[i] = [i + 1, As[i]]  # 番号、身長
    Ss[i] = i+1+As[i]
    Ds[i] = i+1-As[i]

# Ss = sorted(Ps, key=lambda x: x[0] + x[1])
# Ds = sorted(Ps, key=lambda x: x[0] - x[1])
Ss.sort()
Ds.sort()

ans = 0
for s in Ss:
    l = 0
    r = n - 1
    temp = calc(s, l, r)
    if(temp != -1):
        calcStart(s, 0, temp)
        calcGoal(s, 0, temp)
        ans += calcGoal - calcStart

print(ans)


def calc(s, l, r):
    m = (l+r)) // 2
    if (l == m and Ds[m] != s):
        return(-1)  # 不存在
    if (Ds[m] > s):
        r=m
        calc(s, l, r)
    elif (Ds[m] < s):
        l=m
        calc(s, l, r)
    elif (Ds[m] == s):
        return (m)  # 存在

def calcStart(s, l, r)  # ターゲットの数値、開始地点、ターゲットの存在する位置
    m=(l + r) // 2
    if (Ds[m] < s and Ds[m + 1] == s):
        return m
    elif (Ds[m] == s):
        calcStart(s, l, m)
    elif (Ds[m] < s and Ds[m + 1] < s):
        calcStart(s, m, r)

def calcGoal(s, l, r)  # ターゲットの数値、開始地点、ターゲットの存在する位置
    m=(l + r) // 2
    if (Ds[m] > s and Ds[m - 1] == s):
        return m
    elif (Ds[m] == s):
        calcGoal(s, l, m)
    elif (Ds[m] > s and Ds[m - 1] > s):
        calcGoal(s, m, r)

Submission status: Runtime Error

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

  if r - n == abs(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:
from functools import lru_cache

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

count = 0

@lru_cache(maxsize=1000)
def dfs(x, y):
    global count
    if x >= N or y >= N:
        return
    
    if (A[x]+A[y]) == y-x:
        count += 1

    if x+1 >= N and y+1 >= N:
        return
        
    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:
import numpy as np
X=int(input())
flag=0

A=[]
for i in range(X):
    A.append(int(input()))

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

print(flag)

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
lst = deque(list(map(int, input().split())))

ans = 0
for k, v in enumerate(lst):
    l = lst.popleft()
    ans += len([_ for _ in lst if _ +  1 == v+1])

Submission status: Runtime Error

Solution code:
tmp = input().split()
N = int(tmp[0])
A = [0]*N
tmp = input().split()
for n in range(N):
    A[n] = int(tmp[n])

c = 0
HE = [[0 for i in range(N)] for j in range(N)]
S = 0

for i in range(N):
    for j in range(N)[i:N+1]:
        S = A[i] + A[j]
        if S < N:
            if S == abs(i-j):
                HE[i][j] = 1


print (sum(HE))

Submission status: Runtime Error

Solution code:
N =int(input())
A = list(map(int,input().rstrip().split(" ")))
Aq = []
DP = [0 for i in range(2 * 10 ** 5)]
DPP = []
ans = 0
for i in range(N):
    if i >= A[i]:
        ans += DP[i - A[i]]
    if A[i] <= N:
        DP[A[i] + i] += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
num=int(input())
stri=input()
height=[]
height.extend(stri.split(" "))
for i in range(len(height)):
	height[i]=int(height[i])
count=0
for i in range(num-1):
	for j in range(i+1, num):
    	if (j-i)==abs(height[i]+height[j]):
        	count+=1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
d={}
def diff(a,b):
    if a>b:
        return(a-b)
    else:
        return(b-a)
for i in range(0,len(l)):
    if l[i]>2*10**5:
        pass
    else:
        d[i+1]=l[i]
l=list(d.keys()):
for i in range(0,len(l)):
    for j in range(i+1,len(l)):
        if diff(i,j)==d[j]+d[i]:
            count+=1
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from itertools import combinations
N = int(input())
arr = list(map(int, input().split(" ")))

d = dict()
for i in range(len(arr)):
    if arr[i] < 2*(10**5):
        d[i] = arr[i]

ret = 0
for i, j in combinations(list(range(1, len(d)+1)),2):
    if j - i == d[i-1] + d[j-1]:
        ret +=1

print(ret)

Submission status: Runtime Error

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

t=[0]*n
tt=[[0]*n for k in range(n)]

def search(i,j):
   if i==j or j==n or i==n-1:
      return
   if tt[i][j]==1:
      return
   if j-i==a[i]+a[j]:
      t[i]+=1

   tt[i][j]=1

   search(i+1,j)
   search(i,j+1)
search(0,1)

print(sum(t))

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**6))

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

ans = 0
for i in range(len(needsearch)):
    if 0<needsearch[i]+10**6<2*(10**6):
        ans += counter[needsearch[i]+10**6]
    counter[a[i]+10**6]-=1


print(ans)

Submission status: Runtime Error

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

cnt = [0] * (2*(10 ** 5) + 10) 
for i in range(N):
    if A[i]+1 >= 2*(10 ** 5):
        continue
    cnt[A[i]+i] += 1

ans = 0
for i in range(N)[1:]:
    if A[i]-i >= 0:
        continue
    ans += cnt[abs(A[i]-i)]

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)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)
	# tl = [0] * max(ipl)
	tl = [0] * 9999999999999
	for i in ssb:
		if int(i)-1 < len(tl):
			tl[int(i)-1] += 1
	# print(pl)
	# print(sb)
	# print(tl)
	cnt = 0
	for i in pl:
		if int(i)-1 < len(tl):
			cnt += tl[int(i)-1]

	print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
X=int(input())
flag=0
for i in range(X):
    a=int(input())
    if i==0:
        A=np.array(a)
    else:
        A=np.append(A,a)

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

print(flag)

Submission status: Runtime Error

Solution code:
N =int(input())
A = list(map(int,input().rstrip().split(" ")))
Aq = []
DP = [0 for i in range(10 ** 5)]
DPP = []
ans = 0
for i in range(N):
    if i >= A[i]:
        ans += DP[i - A[i]] 
    DP[A[i] + i] += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
dp = [0] * 10 ** 7
ans = 0
for i in range(N):
    x = i + 1 - A[i]
    if x >= 0:
        ans += dp[x]
    if x < 10 ** 7:
        dp[i + 1 + A[i]] += 1

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
ans=0
a=list(map(int,input().split()))
now=max(a)
noww=now
ka=n+2*now
matc=[0]*ka
mat2=[0]*ka
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+1):
  ans+=matc[j]*mat2[j]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
li = []
for i in range(n):
    if a[i] < 200000:
        li.append([a[i],i])
li.sort()
cnt = 0
for i in range(n-1):
    j = i+1
    while j <= n-1 and li[i][0] + li[j][0] < 200000:
        if abs(li[j][1]-li[i][1]) == li[i][0] + li[j][0]:
            cnt += 1
        j += 1
print(cnt)

Submission status: Runtime Error

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

Submission status: 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]

for p in itertools.permutations(A, 2):
  if abs(p[0][0]-p[1][0]) == p[0][1]+p[1][1]:
    cnt += 1

print(int(cnt/2))

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)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)
	tl = [0] * max(ipl)
	for i in ssb:
		if int(i)-1 < len(tl):
			tl[int(i)-1] += 1
	# print(pl)
	# print(sb)
	# print(tl)
	cnt = 0
	for i in pl:
		if int(i)-1 < len(tl):
			cnt += tl[int(i)-1]

	print(cnt)

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)):
    if 0<needsearch[i]+10**5<2*(10**5):
        ans += counter[needsearch[i]+10**5]
    counter[a[i]+10**5]-=1


print(ans)

Submission status: Runtime Error

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

t=[[0]*n for k in range(n)]
tt=[[0]*n for k in range(n)]

def search(i,j):
   if i==j or j==n or i==n-1:
      return
   if tt[i][j]==1:
      return
   if j-i==a[i]+a[j]:
      t[i][j]=1

   tt[i][j]=1

   search(i+1,j)
   search(i,j+1)
search(0,1)
result=0
for row in t:
    result += sum(row)

print(result)

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 x+1 >= N and y+1 >= N:
        return
        
    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:
n=int(input())
a = list(map(int, input().split()))

t=[[0]*n for k in range(n)]
tt=[[0]*n for k in range(n)]

def search(i,j):
   if i==j or j==n or i==n-1:
      return
   if tt[i][j]==1:
      return
   if j-i==a[i]+a[j]:
      t[i][j]=1
      print(i,j)
   tt[i][j]=1

   search(i+1,j)
   search(i,j+1)
search(0,1)
result=0
for row in t:
    result += sum(row)

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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())
A = [int(i) for i in input().split()]
dp = [0] * 10 ** 6
ans = 0
for i in range(N):
    x = i + 1 - A[i]
    if x >= 0:
        ans += dp[x]
    if x < 10 ** 6:
        dp[i + 1 + A[i]] += 1

print(ans)

Submission status: Runtime Error

Solution code:
import itertools
n=int(input())
A=list(map(int,input().split()))
l=list(itertols.combinations([i for i in range(1,n+1)],2))
cnt=0
for p,q in l:
    if q-p==A[q-1]+A[p-1]:
        cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
from math import sqrt

_ = int(input())
count = 0
l = list(map(int,input().split()))
for i in range(len(l)):
    for j in range(i+1,i+1+l[i]+1):
        if(j-i == l[i]+l[j]):
            count += 1
print(count)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
dp = [0] * (10 ** 9 + 2 * (10 ** 5))
ans = 0
for i in range(N):
    x = i + 1 - A[i]
    if x >= 0:
        ans += dp[x]
    dp[i + 1 + A[i]] += 1

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations

n = int(input())
a = list(map(int,input().split()))
b = list(range(1,n+1))
c = [0]*int(n*(n-1)/2)
d = [0]*int(n*(n-1)/2)
for i,j in enumerate(combinations(b,r=2)):
  x,y = map(int,j)
  c[i] = abs(x-y)
cnt = 0

for i,j in enumerate(combinations(a,r=2)):
  x,y = map(int,j)
  difh = x + y
  d[i] = x + y
  if difh == c[i]:
    cnt += 1
# print(c)
# print(d)
print(cnt)

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)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)
	tl = [0] * max(ipl)
	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()))

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 -1*fromLeft[i] < 3*10**5-10:
        ldList[-1*fromLeft[i]] += 1
    if a[i]+i < 3*10**5-10:
        ans += ldList[a[i]+i]

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations
n = int(input())
a_ls = list(map(int, input().split()))
ans = 0
inds = [i for i in range(n)]
for ind_a, ind_b in combinations(inds, 2):
    Sum = a_ls[ind_a] + a_ls[ind_b]
    diff = abs(a-b)
    if Sum == diff:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
num=int(input())
count=0
height=[]
hei=int(input())
height.extend(hei.split(" "))
for i in range(num-1):
	for j in range(i+1,num-1):
    	if abs(j-i)==height[i]+height[j]:
          count+=1
print(count)