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: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = [i+1+a[i] for i in range(n)]
c = [(j+1)-a[j] for j in range(n)]
d = Counter(c)
ans = 0
for i in range(n):
    ans += d[b[i]]
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

D = {}
for i in range(n):
    try:
        D[i-A[i]] += 1
    except:
        D[i-A[i]] = 1

# print(D)

ans = 0
for i in range(n):
    D[i-A[i]] -= 1
    # print(i+A[i])
    try:
        ans += D[i+A[i]]
    except:
        continue

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
C = collections.Counter()
for i ,ai in enumerate(A):
  ans += C[i-ai]
  C[ai+i] += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A1 = list(map(int, input().split()))
A2 = [-1 * A1[i] for i in range(N)]

for i in range(N):
    A1[i] -= i
    A2[i] -= i

C1 = Counter(A1)
C2 = Counter(A2)
res = 0
for c1 in C1.keys():
    res += C1[c1] * C2[c1]
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter

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

B1 = []
B2 = []
for i, a in enumerate(A):
    B1.append(a-i)
    B2.append(-a-i)

dic = {}

ans = 0
for b1, b2 in zip(B1, B2):
    if b1 in dic:
        ans += dic[b1]
    if b2 in dic:
        dic[b2] += 1
    else:
        dic[b2] = 1

print(ans)

Submission status: Accepted

Solution code:
from collections import *

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

M = defaultdict(int)
ans = 0
for i in range(N):
  ans += M[A[i]-i]
  M[-A[i]-i] += 1
print(ans)

Submission status: Accepted

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

X = [a - i for i, a in enumerate(A, start=1)]
Y = [-a - i for i, a in enumerate(A, start=1)]
memo = defaultdict(int)
ans = 0

for i in range(N - 1):
    memo[Y[i]] += 1
    ans += memo[X[i + 1]]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
cc=Counter()
ans=0
for i,val in enumerate(a,1):
    if i-val>0:
       ans+=cc[i-val]
    cc[i+val]+=1
print(ans)

Submission status: Accepted

Solution code:
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

####
from collections import Counter
def solve(N, A):
    # A[i] + A[i + d] = d
    # B[i] + i + B[i + d] + i + d = d
    # B[i + d] = -2i - B[i]
    # 2 3 3 1 3 1
    # 0 1 2 3 4 5
    # 2 2 1 -2 -1 -4
    B = [x-i for i,x in enumerate(A)]
    count = Counter()
    ans = 0
    for i in xrange(N - 1, -1, -1):
        ans += count[-B[i] - 2*i]
        count[B[i]] += 1
    return ans
    


    
print solve(rri(), rrm())

Submission status: Accepted

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
import collections
D=collections.defaultdict(int)
ans=0
for i in range(n):
  ans+=D[i-A[i]]
  D[A[i]+i]+=1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
wa=[]
sa=[]
for i in range(n):
    wa.append(i+a[i])
    sa.append(i-a[i])
d=defaultdict(int)
for i in wa:
    d[i]+=1
ans=0
for i in sa:
    ans+=d[i]
print(ans)

Submission status: Accepted

Solution code:
from bisect import *
n = int(input())
A = list(map(int,input().split()))
s = {}
# d = {}
ans = 0
for i,a in enumerate(A):
    if a+i not in s.keys():s[a+i] = 0# []
    # s[a+i].append(i)
    s[a+i] += 1
    if i-a not in s:continue
    ans += s[i-a]
    # if i-a not in d.keys():d[i-a] = []
    # d[i-a].append(i)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

l1 = Counter([i + 1 - A[i]for i in range(N)])
l2 = Counter([i + 1 + A[i]for i in range(N)])

ret = 0
for k, v in l1.items() :
  ret += v * l2[k]
  
print(ret)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = {}
    for i, a in enumerate(A):
        B[i - a] = B.get(i - a, 0) + 1
    r = 0
    for i, a in enumerate(A):
        B[i - a] -= 1
        r += B.get(a + i, 0)
    return r

print(main())

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n = int(input())
n,*a = [int(i) for i in read().split()]

from collections import Counter
d = Counter()

ans = 0
for i in range(n):
    ans += d[a[i]-i]
    d[-i-a[i]] += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
m = {}
ans = 0
for i in range(n):
    x = A[i] + i
    if x not in m:
        m[x] = 0
    m[x] += 1
    if i - A[i] in m:
        ans += m[i - A[i]]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

dd = defaultdict(int)

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
ans = 0
for i in range(n):
    left = a[i]-i
    ans += d[left]
    d[-a[i]-i] += 1
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    d = defaultdict(lambda : 0)
    ans = 0
    for i,ai in enumerate(a):
        ans += d[-ai+i]
        d[ai+i] += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(input())
D = {}
A = [int(a) for a in input().split()]
ans = 0
for i, a in enumerate(A):
    if i - a in D:
        ans += D[i-a]
    if i + a in D:
        D[i+a] += 1
    else:
        D[i+a] = 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]


p = Counter()
q = Counter()

for i in range(n):
    p[i-a[i]] += 1
    q[i+a[i]] += 1
    
ans = 0

for x in p.keys():
    ans += p[x]*q[x]

print(ans)

Submission status: Accepted

Solution code:
import bisect
N=int(input())
A=[int(i) for i in input().split()]
X=sorted([i-A[i] for i in range(N)])
Y=sorted([i+A[i] for i in range(N)])
ans=0
for i in range(N):
    l=bisect.bisect_left(Y,X[i])
    r=bisect.bisect_right(Y,X[i])
    ans+=r-l
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
plus = [A[i] + i for i in range(N)]
minus = [A[i] - i for i in range(N)]
cnt = defaultdict(int)
ans = 0
for i in range(N):
    ans += cnt[-minus[i]]
    cnt[plus[i]] += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
m = {}
ans = 0
for i in range(n):
    if i - a[i] in m:
        ans += m[i - a[i]]
    j = i + a[i]
    if j in m:
        m[j] += 1
    else:
        m[j] = 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    n=int(input())
    A=list(map(int,input().split()))
    B,C=[0]*n,[0]*n
    for i,a in enumerate(A):
        B[i]=a+i
        C[i]=i-a
    D=defaultdict(int)
    D[C[-1]]+=1
    ans=0
    for i in range(n-1)[::-1]:
        ans+=D[B[i]]
        D[C[i]]+=1
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:

N = int(input())

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

dic = {}
ans = 0

for j in range(N):

    now = A[j] - (j+1)

    if now in dic:
        ans += dic[now]

    pl = -1 * A[j] - (j+1)

    if pl not in dic:
        dic[pl] = 1
    else:
        dic[pl] += 1

print (ans)

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

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

    AA = [0] * N
    for i, a in enumerate(A):
        AA[i] = -a + i + 1
    ans = 0
    C = defaultdict(int)
    for i in range(N-2, -1, -1):
        C[AA[i+1]] += 1
        ans += C[A[i] + i + 1]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
input = sys.stdin.readline


def inp():
    return int(input())


def inpl():
    return list(map(int, input().split()))


N = inp()
aa = inpl()


ajs = []
ais = []

for i, a in enumerate(aa):
    ajs.append(a - i)
    ais.append(-a - i)


cnt = defaultdict(int)
ans = 0
for ai, aj in zip(ais, ajs):
    ans += cnt[aj]
    cnt[ai] += 1


print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        d[a[i] + i + 1] += 1
    ans = 0
    for i in range(n):
        x = i + 1 - a[i]
        ans += d[x]
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

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

t = [0] * (10 ** 10)
ans = 0
for i in range(N):
    sa = i - A[i]
    ans += t[sa]
    wa = i + A[i]
    t[wa] += 1

print(ans)

Submission status: Runtime Error

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

t = [0] * N + [0] * 10 ** 6
ans = 0
for i in range(N):
    sa = i - A[i]
    ans += t[sa]
    wa = i + A[i]
    t[wa] += 1

print(ans)

Submission status: Runtime Error

Solution code:
import math , sys

N  = int( input() )

A = list(map(int, input().split() ) )
M = max( [ i + A[i] for i in range(N) ])
B = [0] * (2*M)
ans = 0
for i in range(N):
    if i - A[i] >=0:
        ans += B[i - A[i]]
    B[i + A[i]]+=1
print(ans)

Submission status: Runtime Error

Solution code:
import math , sys

N  = int( input() )

A = list(map(int, input().split() ) )
M = max( [ i + A[i] for i in range(N) ])
B = [0] * (M + 2)
ans = 0
for i in range(N):
    if i - A[i] >=0:
        ans += B[i - A[i]]
    B[i + A[i]]+=1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
nums = [0] + list(map(int, input().split()))

A = [i + n for n in enumerate(nums, start=1)]
B = [j - n for n in enumerate(nums, start=1)]
BC = Counter(B)
answer = 0
for a in A:
  answer += BC[a]
print(answer)

Submission status: Runtime Error

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

plus=[0]*1000000
minus=[0]*1000000

for i in range(n):
  ene=i+1
  pin=a[i]
  pl,mi=ene+pin,ene-pin
  plus[pl]+=1
  minus[mi]+=1
  
for i in range(1000000):
  ans+=plus[i]*minus[i]
  

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

B = np.zeros(11 * 10**8, dtype = "uint32")

ans = 0

for index, A in enumerate(As):
    if(index - A >= 0):
        ans += B[index-A]

    B[index+A] += 1
#    print(list(B[:20]))

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

B = np.zeros(3 * 10**9, dtype = "int32")

ans = 0

for index, A in enumerate(As):
    ans += B[index-A]

    B[index+A] += 1
#    print(list(B[:20]))

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

B = np.zeros(2 * 10**9, dtype = int)

ans = 0

for index, A in enumerate(As):
    if(index - A >= 0):
        ans += B[index-A]

    B[index+A] += 1
#    print(list(B[:20]))

print(ans)

Submission status: Runtime Error

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

j_Aj = [0]
i_Ai = [0] * (max(j_Aj)+1)

for j, aj in enumerate(a):
    j_Aj.append(j + 1 - aj)
ans = 0
for j, j_aj in enumerate(j_Aj):
    if j == 0:
        continue
    if j_aj >= 2:
        ans += i_Ai[j_aj]
    if j + a[j - 1]<=max(j_Aj):
        i_Ai[j + a[j - 1]] += 1
print(ans)

Submission status: Runtime Error

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

j_Aj = [0]
i_Ai = [0] * (max(a)+n+1)

for j, aj in enumerate(a):
    j_Aj.append(j + 1 - aj)
ans = 0
for j, j_aj in enumerate(j_Aj):
    if j == 0:
        continue
    if j_aj >= 2:
        ans += i_Ai[j_aj]
    i_Ai[j + a[j - 1]] += 1
print(ans)

Submission status: Runtime Error

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

j_Aj = [0]
i_Ai = [0] * (10 ** 9 + 2 * 10 ** 5)

for j, aj in enumerate(a):
    j_Aj.append(j + 1 - aj)
ans = 0
for j, j_aj in enumerate(j_Aj):
    if j == 0:
        continue
    if j_aj >= 2:
        ans += i_Ai[j_aj]
    i_Ai[j + a[j - 1]] += 1
print(ans)

Submission status: Runtime Error

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


j_Aj=[0]
i_Ai=[0]*(10**9+2*10**5)

for j,aj in enumerate(a):
    j_Aj.append(j+1-aj)
ans=0
for j,j_aj in enumerate(j_Aj):
    if j==0:
        continue
    if j_aj>=2:
        ans+=i_Ai[j_aj]
    i_Ai[j+a[j-1]]+=1
print(ans)

Submission status: Runtime Error

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


j_Aj=[0]
i_Ai=[0]*(10**9+2*10**5)

for j,aj in enumerate(a):
    j_Aj.append(j+1-aj)
ans=0
for j,j_aj in enumerate(j_Aj):
    if j==0:
        continue
    if j_aj>=2:
        ans+=i_Ai[j_aj]
    i_Ai[j+a[j-1]]+=1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

M = max(A) + N

counter = [0] * (M + 1)

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

print(ans)

Submission status: Runtime Error

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

dic = {}
for i in range(n):
  a = lst[i]
  if a >= n - 1:
    continue
  if a not in dic:
    dic[a] = set()
  dic[a].add(i)
#print(dic)
count = 0
for a in dic.keys():
  set_ = dic[a]
  for index in set_:
    b = a + index
    if b > n:
      continue
    for j in dic.keys():
      j = b + c
      if c in dic[c]:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
ans=0
for i in range(n):
  b.append(i+1-a[i])
  c.append(a[i]+i+1)
c_=[0]*(max(c)+1)
b_=[0]*(max(c)+1)
for i in range(n):
  c_[c[i]]+=1
for i in range(n):
  if 0<=b[i]<=max(c)+1:
    b_[b[i]]+=1
for i in range(max(c)+1):
  ans+=b_[i]*c_[i]
print(ans)

Submission status: Runtime Error

Solution code:
import sys,math,collections,
input = sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))
B = []
C = []
for i,a in enumerate(A):
    B.append(i+a)
    C.append(i-a)
cnt = 0
Bc = collections.Counter(B)
Cc = collections.Counter(C)

for key,val in Bc.items():
    cnt += val*Cc[key]
print(cnt)

Submission status: Runtime Error

Solution code:
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

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

B = []
for i,a in enumerate(A):
    if a <= N-1:
        B.append([a,i])
if len(B)==0:
    print(0)
    exit()
B.sort()
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if B[i][0]+B[j][0]==abs(B[i][1]-B[j][1]):
            cnt +=1
        if B[i][0]+B[j][0]>=N:
            break
print(cnt)

Submission status: Runtime Error

Solution code:
import sys,math,collections,itertools,bisect
input = sys.stdin.readline

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

B = []
for i,a in enumerate(A):
    if a <=N-1:
        B.append([a,i])
B.sort()
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if B[i][0]+B[j][0]==abs(B[i][1]-B[j][1]):
            cnt +=1
        if B[i][0]+B[j][0]>=N:
            break
print(cnt)

Submission status: Runtime Error

Solution code:

ni = np.array([i for i in range(n)])

ap = a + ni
an = (a - ni) * -1
an.sort()
ans = 0
for j in an[::-1]:
  if j <= 0:break
  for i in ap:
    if j == i:
      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())))

sign = np.arange(1,N+1)
sign = sign + A
temp = np.arange(N)+1-A
count = 0
for i in range(1,N):
  count += (sign[:i]==temp[:i]).sum()

print(count)

Submission status: Runtime Error

Solution code:
import collections
cc = collections.Counter()
count = 0
n = raw_input()
for i,e in enumerate(map(int, raw_input().split())):
	count += cc[e - i]
    cc[e-  i] +=1
    
print count

Submission status: Runtime Error

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

ans = 0
cnt = defaultdict(int)
for i in range(n):
	ans += cnt[i - a[i]]
	cnt[i + a[i]] += 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
A = l()
L = []
L2 = [0]*(10**6)
for i in range(N):
    L.append(i+A[i]+1)
    if i-A[i]+1 >= 0 and i-A[i]+1 < 10**6:
        L2[i-A[i]+1] += 1
ans = 0
for l in L:
    ans += L2[l]
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
A = l()
L = []
L2 = [0]*N*2
for i in range(N):
    L.append(i+A[i]+1)
    if i-A[i]+1 >= 0:
        L2[i-A[i]+1] += 1
ans = 0
for l in L:
    ans += L2[l]
print(ans)

Submission status: Runtime Error

Solution code:
せっかimport sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
p = []
q = []
d = collections.defaultdict(int)
e = collections.defaultdict(int)
for i in range(n):
    p.append(a[i]+i+1)
for i in range(n):
    q.append(-a[i]+i+1)
ans = 0
for i in range(n):
    d[p[i]] += 1
    e[q[i]] += 1
for i in d.keys():
    ans += d[i]*e[i]
print(ans)

Submission status: Runtime Error

Solution code:
N  = int(input())
a  = list(map(int,input().split()))
i = 0
key =0
while i <N:
	j=0
	if a[i] > N- i:
		pass
	else:
		while j<N:
			if abs(i-j) < a[i] or j < i:
				j = i+a[i] +1
			if a[i] + a[j] == abs(i-j):
				key +=1
			j+=1
	i += 1

print(key)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():

    N = int(input())
    num = [i for i in range(1, N+1)]
    A = list(map(int, input().split()))
    d=defaultdict(int)
    cnt=0
    for k,v in enumerate(A):
        d[k+v]+=1
        cnt+=d[k-v]

    print(cnt)


resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())

A=list(map(int,input().split()))
#B=[]
#C=[]
D=[0]*1500000
E=[0]*1500000

ans=0

for i in range(N):
  #B.append(A[i]+i+1)
  #C.append(-A[i]+i+1)
  D[A[i]+i+1]+=1
  E[-A[i]+i+1]+=1

for i in range(len(D)):
  #ans+=C.count(i)
  ans+=D[i]*E[i]

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

A=list(map(int,input().split()))
#B=[]
#C=[]
D=[0]*10000000
E=[0]*10000000

ans=0

for i in range(N):
  #B.append(A[i]+i+1)
  #C.append(-A[i]+i+1)
  D[A[i]+i+1]+=1
  E[-A[i]+i+1]+=1

for i in range(len(D)):
  #ans+=C.count(i)
  ans+=D[i]*E[i]

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

A=list(map(int,input().split()))
#B=[]
#C=[]
D=[0]*1000000000
E=[0]*1000000000

ans=0

for i in range(N):
  #B.append(A[i]+i+1)
  #C.append(-A[i]+i+1)
  D[A[i]+i+1]+=1
  E[-A[i]+i+1]+=1

for i in range(len(D)):
  #ans+=C.count(i)
  ans+=D[i]*E[i]

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

A=list(map(int,input().split()))
#B=[]
#C=[]
D=[0]*10**9
E=[0]*10**9

ans=0

for i in range(N):
  #B.append(A[i]+i+1)
  #C.append(-A[i]+i+1)
  D[A[i]+i+1]+=1
  E[-A[i]+i+1]+=1

for i in range(len(D)):
  #ans+=C.count(i)
  ans+=D[i]*E[i]

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

A=list(map(int,input().split()))
#B=[]
#C=[]
D=[0]*1000000
E=[0]*1000000

ans=0

for i in range(N):
  #B.append(A[i]+i+1)
  #C.append(-A[i]+i+1)
  D[A[i]+i+1]+=1
  E[-A[i]+i+1]+=1

for i in range(len(D)):
  #ans+=C.count(i)
  ans+=D[i]*E[i]

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

A=list(map(int,input().split()))
#B=[]
#C=[]
D=[0]*500000
E=[0]*500000

ans=0

for i in range(N):
  #B.append(A[i]+i+1)
  #C.append(-A[i]+i+1)
  D[A[i]+i+1]+=1
  E[-A[i]+i+1]+=1

for i in range(len(D)):
  #ans+=C.count(i)
  ans+=D[i]*E[i]

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())

A=list(map(int,input().split()))
#B=[]
#C=[]
D=[0]*400000
E=[0]*400000

ans=0

for i in range(N):
  #B.append(A[i]+i+1)
  #C.append(-A[i]+i+1)
  D[A[i]+i+1]+=1
  E[-A[i]+i+1]+=1

for i in range(len(D)):
  #ans+=C.count(i)
  ans+=D[i]*E[i]

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
dicta = {}
for i in range(n):
    dicta[i + 1] = a[i]
for i in range(1, n + 1):
    if dicta[i] > n:
        del dicta[i]

s = 0
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        ndif = abs(i - j)
        tsum = dicta[i] + dicta[j]
        if ndif == tsum:
            s += 1

print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

def main():
    pass
    N = int(input())
    A = list(map(int, input().split()))

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

    ans = 0
    for k in range(0,N):
        Bk = k+A[k]
        if Bk <= 2*10**5:
            ans += H[Bk]

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
high=map(int,input().split())
high_i=[]
high_j=[]
ans=0

for m in range(N):
    tmp_i=m+high[m]
    high_i.append(tmp_i)

for n in range(N):
    tmp_j=n-high[n]
    high_j.append(tmp_j)

for p in range(N):
    for q in range(p+1,N):
        if high_i[p]==high[q]:
            ans+=1

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict


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

memo = defaultdict(int)
ans = 0
for i, x in enumerate(a, 1):
    print(memo)
    ans += memo[i - x]
    memo[x + i] += 1

print(ans)

Submission status: Runtime Error

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

dict_diffs = dict()
for i in range(1, n+1):
  dict_diffs[i+a[i-1]] = dict_diffs1.get(i+a[i-1], 0) + 1
total = 0
for j in range(1, n+1):
  total += dict_diffs1.get(j-a[j-1], 0)
print(total)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
P = {}
Q = {}
X = {}
for i in range(N):
  p = i+1+A[i]
  q = i+1-A[i]
  if str(p) in P:
    P[str(p)] += 1
  else:
    P[str(p)] = 0
  if str(q) in Q:
    Q[str(q)] += 1
  else:
    Q[str(q)] = 0
  
  X.setdefalut(str(i+1+A[i]),i+1+A[i])
  X.setdefalut(str(i+1-A[i]),i+1-A[i])
  
#J[a]とI[b]が等しいのが条件
#とりうる値 < 10**9を全て試す
ans = 0

for key in X.keys():
  ans += P[key] * Q[key]
  
print(ans)

Submission status: Runtime Error

Solution code:
J = [0 for i in range(int(2e5+3))]


def main():
    n = int(input())
    a = list(map(lambda x: int(x)-1, input().split()))

    for i in range(n):
        tmp = i - a[i]
        if 0 < tmp:
            J[tmp] += 1

    cnt = 0
    for i in range(n):
        tmp = a[i]+i+2
        cnt += J[tmp]

    print(cnt)
    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    a = list(map(lambda x: int(x)-1, input().split()))
    J = [0 for i in range(int(2e5+3))]

    for i in range(n):
        tmp = i - a[i]
        if 0 <= tmp:
            J[tmp] += 1

    cnt = 0
    for i in range(n):
        tmp = a[i]+i+2
        cnt += J[tmp]

    print(cnt)
    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

H=[0]+list(map(int,input().split()))

J={x:[] for x in range(1,N+1)}

for i in range(M):
    a,b=map(int,input().split())
    J[a].append(b)
    J[b].append(a)

S=0
for x in J:
    f=1
    for y in J[x]:
        if H[x]<=H[y]:
            f=0
    S+=f

print(S)