TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.  Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road. Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.  How many good observatories are there?

Submission attempts (in order):
N,M = map(int, input().split())
H=list(map(int, input().split()))
A=[]
B=[]
for i in range(M):
    A1,B1=map(int, input().split())
    A.append(A1)
    B.append(B1)
miti={}
for i in range(M):
    if A[i] in miti:
        miti[A[i]].append(H[B[i]-1])            
    else:
        miti[A[i]]=[]
        miti[A[i]].append(H[B[i]-1])
    if B[i] in miti:
        miti[B[i]].append(H[A[i]-1])            
    else:
        miti[B[i]]=[]
        miti[B[i]].append(H[A[i]-1])
count=0
print(miti)
for i in range(M):
    if i+1 in miti:
        for j in range(len(miti[i+1])):
            if H[i]<=miti[i+1][j]:
                count+=1
                print(i+1)
                break
print(N-count)

N,M = map(int, input().split())
H=list(map(int, input().split()))
A=[]
B=[]
for i in range(M):
    A1,B1=map(int, input().split())
    A.append(A1)
    B.append(B1)
miti={}
for i in range(M):
    if A[i] in miti:
        miti[A[i]].append(H[B[i]-1])            
    else:
        miti[A[i]]=[]
        miti[A[i]].append(H[B[i]-1])
    if B[i] in miti:
        miti[B[i]].append(H[A[i]-1])            
    else:
        miti[B[i]]=[]
        miti[B[i]].append(H[A[i]-1])
count=0
print(miti)
for i in range(M):
    if i+1 in miti:
        for j in range(len(miti[i+1])):
            if H[i]<miti[i+1][j]:
                count+=1
                break
    else:
        count+=1
print(N-count)

N,M = map(int, input().split())
H=list(map(int, input().split()))
A=[]
B=[]
for i in range(M):
    A1,B1=map(int, input().split())
    A.append(A1)
    B.append(B1)
miti={}
for i in range(M):
    if A[i] in miti:
        miti[A[i]].append(H[B[i]-1])            
    else:
        miti[A[i]]=[]
        miti[A[i]].append(H[B[i]-1])
    if B[i] in miti:
        miti[B[i]].append(H[A[i]-1])            
    else:
        miti[B[i]]=[]
        miti[B[i]].append(H[A[i]-1])
count=0
for i in range(N):
    if i+1 in miti:
        for j in range(len(miti[i+1])):
            if H[i]<=miti[i+1][j]:
                count+=1
                break
print(N-count)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.  Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road. Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.  How many good observatories are there?

Submission attempts (in order):
N, M = map(int, input().split())
H = list(map(int, input().split()))

t = [0]*N
for i in range(M):
   a, b = map(int, input().split())
   t[a-1] = max(t[a-1], H[b-1])
   t[b-1] = max(t[b-1], H[a-1])

res = 0
for i range(N):
    if H[i] > t[i]:
        res += 1

print(res) 

N, M = map(int, input().split())
H = list(map(int, input().split()))

t = [0]*N
for i in range(M):
   a, b = map(int, input().split())
   t[a-1] = max(t[a-1], H[b-1])
   t[b-1] = max(t[b-1], H[a-1])

res = 0
for i in range(N):
    if H[i] > t[i]:
        res += 1

print(res) 

Verdicts: Runtime Error

Accepted
Problem: There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.  Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road. Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.  How many good observatories are there?

Submission attempts (in order):
h = list(map(int,input().split()))
d = [1] * n
for i in range(m):
  a,b = list(map(int,input().split()))
  a -= 1
  b -= 1
  if h[a] > h[b]:
    d[b] = 0
  elif h[b] > h[a]:
    d[a] = 0
  else:
    d[a] = 0
    d[b] = 0

print(sum(d))


n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
d = [1] * n
for i in range(m):
  a,b = list(map(int,input().split()))
  a -= 1
  b -= 1
  if h[a] > h[b]:
    d[b] = 0
  elif h[b] > h[a]:
    d[a] = 0
  else:
    d[a] = 0
    d[b] = 0

print(sum(d))

Verdicts: Runtime Error

Accepted
Problem: There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.  Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road. Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.  How many good observatories are there?

Submission attempts (in order):
# -*- coding: utf-8 -*-
def main():
    N,M = map(int, input().split())
    H = list(map(int, input().split()))
    ans = []
    for _ in range(N):
        ans.append(1)
    for i in range(M):
        A,B = map(int, input().split())
        if H[A-1] < H[B-1]:
            ans[A-1] = -1
        elif H[A-1] > H[B-1]:
            ans[B-1] = 0
        else:
            ans[B-1] = 0
            ans[A-1] = 0
    print(sum(ans))

if __name__ == '__main__':
    main()

# -*- coding: utf-8 -*-
def main():
    N,M = map(int, input().split())
    H = list(map(int, input().split()))
    ans = []
    for _ in range(N):
        ans.append(1)
    for i in range(M):
        A,B = map(int, input().split())
        if H[A-1] < H[B-1]:
            ans[A-1] = 0
        elif H[A-1] > H[B-1]:
            ans[B-1] = 0
        else:
            ans[B-1] = 0
            ans[A-1] = 0
    print(sum(ans))

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.  Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road. Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.  How many good observatories are there?

Submission attempts (in order):

d = defaultdict(list)

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

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

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

ans = 0
for i in range(N):
    ng = 0

    if(i not in d):
        ans += 1
        continue

    for j in d[i]:
        if(H[i] <= H[j]): ng = 1
    if(ng != 1):
        ans += 1

print(ans)

from collections import defaultdict

d = defaultdict(list)

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

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

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

ans = 0
for i in range(N):
    ng = 0

    if(i not in d):
        ans += 1
        continue

    for j in d[i]:
        if(H[i] <= H[j]): ng = 1
    if(ng != 1):
        ans += 1

print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.  Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road. Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.  How many good observatories are there?

Submission attempts (in order):
n,m = map(int,input().split())
h = list(map(int,input().split()))
a = []
b = []
cnt = 0
while True:
  try:
    ta,tb = map(int,input().split())
    a.append(ta)
    b.append(tb)
  except:
    break

highest = h.index(max(h))+1

for i in range(1,m+1):
  if i not in a and i not in b:
    cnt +=1
  if a[i-1]==highest or b[i-1]==highest:
    cnt +=1
print(cnt)

n,m = map(int,input().split())
h = list(map(int,input().split()))
a = []
b = []
cnt = 0
while True:
  try:
    ta,tb = map(int,input().split())
    a.append(ta)
    b.append(tb)
  except:
    break
    
H = [0]*n

for i in range(m):

  if h[a[i]-1]>h[b[i]-1]:
    H[b[i]-1]-=1
  
  if h[a[i]-1]==h[b[i]-1]:
    H[a[i]-1]-=1
    H[b[i]-1]-=1
  if h[a[i]-1]<h[b[i]-1]:
    H[a[i]-1]-=1
n = [1 for i in H if i>=0]
print(len(n))

Verdicts: Wrong Answer

Accepted
Problem: There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.  Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road. Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.  How many good observatories are there?

Submission attempts (in order):
N, K = (int(i) for i in input().split())
H = list(map(int,input().split()))
ans = [1]*N
for m in range(M):
  a, b = (int(i) for i in input().split())
  if H[a-1] < H[b-1]:
    ans[a-1] = 0
  elif H[a-1] > H[b-1]:
    ans[b-1] = 0
print(ans.count(1))

N, M = (int(i) for i in input().split())
H = list(map(int,input().split()))
ans = [1]*N
for m in range(M):
    a, b = (int(i) for i in input().split())
    if H[a-1] < H[b-1]:
        ans[a-1] = 0
    elif H[a-1] > H[b-1]:
        ans[b-1] = 0
    else:
        ans[a-1] = 0
        ans[b-1] = 0
print(ans.count(1))

Verdicts: Runtime Error

Accepted
Problem: There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.  Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road. Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.  How many good observatories are there?

Submission attempts (in order):
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))

print(AB)

for d in range(0,M):
    if H[AB[d][0]-1] < H[AB[d][1]-1]:
        AB[d].pop(1)
    elif H[AB[d][0]-1] > H[AB[d][1]-1]:
        AB[d].pop(0)

print(AB)

bad = [e for row in AB for e in row]
badsingle = list(set(bad))
print(N - len(badsingle))


N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))


for d in range(0,M):
    if H[AB[d][0]-1] < H[AB[d][1]-1]:
        AB[d].pop(1)
    elif H[AB[d][0]-1] > H[AB[d][1]-1]:
        AB[d].pop(0)


bad = [e for row in AB for e in row]
badsingle = list(set(bad))
print(N - len(badsingle))

Verdicts: Wrong Answer

Accepted
Problem: There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.  Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road. Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.  How many good observatories are there?

Submission attempts (in order):
def main():
    import collections
    n, m = map(int, input().split())
    hs = list(map(int, input().split()))
    nmap = [0] * n
    cnt = 0

    for j in range(m):
        v = input().split()
        v0 = int(v[0]) - 1
        v1 = int(v[1]) - 1
        if hs[v0] < hs[v1]:
            nmap[v0] += 1
        elif hs[v0] == hs[v1]:
            nmap[v0] += 1
            nmap[v1] += 1
        # else:
        #     nmap[v1] += 1
    print(nmap)
    for i in nmap:
        if i == 0:
            cnt += 1
    return cnt


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


def main():
    import collections
    n, m = map(int, input().split())
    hs = list(map(int, input().split()))
    nmap = [0] * n
    cnt = 0

    for j in range(m):
        v = input().split()
        v0 = int(v[0]) - 1
        v1 = int(v[1]) - 1
        if hs[v0] < hs[v1]:
            nmap[v0] += 1
        elif hs[v0] == hs[v1]:
            nmap[v0] += 1
            nmap[v1] += 1
        else:
            nmap[v1] += 1
    for i in nmap:
        if i == 0:
            cnt += 1
    return cnt


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


Verdicts: Wrong Answer

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

Submission attempts (in order):

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

from collections import defaultdict
n = int(input())
a = np.array(list(map(int, input().split())))
ci = defaultdict(int)
cj = defaultdict(int)
for i in range(n):
    ci[a[i]+i] += 1
    cj[i-a[i]] += 1
cnt = 0
for k in ci.keys():
    cnt += ci[k] * cj[k]
print(cnt)

from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
ci = defaultdict(int)
cj = defaultdict(int)
for i in range(n):
    ci[a[i]+i] += 1
    cj[i-a[i]] += 1
cnt = 0
for k in ci.keys():
    cnt += ci[k] * cj[k]
print(cnt)

Verdicts: Runtime Error

Runtime Error

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

Submission attempts (in order):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
L = [0]*n
R = [0]*n
cnt=0
for i in range(n):
    L[i] = i+a[i]
    R[i] = i-a[i]
z1=Counter(L)
z2=Counter(R)
print(z1)
print(z2)
cnt=0
for k1,v1 in z1.items():
    v2 = z2[k1]
    cnt += v1*v2
print(cnt)

from collections import Counter
n = int(input())
a = list(map(int,input().split()))
L = [0]*n
R = [0]*n
cnt=0
for i in range(n):
    L[i] = i+a[i]
    R[i] = i-a[i]
z1=Counter(L)
z2=Counter(R)
cnt=0
for k1,v1 in z1.items():
    v2 = z2[k1]
    cnt += v1*v2
print(cnt)

Verdicts: Wrong Answer

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

Submission attempts (in order):
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 (i2-i1) == (a2+a1):
            count += 1
    i += 1

print(count)



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)



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

count = 0
for i in range(n):
    for j in range(i+1,n):
        if (j-i) == abs(a_l[j-1] - a_l[i-1]):
            count += 1

print(count)



n = int(input())
a_l = list(map(int,input().split()))
ia = list(enumerate(a_l))

x_dict = {}
y_dict = {}
for i, a in ia:
    x = i+a
    y = i-a
    if x in x_dict:
        x_dict[x] += 1
    else:
        x_dict[x] = 1
    if y in y_dict:
        y_dict[y] += 1
    else:
        y_dict[y] = 1

count = 0
for xkey in x_dict.keys():
    if xkey in y_dict:
        count += x_dict[xkey] * y_dict[xkey]

print(count)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

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

Submission attempts (in order):
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)

from collections import defaultdict

n=int(input())
A=list(map(int,input().split()))
B=defaultdict(int)
res=0

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

print(res)

Verdicts: Runtime Error

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

Submission attempts (in order):
# coding: utf-8
import sys
sysread = sys.stdin.readline
sys.setrecursionlimit(10**7)

def run():
    N = int(input())
    A = list(map(int, sysread().split()))

    import numpy as np
    N = 200000
    A = np.random.randint(1, N, size=N)

    A = [(idx, val) for idx, val in enumerate(A, 1) if val < N]

    ret = 0
    store = [0] * N
    for idx, val in A:
        ret += store[idx - val]
        try:
            store[idx + val] += 1
        except:
            continue
    print(ret)

if __name__ == "__main__":
    run()

# coding: utf-8
import sys
sysread = sys.stdin.readline

def run():
    N = int(input())
    A = list(map(int, sysread().split()))


    A = [(idx, val) for idx, val in enumerate(A, 1) if val < N]

    ret = 0
    store = [0] * N
    for idx, val in A:
        if idx - val > 0:
            ret += store[idx - val]
        try:
            store[idx + val] += 1
        except:
            continue
    print(ret)

if __name__ == "__main__":
    run()

Verdicts: Wrong Answer

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

Submission attempts (in order):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
count = 0
b = []
c = []

for i in range(n):
    b.append(a[i]+i)
    c.append(i-a[i])
t = Counter(b)
for s in c:
    count += t[s]
    print(t[s],s)
print(t,1)
print(count)

from collections import Counter
n = int(input())
a = list(map(int,input().split()))
count = 0
b = []
c = []

for i in range(n):
    b.append(a[i]+i)
    c.append(i-a[i])
t = Counter(b)
for s in c:
    count += t[s]
    print(t[s],s)
print(t,1)
print(count)

from collections import Counter
n = int(input())
a = list(map(int,input().split()))
count = 0
b = []
c = []

for i in range(n):
    b.append(a[i]+i)
    c.append(i-a[i])
t = Counter(c) 
for s in b:
    count += t[s]

print(count)

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
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)


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]
    y = i + 1 + A[i]
    if y < 10 ** 7:
        dp[y] += 1

print(ans)


Verdicts: Runtime Error

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

Submission attempts (in order):
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)


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
fsu = []
for d in su:
    fsu.append([d, su[d]])
fsu.sort()
fsd = []
for d in sd:
    fsd.append([d, sd[d]])
fsd.sort()
s = 0
i1 = len(fsu) - 1
j1 = 0
#print(fsu)
#print(fsd)
while (i1 >= 0 and j1 <= len(fsd)-1):
    if (fsu[i1][0] + fsd[j1][0] == 0):
                s+=fsu[i1][1] * fsd[j1][1]
                i1-=1
    elif (fsu[i1][0] + fsd[j1][0] > 0):
                i1-=1
    elif (fsu[i1][0] + fsd[j1][0] < 0):
                j1+=1

print(s)


Verdicts: Runtime Error

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

Submission attempts (in order):
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()


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n = int(input())
    a = list(map(int, input().split()))

    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i, ae in enumerate(a):
        d1[i + ae +1] += 1
        d2[i - ae +1] += 1
    r = 0
    for d1e in d1.keys():
        rt = d1[d1e] * d2[d1e]
        r += rt
    print(r)

if __name__ == '__main__':
    main()

Verdicts: Runtime Error

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

Submission attempts (in order):
from collections import Counter

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

q1=[]
q2=[]

for i in range(n):
  q1.append(i+a[i])
  q2.append(i-a[i])

c2=Counter(q2)

ans=0
for i in c1.keys():
  ans+=c2[i]

print(ans)

from collections import Counter

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

l1=[i+a[i] for i in range(n)]
l2=[i-a[i] for i in range(n)]

c2=Counter(l2)

ans=0
for i in l1:
  ans+=c2[i]

print(ans)

Verdicts: Runtime Error

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

Submission attempts (in order):
import numpy as np
n = int(input())
A = np.array(list(map(int,input().split())))
B = np.array([i+1 for i in range(n)])
C,D = A+B,B-A
ans = 0
for i in C:
    ans += np.count_nonzero(D==i)


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

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


Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))
B = A

for i in range(N):
    A[i] -= i+1
    B[i] += i+1

from collections import Counter

C = Counter(A)
D = Counter(B)

E = list(C.keys())
F = list(D.keys())


ans = 0
for i in E:
    ans += C[i]*D[i]

print(ans//2)

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

from copy import deepcopy

B = deepcopy(A)

for i in range(N):
    A[i] += i+1
    B[i] = (i+1)-B[i]

from collections import Counter

C = Counter(A)
D = Counter(B)

E = list(C.keys())

ans = 0
for i in E:
    ans += C[i]*D[i]

print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
def main():
    x = int(input())

    i = 0
    while True:
        j = i ** 5
        a1, a2 = x + j, x - j

        p = a1 ** (1 / 5)
        q = a2 ** (1 / 5) if a2 >= 0 else abs(a2) ** (1 / 5) * -1

        f = int(p) - p == 0
        g = int(q) - q == 0
        if f:
            print(int(p), i)
            break
        if g:
            print(int(q), -1 * i)
            break

        i += 1


if __name__ == '__main__':
    main()


def main():
    from collections import defaultdict
    n, *a = map(int, open(0).read().split())
    d = defaultdict(lambda: [0, 0])

    ans = 0
    for i, x in enumerate(a, 1):
        d[i + x][0] += 1
        d[i - x][1] += 1
        ans += d[i + x][1] + d[i - x][0]

    print(ans)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

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

Submission attempts (in order):
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)

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

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)

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)

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)

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)

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)

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)

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
import numpy as np
n=int(input())
a=list(map(int,input().split()))
a1=[]
a2=[]
for i in range(n):
  a1.append(i+1-a[i])
for i in range(n):
  a2.append(i+1+a[i])
count=0
p=0
q=1
while q==n:
  if a1[q]==a2[p]:
    count+=1
  p+=1
  if p==q:
    p=0
    q+=1
print(count)

from collections import Counter
n=int(input())
alist=list(map(int,input().split()))
a1=[]
a2=[]
for i,a in enumerate(alist):
  a2.append(i-a)
  a1.append(i+a)
aa=Counter(a2)
count=0
for k in a1:
  count+=aa.get(k,0)
print(count)

Verdicts: Wrong Answer

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

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

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

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



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

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

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



Verdicts: Wrong Answer

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

Submission attempts (in order):
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)

from collections import defaultdict
n = int(input())
a_ls = list(map(int, input().split()))
L_dict = defaultdict(int)
for i in range(n):
    Li = a_ls[i] + i + 1
    L_dict[Li] += 1

ans = 0
for j in range(n):
    Rj = j + 1 - a_ls[j]
    ans += L_dict[Rj]
print(ans)


Verdicts: Runtime Error

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

Submission attempts (in order):
import sys
import numpy as np
from numba import jit
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N = int(input())
    H = np.array(input().split(), np.int64)
    A = np.arange(1,N+1)
    B = np.arange(1,N+1)
    A = A + H
    B = B - H
    ans = 0

    @jit(nopython=True)
    def aa(i):
        return N - i - np.count_nonzero(B[i:] - A[:-i])
    for i in range(1,N):
        ans += aa(i)
    print(ans)



if __name__ == '__main__':
    main()

import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    L = defaultdict(int)
    R = defaultdict(int)
    for i in range(N):
        L[i+1+A[i]] += 1
        R[i+1-A[i]] += 1
    ans = 0
    for key, value in L.items():
        ans += value*R[key]
    print(ans)


if __name__ == '__main__':
    main()


Verdicts: Time Limit Exceeded

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

Submission attempts (in order):
N = int(input())

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

L = {}
R = {}

for i in range(N):
  t = A[i]+i
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  s = i - A[i]
  if s in R:
    R[s] += 1
  else:
    R[s] = 1  
print(L,R)
ans = 0
for i in range(N):
  t = A[i]+i
  
  if t in R.keys():
    ans += R[t]
    print(t,R[t])
print(ans)

N = int(input())
 
A = list(map(int, input().split()))
 
L = {}
R = {}
 
for i in range(N):
  t = A[i]+i
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  s = i - A[i]
  if s in R:
    R[s] += 1
  else:
    R[s] = 1  
#print(L,R)
ans = 0
for i in range(N):
  t = A[i]+i
  
  if t in R.keys():
    ans += R[t]
    #print(t,R[t])
print(ans)

Verdicts: Wrong Answer

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

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

from collections import Counter

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

for i in range(1,N+1):
    sumlist.append(i+alist[i])
sumlist.sort()
sum_cnt = Counter(sumlist)
ans = 0

for i in range(1, N+1):
    diff = i - alist[i]
    if diff in sum_cnt:
        ans += sum_cnt[diff]
print(ans)

Verdicts: Runtime Error

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

Submission attempts (in order):
n=int(input())
A=list(map(int,input().split()))
L,R={},{}
for i,a in enumerate(A):
  l,r = i-a,i+a
  if l in L: L[l]=0
  if r in R: R[r]=0
  L[l]+=1
  R[r]+=1

count = 0
for x in L:
  if x not in R: continue
  count += L[x]*R[x]
print(count)

n=int(input())
A=list(map(int,input().split()))
L,R={},{}
for i,a in enumerate(A):
  l,r = i-a,i+a
  if l not in L: L[l]=0
  if r not in R: R[r]=0
  L[l]+=1
  R[r]+=1

count = 0
for x in L:
  if x not in R: continue
  count += L[x]*R[x]
print(count)

Verdicts: Runtime Error

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

Submission attempts (in order):
n=int(input())
y=list(map(int,input().split()))
from collections import Counter
lhs=Counter([j+y[j] for j in range(n)])
rhs=Counter([j-y[j] for j in range(n)])
count=0
for i in lhs:
   if i in rhs:
      count+=lhs[i]+rhs[i]

print(count)

n=int(input())
y=list(map(int,input().split()))
from collections import Counter
lhs=Counter([j+y[j] for j in range(n)])
rhs=Counter([j-y[j] for j in range(n)])
count=0
for i in lhs:
   if i in rhs:
      count+=lhs[i]*rhs[i]

print(count)


Verdicts: Wrong Answer

Accepted