ZhenlongDai/ACPR huggingface dataset:
Problem: p03400
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    D, X = map(int, input().split())
    A = [int(input()) for _ in range(N)]

    c = 0
    for a in A:
        i = 0
        while i * a <= D:
            c += 1
            i += 1

    print(c + X)


if __name__ == '__main__':
    main()


Failing test case input:
3
4 2
1
3
10

Expected output:
9


Actual output:
10


Fixed submission (verdict: Accepted):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    D, X = map(int, input().split())
    A = [int(input()) for _ in range(N)]

    c = 0
    for a in A:
        i = 0
        while (i * a) + 1 <= D:
            c += 1
            i += 1

    print(c + X)


if __name__ == '__main__':
    main()

Problem: p03400
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
d,x = map(int,input().split())
ans = 0
for i in range(n):
  num = int(input())
  ans += (num-1)
print(ans)

Failing test case input:
5
30 29
26
18
81
5
10

Expected output:
43


Actual output:
135


Fixed submission (verdict: Accepted):
from math import ceil
n = int(input())
d,x = map(int,input().split())
ans = 0
for i in range(n):
  num = int(input())
  ans += ceil(d/num)
print(ans+x)

Problem: p03400
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
D,X=map(int,input().split())
A=list()
chocolate=0
for i in range(N):
    A.append(int(input()))
for i in range(D):
    for j in A:
        if (i+1)%j==1:
            chocolate+=1
print(chocolate+X)

Failing test case input:
2
16 44
1
19

Expected output:
61


Actual output:
45


Fixed submission (verdict: Accepted):
N=int(input())
D,X=map(int,input().split())
A=list()
chocolate=0
for i in range(N):
    A.append(int(input()))
for i in range(D):
    for j in A:
        if ((i+1)%j==1)|(j==1):
            chocolate+=1
print(chocolate+X)

Problem: p03400
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
p = int(input())
dr = input().split(' ')
d, r = int(dr[0]), int(dr[1])


for i in range(p):
    nb = int(input())
    if nb == 1:
        r += d
    else:
        r += d

print(r)

Failing test case input:
3
10 1
2
4
10

Expected output:
10


Actual output:
31


Fixed submission (verdict: Accepted):
p = int(input())
dr = input().split(' ')
d, r = int(dr[0]), int(dr[1])


for i in range(p):
    nb = int(input())
    if nb == 1:
        r += d
    else:
        if d % nb == 0:
            r += d/nb
        else:
            r += (d

print(int(r))
Problem: p03400
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
d,x = list(map(int, input().split()))

a=[]
for i in range(n):
    a.append(int(input()))

m=[]
for i in range(n):
    if d%a[i]==0:
        m.append(int(d/a[i]))
    else:
        m.append(int(d/a[i]+1))
    print('m=',m[i])

s=0
for i in range(n):
    s += m[i]
s += x

print(s)


Failing test case input:
3
10 1
2
4
10

Expected output:
10


Actual output:
m= 5
m= 3
m= 1
10


Fixed submission (verdict: Accepted):
n=int(input())
d,x = list(map(int, input().split()))

a=[]
for i in range(n):
    a.append(int(input()))

m=[]
for i in range(n):
    if d%a[i]==0:
        m.append(int(d/a[i]))
    else:
        m.append(int(d/a[i]+1))

s=0
for i in range(n):
    s += m[i]
s += x

print(s)

Problem: p03400
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
d,x = map(int,input().split())
a = [int(input()) for i in range(n)]
ans = x
for i in range(n):
  for j in range(d+1):
    if j % a[i] == 1 and j*a[i] <= d:
      ans += 1
    elif a[i] == 1:
      ans += 1

print(ans)

Failing test case input:
3
1 1
2
5
15

Expected output:
4


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
d,x = map(int,input().split())
a = [int(input()) for i in range(n)]
ans = x
for i in range(n):
  for j in range(1,d+1):
    if j % a[i] - 1 == 0:
      ans += 1
    elif a[i] == 1:
      ans += 1

print(ans)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections
N = int(input())
A = list(map(int,input().split()))


pp =[]
pm = []
all_set = set()
for i in range(N):

    pp.append(i + A[i])
    pm.append( i - A[i])

count = 0
c = collections.Counter(pp)

for i in range(N):
    count += c[pm[i]] 
    print(c[pm[i]])

    
    

print(count)

Failing test case input:
32
3 1 4 1 5 9 3 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 17 5

Expected output:
23


Actual output:
0
0
0
1
0
0
1
0
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
0
2
0
2
0
2
2
23


Fixed submission (verdict: Accepted):
import collections
N = int(input())
A = list(map(int,input().split()))


pp =[]
pm = []
all_set = set()
for i in range(N):

    pp.append(i + A[i])
    pm.append( i - A[i])

count = 0
c = collections.Counter(pp)

for i in range(N):
    count += c[pm[i]] 
    

    
    

print(count)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")


def main():
    N = int(input())
    A_1 = list(map(int, input().split()))
    B_l = [1 - A_1[0]]

    sum = 0
    
    for i in range(1, N):
        if A_1[i] in B_l:
            sum += 1

        B_l = list(map(lambda x: x+1, B_l))
        B_l.append(0 - A_1[i])

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


Failing test case input:
32
3 1 4 2 5 9 4 6 4 3 5 8 9 7 9 3 4 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Expected output:
24


Actual output:
16


Fixed submission (verdict: Accepted):
import logging
import collections

logging.basicConfig(level=logging.INFO, format="%(message)s")


def main():
    N = int(input())
    A_i = list(map(int, input().split()))
    
    Ai_plu_i = collections.Counter([i + 1 + A_i[i] for i in range(N)])
    ans = sum([Ai_plu_i.get(j + 1 - A_i[j], 0) for j in range(N)])
    
    print(ans)
    
if __name__ == "__main__":
    main()

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

d1 = []
d2 = []

for ind,i in enumerate(A):
    d1.append(ind+i+1)
    d2.append(abs(ind-i+1))
    
c1 = Counter(d1)
c2 = Counter(d2)

ans = 0

for i in range(0,10**5+1):
    ans += (c1[i]*c2[i])

print(ans)

Failing test case input:
32
2 1 4 1 5 9 2 6 5 3 5 8 9 7 9 2 2 4 8 4 6 4 6 4 3 3 11 3 4 7 17 8

Expected output:
21


Actual output:
23


Fixed submission (verdict: Accepted):
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
 
d1 = []
d2 = []
 
for ind,i in enumerate(A):
    d1.append(ind+i)
    d2.append(ind-i)
    
c1 = Counter(d1)
c2 = Counter(d2)

ans = 0
for i in c1.keys():
    ans += (c1[i]*c2[i])
 
print(ans)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys

N = int(sys.stdin.readline().rstrip())
As = list(map(int, sys.stdin.readline().rstrip().split()))

ll = [0] * N
lr = [0] * N
for i in range(N):
    ll[i] = i + 1 + As[i]
    lr[i] = i + 1 - As[i]

print(ll, lr)

ans = 0
for l in ll:
    ans += lr.count(l)

print(ans)


Failing test case input:
6
2 5 3 2 3 1

Expected output:
0


Actual output:
[3, 7, 6, 6, 8, 7] [-1, -3, 0, 2, 2, 5]
0


Fixed submission (verdict: Accepted):
import sys
from collections import Counter

N = int(sys.stdin.readline().rstrip())
As = list(map(int, sys.stdin.readline().rstrip().split()))

ll = [0] * N
lr = [0] * N
for i, a in enumerate(As):
    ll[i] = i + a
    lr[i] = i - a

cl = Counter(ll)
cr = Counter(lr)

ans = 0
for l in cl.keys():
    ans += cl[l] * cr[l]

print(ans)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

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







Ap = [A[i]+i for i in range(len(A))]
Am = [i-A[i] for i in range(len(A))]

S = set(Ap) & set(Am)

Cp = Counter(Ap)
Cm = Counter(Am)

cnt = 0
for i in S:
  cnt += Cp[i]*Cm[i]

Failing test case input:
6
2 6 6 1 3 1

Expected output:
2


Actual output:

Fixed submission (verdict: Accepted):
from collections import Counter

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







Ap = [A[i]+i for i in range(len(A))]
Am = [i-A[i] for i in range(len(A))]

S = set(Ap) & set(Am)

Cp = Counter(Ap)
Cm = Counter(Am)

cnt = 0
for i in S:
  cnt += Cp[i]*Cm[i]
  
print(cnt)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):



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

    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    ans = 0

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

        if diff in d.keys():
            ans += d[diff]

        summed = i + a[i]

        if diff in d.keys():
            d[summed] += 1
        else:
            d[summed] = 1

    print(ans)


if __name__ == '__main__':
    main()


Failing test case input:
32
2 1 4 1 5 9 2 6 5 3 5 8 9 7 9 2 2 4 8 4 6 2 6 4 3 3 8 6 4 7 17 5

Expected output:
23


Actual output:
19


Fixed submission (verdict: Accepted):



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

    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    ans = 0

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

        summed = i + a[i]
        d[summed] += 1

    print(ans)


if __name__ == '__main__':
    main()
Problem: p02691
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]
print(A)







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


Failing test case input:
32
3 1 4 1 8 11 8 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 1 8 3 3 7 2 14

Expected output:
19


Actual output:
[3, 1, 4, 1, 8, 11, 8, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 1, 8, 3, 3, 7, 2, 14]
19


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(i) for i in input().split()]






counter = 0
dic = {}
for j in range(N):
    if j-A[j] in dic:
        counter += dic[j - A[j]]
    if j + A[j] in dic:
        dic[j+A[j]] += 1
    else:
        dic[j+A[j]] = 1
print(counter)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=list(map(int, input().split()))
D={}
E={}
for i in range(N):
  a=i+A[i]
  b=i+A[i]
  D.setdefault(a,0)
  E.setdefault(b,0)
  D[a]+=1
  E[b]+=1
ans=0
for i in D.keys():
  if i in E.keys():
    ans+=D[i]*E[i]
print(ans)

Failing test case input:
32
3 1 4 1 5 9 4 6 5 3 5 13 9 3 9 3 2 3 8 5 6 2 6 4 3 3 8 3 2 7 9 5

Expected output:
23


Actual output:
50


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int, input().split()))
D={}
E={}
for i in range(N):
  a=i+A[i]
  b=i-A[i]
  D.setdefault(a,0)
  E.setdefault(b,0)
  D[a]+=1
  E[b]+=1
ans=0
for i in D:
  if i in E:
    ans+=D[i]*E[i]
print(ans)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
32
3 1 4 1 5 9 4 12 5 3 5 8 9 7 9 3 2 4 8 4 6 2 7 4 3 3 8 3 2 7 2 8

Expected output:
28


Actual output:
Counter({23: 3, 19: 2, 21: 2, 18: 2, 26: 2, 27: 2, 30: 2, 3: 1, 2: 1, 6: 1, 4: 1, 9: 1, 14: 1, 10: 1, 13: 1, 12: 1, 15: 1, 20: 1, 29: 1, 28: 1, 34: 1, 36: 1, 32: 1, 39: 1})
Counter({3: 3, 2: 2, 6: 2, 5: 2, 14: 2, 15: 2, 19: 2, 22: 2, -3: 1, 0: 1, -2: 1, -1: 1, -4: 1, -5: 1, 12: 1, 13: 1, 10: 1, 21: 1, 18: 1, 24: 1, 26: 1, 28: 1, 23: 1})
28


Fixed submission (verdict: Accepted):
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)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A_ = list(map(int, input().split()))
A = list()
for i in range(len(A_)):
    if A_[i] < N - 1:
        A.append([i + 1, A_[i]])
ret = 0
for i in range(len(A)-1, -1, -1):
    ind, val = A[i][0], A[i][1]
    B = [a for a in A if a[1] < N - 1 - val]
    for b in B:
        if abs(b[0] - ind) == val + b[1]:
            ret += 1
print(ret)

Failing test case input:
32
3 1 4 1 8 19 8 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 1 8 3 3 7 2 14

Expected output:
20


Actual output:
40


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
L1 = list()
D2 = dict()
ret = 0
for i in range(len(A)):
    num1 = i + 1 - A[i]
    num2 = i + 1 + A[i]
    L1.append(num1)
    if num2 not in D2:
        D2[num2] = 1
    else:
        D2[num2] += 1
ret = 0
retlist = dict()
for l in L1:
    if l in D2.keys():
        ret += D2[l]
print(ret)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections
N = int(input())
A = list(map(int,input().split()))


pp =[]
pm = []
all_set = set()
for i in range(N):

    pp.append(i + A[i])
    pm.append( i - A[i])

count = 0
c = collections.Counter(pp)
print(c)
for i in range(N):
    count += c[pm[i]] 
    print(c[pm[i]])

    
    

print(count)

Failing test case input:
32
2 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 17 5

Expected output:
21


Actual output:
Counter({23: 3, 2: 2, 13: 2, 20: 2, 18: 2, 26: 2, 28: 2, 27: 2, 30: 2, 36: 2, 6: 1, 4: 1, 9: 1, 14: 1, 8: 1, 12: 1, 15: 1, 19: 1, 21: 1, 34: 1, 47: 1})
0
0
0
2
0
0
1
0
0
1
0
0
0
1
0
1
1
1
0
1
1
1
0
1
1
0
2
0
2
0
2
2
21


Fixed submission (verdict: Accepted):
import collections
N = int(input())
A = list(map(int,input().split()))


pp =[]
pm = []
all_set = set()
for i in range(N):

    pp.append(i + A[i])
    pm.append( i - A[i])

count = 0
c = collections.Counter(pp)

for i in range(N):
    count += c[pm[i]] 
    

    
    

print(count)

Problem: p02691
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N=int(input())
a=input().split()
A=[int(number) for number in a]
pluss=[]
minuss=[]
number=1
for a in A:
    plus=a+number
    minus=abs(a-number)
    pluss.append(plus)
    minuss.append(minus)
    number+=1
answer=0
suuji=0
for n in pluss:
    answers=minuss[suuji:]
    answer+=answers.count(n)
    suuji+=1


print(answer)



Failing test case input:
32
3 1 4 1 8 9 4 6 5 3 2 8 9 7 9 3 2 3 8 4 6 2 6 4 6 3 8 3 4 7 2 14

Expected output:
22


Actual output:
24


Fixed submission (verdict: Accepted):
import collections
from collections import Counter
N=int(input())
a=input().split()
A=[int(number) for number in a]
pluss=[]
minuss=[]
number=1
for a in A:
    plus=a+number
    minus=number-a
    pluss.append(plus)
    minuss.append(minus)
    number+=1

m=Counter(minuss)

answer=0
for p in pluss:
    if p in m.keys():
        answer+=m[p]
print(answer)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
box = [[0,0] for i in range(n)]

for i in range(n):
    num = i + 1
    if 0 < num - a[i] < n:
        box[a[i]-num][0] += 1
    if 0 < a[i]+num < n:
        box[a[i]-num][1] += 1
ans = 0
for i in range(n):
    ans += box[i][0] * box[i][1]
print(ans)



Failing test case input:
32
3 1 4 1 8 11 8 6 5 3 5 8 9 7 9 3 2 3 8 2 6 2 6 4 3 3 8 3 3 7 2 14

Expected output:
20


Actual output:
43


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
box = [[0,0] for i in range(n)]

for i in range(n):
    num = i + 1
    if 0 < num - a[i] < n:
        box[num - a[i]][0] += 1
    if 0 < a[i]+num < n:
        box[a[i]+num][1] += 1
ans = 0
for i in range(n):
    ans += box[i][0] * box[i][1]
print(ans)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import defaultdict

N = int(input())	



L = defaultdict(lambda: 0)
R = defaultdict(lambda: 0)
for i, val in enumerate(map(int, input().split())):
  L[i - val] += 1	
  R[i + val] += 1	
  
print(L)
print("===")
print(R)

cnt = 0
for key, val in L.items():
  if key > 0:
    cnt += L[key] * R[key]
    
print(cnt)

Failing test case input:
6
5 2 4 2 8 8

Expected output:
0

Actual output:
defaultdict(<function <lambda> at 0x7f9a3a2804a0>, {-5: 1, -1: 1, -2: 1, 1: 1, -4: 1, -3: 1})
===
defaultdict(<function <lambda> at 0x7f9a3a09c720>, {5: 2, 3: 1, 6: 1, 12: 1, 13: 1})
0


Fixed submission (verdict: Accepted):
from collections import defaultdict
 
N = int(input())	
 


L = defaultdict(lambda: 0)
R = defaultdict(lambda: 0)
for i, val in enumerate(map(int, input().split())):
  L[i - val] += 1	
  R[i + val] += 1	
  
cnt = 0
for key, val in L.items():
  if key > 0:
    cnt += L[key] * R[key]
    
print(cnt)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


import bisect
N = int(input())
A = list(map(int, input().split()))
X = [A[i]+i for i in range(N)]
Y = [j - A[j] for j in range(N)]
ans = 0
X.sort()
for i in range(N):
    ans += bisect.bisect_left(Y,X[i]) - bisect.bisect_right(Y,X[i])
print(ans)




Failing test case input:
32
3 1 4 1 5 9 4 6 5 3 5 13 9 3 9 3 2 3 8 5 6 2 6 4 3 3 8 3 2 7 9 5

Expected output:
23


Actual output:
-28


Fixed submission (verdict: Accepted):


import bisect
N = int(input())
A = list(map(int, input().split()))
X = [A[i]+i for i in range(N)]
Y = [j - A[j] for j in range(N)]
ans = 0
Y.sort()
for i in range(N):
    ans += bisect.bisect_right(Y,X[i]) - bisect.bisect_left(Y,X[i])
print(ans)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())

height = input()
height = height.split()
height = [int(s) for s in height]

count = 0

for i in range(N):
  for j in range(i+1, N):
    if j-1 == height[i] + height[j]:
      count += 1

print(count)

Failing test case input:
32
3 1 4 1 8 9 4 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 3 7 2 1

Expected output:
22


Actual output:
13


Fixed submission (verdict: Accepted):
import collections

N = int(input())

height = input()
height = height.split()
height = [int(s) for s in height]

count = 0


d = dict(collections.Counter([i + height[i] for i in range(N)]))
ans = sum([d.get(i - height[i], 0) for i in range(N)])
print(ans)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections

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







i = [k for k in range(1,N+1)]
j = [k for k in range(1,N+1)]

Li = [i[k]+A[k] for k in range(N)]
Rj = [j[k]-A[k] for k in range(N)]

Li = collections.Counter(Li)

counter = 0
for r in Rj:
    counter += Li[r]

Failing test case input:
6
2 5 3 1 3 1

Expected output:
2


Actual output:

Fixed submission (verdict: Accepted):
import collections

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







i = [k for k in range(1,N+1)]
j = [k for k in range(1,N+1)]

Li = [i[k]+A[k] for k in range(N)]
Rj = [j[k]-A[k] for k in range(N)]

Li = collections.Counter(Li)

counter = 0
for r in Rj:
    counter += Li[r]
print(counter)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
ans = 0

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

print(ans, D)

Failing test case input:
32
3 1 4 1 5 9 4 6 5 3 5 13 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Expected output:
21


Actual output:
21 defaultdict(<class 'int'>, {-2: 0, 4: 1, 1: 0, 3: 1, -1: 0, 7: 1, 5: 1, 0: 0, 10: 1, -3: 0, 15: 1, 11: 1, 2: 0, 14: 2, 13: 1, 6: 0, 16: 1, 25: 1, 22: 1, 21: 2, 24: 3, 19: 2, 27: 2, 20: 0, 17: 0, 29: 2, 28: 2, 23: 0, 35: 1, 31: 2, 37: 2, 40: 1})


Fixed submission (verdict: Accepted):
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
ans = 0

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

print(ans)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter


N = int(input())
A = list(map(int,input().split()))
c=0
l=[]
r=[]
for i in range(N):
    l.append(A[i]+i+1)
    r.append(i+1-A[i])

C=Counter(r)
print(l,r,C)
for x in l:
    c+=C.get(x,0)
print(c)


Failing test case input:
32
3 1 4 1 5 9 4 6 5 3 5 13 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Expected output:
21


Actual output:
[4, 3, 7, 5, 10, 15, 11, 14, 14, 13, 16, 25, 22, 21, 24, 19, 19, 21, 27, 24, 27, 24, 29, 28, 28, 29, 35, 31, 31, 37, 40, 37] [-2, 1, -1, 3, 0, -3, 3, 2, 4, 7, 6, -1, 4, 7, 6, 13, 15, 15, 11, 16, 15, 20, 17, 20, 22, 23, 19, 25, 27, 23, 22, 27] Counter({15: 3, -1: 2, 3: 2, 4: 2, 7: 2, 6: 2, 20: 2, 22: 2, 23: 2, 27: 2, -2: 1, 1: 1, 0: 1, -3: 1, 2: 1, 13: 1, 11: 1, 16: 1, 17: 1, 19: 1, 25: 1})
21


Fixed submission (verdict: Accepted):
from collections import Counter


N = int(input())
A = list(map(int,input().split()))
c=0
l=[]
r=[]
for i in range(N):
    l.append(A[i]+i+1)
    r.append(i+1-A[i])

C=Counter(r)

for x in l:
    c+=C.get(x,0)
print(c)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

import bisect

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


b = [a[i] - i - 1 for i in range(0, n)]
b.sort()
ans = 0
for i in range(n):
    
    r = bisect.bisect_right(b, -b[i] - 2 * i)
    l = bisect.bisect_left(b, -b[i] - 2 * i)
    if l != r:
        ans += r - l
print(ans)


Failing test case input:
32
3 1 4 1 8 9 4 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 4 7 2 14

Expected output:
21


Actual output:
10


Fixed submission (verdict: Accepted):

import bisect

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


b = [a[i] - (1 + i) for i in range(0, n)]
b, idx = zip(*sorted(zip(b, range(1, n + 1))))

ans = 0
for i in range(n):
    
    r = bisect.bisect_right(b, -b[i] - 2 * idx[i])
    l = bisect.bisect_left(b, -b[i] - 2 * idx[i])
    ans += r - l
    
    
print(ans)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections

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

L = [i + A[i] for i in range(N)]
R = [i - A[i] for i in range(N)]

countL = collections.Counter(L)

countR = collections.Counter(R)


print([countL[n] * countR[n] for n in countL.keys()])

Failing test case input:
32
3 1 4 1 5 9 4 6 4 3 5 8 18 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Expected output:
21


Actual output:
[1, 2, 2, 1, 0, 3, 1, 0, 2, 1, 2, 0, 0, 0, 2, 4, 0, 0, 0, 0, 0]


Fixed submission (verdict: Accepted):
import collections

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

L = [i + A[i] for i in range(N)]
R = [i - A[i] for i in range(N)]

countL = collections.Counter(L)

countR = collections.Counter(R)


print(sum([countL[n] * countR[n] for n in countL.keys()]))
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
res = 0
dict = {}
dict[a[0]] = 1
for i in range(1,n):
  res += dict.get(abs(a[i]-i-1),0)
  dict[a[i]+i+1] = dict.get(a[i]+i+1,0) + 1
print(res)

Failing test case input:
32
3 1 4 1 5 9 4 12 4 3 5 8 18 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Expected output:
23


Actual output:
27


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
res = 0
dict = {}
dict[a[0]+1] = 1
for i in range(1,n):
  res += dict.get(i+1-a[i],0)
  dict[a[i]+i+1] = dict.get(a[i]+i+1,0) + 1
print(res)

Problem: p02691
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from bisect import bisect_left, bisect_right

N = int(input())

A = list(map(int, input().split()))
Ap = [i - A[i] for i in range(N)]
Ap.sort()

print(Ap)
ans = 0
for i in range(N):
	ans += bisect_right(Ap, i + A[i]) - bisect_left(Ap, i + A[i])

print(ans)

Failing test case input:
32
2 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 17 5

Expected output:
21


Actual output:
[-4, -2, -2, -1, 0, 1, 2, 3, 3, 3, 4, 5, 5, 6, 6, 10, 12, 13, 14, 14, 14, 15, 16, 18, 19, 19, 21, 22, 22, 24, 26, 26]
21


Fixed submission (verdict: Accepted):
from bisect import bisect_left, bisect_right

N = int(input())

A = list(map(int, input().split()))
Ap = [i - A[i] for i in range(N)]
Ap.sort()

ans = 0
for i in range(N):
	ans += bisect_right(Ap, i + A[i]) - bisect_left(Ap, i + A[i])

print(ans)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
count = 0
d={}
for i in range(n):
    if i - a[i] in d:
        count+=d[i - a[i]]
    if i + a[i] in d:
        d[i+a[i]] + 1
    else:
        d[i+a[i]] = 1

print(count)

Failing test case input:
6
2 3 6 1 3 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
count = 0
d={}
for i in range(n):
    if i - a[i] in d:
        count+=d[i - a[i]]
    if i + a[i] in d:
        d[i+a[i]] += 1
    else:
        d[i+a[i]] = 1

print(count)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())

height = input()
height = height.split()
height = [int(s) for s in height]

count = 0

iAi = [0] * N
jAj = [0] * N

for i in range(N):
    iAi[i] = i+1 + height[i]
    jAj[i] = i+1 -height[i]

for i in range(N):
    if jAj.count(iAi[i]) >= 1:
        count +=1


print(count)

Failing test case input:
32
3 1 4 1 5 9 4 6 4 3 5 8 18 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Expected output:
21


Actual output:
14


Fixed submission (verdict: Accepted):
import collections

N = int(input())

height = input()
height = height.split()
height = [int(s) for s in height]

count = 0


d = dict(collections.Counter([i + height[i] for i in range(N)]))
ans = sum([d.get(i - height[i], 0) for i in range(N)])
print(ans)

Problem: p02691
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

d = [0]*N
ans = 0
for i in range(N):
    a = A[i]
    l,r = i+a, i-a
    if l < N:
        d[l] += 1
    if r >= 2:
        d[r] += 1
    if r in d:
        ans += d[r]

print(ans)


Failing test case input:
32
3 1 4 1 5 9 4 12 4 3 5 8 9 7 9 3 2 4 8 4 6 2 7 4 3 3 8 3 2 7 2 8

Expected output:
28


Actual output:
7


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

d = [0]*N
ans = 0
for i in range(N):
    a = A[i]
    l,r = i+a, i-a
    if 0 <= l < N:
        d[l] += 1
    if 0 <= r < N:
        ans += d[r]

print(ans)

Problem: p02691
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import defaultdict

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

cnt = 0
d = defaultdict(int)
for key in a:
    d[key] += 1

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

print(cnt)


Failing test case input:
32
3 1 1 1 5 9 7 6 5 3 5 8 9 7 9 3 2 1 16 4 6 2 1 4 1 3 8 4 2 8 3 8

Expected output:
33


Actual output:
77


Fixed submission (verdict: Accepted):
from collections import defaultdict

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

cnt = 0
d = defaultdict(int)

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

print(cnt)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())

A = list(map(int, input().split()))
S = [-A[i] for i in range(N)]

D = {}
for i in range(N):
    if A[i] in D:
        D[A[i]][0] += 1
    else:
        D[A[i]] = [1, 0]
    if S[i] in D:
        D[S[i]][1] += 1
    else:
        D[S[i]] = [0, 1]
cnt = 0
for i in D:
    cnt += D[i][0] * D[i][1]
print(cnt)

Failing test case input:
6
2 3 6 1 3 1

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())

A = list(map(int, input().split()))
S = [-A[i] for i in range(N)]

for i in range(N):
    A[i] += i
    S[i] += i
D = {}
for i in range(N):
    if A[i] in D:
        D[A[i]][0] += 1
    else:
        D[A[i]] = [1, 0]
    if S[i] in D:
        D[S[i]][1] += 1
    else:
        D[S[i]] = [0, 1]
cnt = 0
for i in D:
    cnt += D[i][0] * D[i][1]
print(cnt)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
B = [0] * (n)
C = [0] * (n)
kouho = defaultdict(int)
ans = 0
for i in range(n):
    kouho[A[i] - i] += 1
    ans += kouho[A[i] + i]
print(ans)


Failing test case input:
32
3 1 4 1 5 9 4 9 5 3 5 8 9 7 13 3 2 3 8 4 6 2 6 4 3 3 3 3 2 7 2 5

Expected output:
25


Actual output:
1


Fixed submission (verdict: Accepted):
from collections import defaultdict

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

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

print(ans)

Problem: p02691
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
H = list(map(int, input().split()))
H2 = [0]*n
H3 = [0]*n

for i in range(n):
  H2[i] = H[i] - i 
  H3[i] = H[i] + i
  

import collections 
c2 = collections.Counter(H2)
c3 = collections.Counter(H3)

ans = 0
for k2 in c2:
  val = -k2
  if val in c3:
    ans += c3[val]
print(ans)  



Failing test case input:
32
3 1 4 1 8 11 4 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 3 7 2 14

Expected output:
19


Actual output:
14


Fixed submission (verdict: Accepted):
n = int(input())
H = list(map(int, input().split()))
H2 = [0]*n
H3 = [0]*n

for i in range(n):
  H2[i] = H[i] - i 
  H3[i] = - (H[i] + i)



import collections 
c2 = collections.Counter(H2)
c3 = collections.Counter(H3)

ans = 0
for k2 in c2:
  if k2 in c3:
    ans += c3[k2] * c2[k2]
print(ans)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

check = {}
ans = 0

for i in range(N):
    x = i - A[i]
    y = A[i] + i
    ans += check.get(x, 0)
    check.setdefault(y, 0)
    check[y] += 1

print(ans)
print(check)

Failing test case input:
32
3 1 4 1 5 9 4 9 5 3 5 8 9 7 13 3 2 3 1 4 6 2 6 4 3 3 3 3 2 7 2 5

Expected output:
24


Actual output:
24
{3: 1, 2: 1, 6: 1, 4: 1, 9: 1, 14: 1, 10: 1, 16: 1, 13: 1, 12: 1, 15: 1, 19: 2, 21: 1, 20: 2, 27: 3, 18: 2, 23: 2, 26: 1, 28: 2, 29: 1, 30: 2, 36: 2, 32: 1}


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

check = {}
ans = 0

for i in range(N):
    x = i - A[i]
    y = A[i] + i
    ans += check.get(x, 0)
    check.setdefault(y, 0)
    check[y] += 1

print(ans)

Problem: p02691
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):


from pprint import pprint
from collections import deque, defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float("inf")

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

min_diff = 1
max_diff = N - 1

d = defaultdict(list)
for i in range(N):
    key = i + 1 + A[i]
    d[key].append(i + 1)


count = 0
for diff in range(min_diff, max_diff + 1):
    count += len(d[diff])

print(count)


Failing test case input:
32
3 1 4 1 5 14 4 6 5 3 5 6 9 7 9 3 2 3 8 4 6 2 6 2 3 3 8 3 2 7 2 5

Expected output:
20


Actual output:
28


Fixed submission (verdict: Accepted):


from pprint import pprint
from collections import deque, defaultdict
import math
import itertools
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float("inf")

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

min_diff = 1
max_diff = N - 1

dl = defaultdict(list)
dr = defaultdict(list)
for i in range(1, N + 1):
    key = i + A[i-1]
    dl[key].append(i)
    key = i - A[i-1]
    if key > 0:
        dr[key].append(i)



count = 0
for diff in range(min_diff, max_diff + 1):
    count += len(dl[diff]) * len(dr[diff])
print(count)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections
import sys
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    ans = 0
    c = collections.Counter()

    for i in range(n):
        ans += c[i + 1 - A[i]]
        c[i + 1 + A[i]] += 1

    print(c)

    print(ans)


if __name__ == '__main__':
    main()


Failing test case input:
32
3 1 4 1 8 9 4 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 4 7 2 14

Expected output:
21


Actual output:
Counter({24: 3, 13: 2, 14: 2, 21: 2, 19: 2, 27: 2, 29: 2, 28: 2, 33: 2, 4: 1, 3: 1, 7: 1, 5: 1, 15: 1, 11: 1, 16: 1, 20: 1, 22: 1, 35: 1, 31: 1, 37: 1, 46: 1})
21


Fixed submission (verdict: Accepted):
import collections
import sys
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    ans = 0
    c = collections.Counter()

    for i in range(n):
        ans += c[i + 1 - A[i]]
        c[i + 1 + A[i]] += 1

    print(ans)


if __name__ == '__main__':
    main()

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
plus = dict()
minus = dict()
for i in range(n):
  if (a[i]+i+1) in plus:
    plus[a[i]+i+1] += 1
  else:
    plus[a[i]+i+1] = 1
  if (a[i]+i+1) in minus:
    minus[i+1-a[i]] += 1
  else:
    minus[i+1-a[i]] = 1
c = 0
for v in plus.keys():
  if v in minus:
    c += plus[v] * minus[v]
print(c)

Failing test case input:
32
2 1 4 1 5 9 4 13 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 16 3 2 7 2 8

Expected output:
23


Actual output:
16


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
plus = dict()
minus = dict()
for i in range(n):
  num = i+1
  p = a[i] + num
  m = num - a[i]
  if p in plus:
    plus[p] += 1
  else:
    plus[p] = 1
  if (m) in minus:
    minus[m] += 1
  else:
    minus[m] = 1
c = 0
for v in plus.keys():
  if v in minus:
    c += plus[v] * minus[v]
print(c)
Problem: p02691
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

ans = 0

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

Failing test case input:
32
2 2 4 1 5 9 2 6 5 3 5 8 9 7 9 2 2 4 8 3 6 4 6 4 2 3 1 1 4 7 17 5

Expected output:
27


Actual output:
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
0 20
0 21
0 22
0 23
0 24
0 25
0 26
0 27
0 28
0 29
0 30
0 31
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 18
2 19
2 20
2 21
2 22
2 23
2 24
2 25
2 26
2 27
2 28
2 29
2 30
2 31
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
3 15
3 16
3 17
3 18
3 19
3 20
3 21
3 22
3 23
3 24
3 25
3 26
3 27
3 28
3 29
3 30
3 31
4 10
4 11
4 12
4 13
4 14
4 15
4 16
4 17
4 18
4 19
4 20
4 21
4 22
4 23
4 24
4 25
4 26
4 27
4 28
4 29
4 30
4 31
5 15
5 16
5 17
5 18
5 19
5 20
5 21
5 22
5 23
5 24
5 25
5 26
5 27
5 28
5 29
5 30
5 31
6 9
6 10
6 11
6 12
6 13
6 14
6 15
6 16
6 17
6 18
6 19
6 20
6 21
6 22
6 23
6 24
6 25
6 26
6 27
6 28
6 29
6 30
6 31
7 14
7 15
7 16
7 17
7 18
7 19
7 20
7 21
7 22
7 23
7 24
7 25
7 26
7 27
7 28
7 29
7 30
7 31
8 14
8 15
8 16
8 17
8 18
8 19
8 20
8 21
8 22
8 23
8 24
8 25
8 26
8 27
8 28
8 29
8 30
8 31
9 13
9 14
9 15
9 16
9 17
9 18
9 19
9 20
9 21
9 22
9 23
9 24
9 25
9 26
9 27
9 28
9 29
9 30
9 31
10 16
10 17
10 18
10 19
10 20
10 21
10 22
10 23
10 24
10 25
10 26
10 27
10 28
10 29
10 30
10 31
11 20
11 21
11 22
11 23
11 24
11 25
11 26
11 27
11 28
11 29
11 30
11 31
12 22
12 23
12 24
12 25
12 26
12 27
12 28
12 29
12 30
12 31
13 21
13 22
13 23
13 24
13 25
13 26
13 27
13 28
13 29
13 30
13 31
14 24
14 25
14 26
14 27
14 28
14 29
14 30
14 31
15 18
15 19
15 20
15 21
15 22
15 23
15 24
15 25
15 26
15 27
15 28
15 29
15 30
15 31
16 19
16 20
16 21
16 22
16 23
16 24
16 25
16 26
16 27
16 28
16 29
16 30
16 31
17 22
17 23
17 24
17 25
17 26
17 27
17 28
17 29
17 30
17 31
18 27
18 28
18 29
18 30
18 31
19 23
19 24
19 25
19 26
19 27
19 28
19 29
19 30
19 31
20 27
20 28
20 29
20 30
20 31
21 26
21 27
21 28
21 29
21 30
21 31
22 29
22 30
22 31
23 28
23 29
23 30
23 31
24 27
24 28
24 29
24 30
24 31
25 29
25 30
25 31
26 28
26 29
26 30
26 31
27 29
27 30
27 31
27


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

mp = [0] * n

ans = 0

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

print(ans)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
32
3 1 4 1 8 9 6 3 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 2 14

Expected output:
24


Actual output:
0 -3
0 0
0 -2
1 2
0 -4
0 -4
0 0
1 4
1 3
1 6
0 5
1 3
1 3
1 6
0 5
3 12
1 14
1 14
1 10
1 15
1 14
1 19
0 16
1 19
1 21
0 22
2 18
0 24
2 26
0 22
2 28
0 17
Counter({12: 3, 23: 3, 20: 2, 18: 2, 26: 2, 28: 2, 27: 2, 30: 2, 3: 1, 2: 1, 6: 1, 4: 1, 14: 1, 10: 1, 13: 1, 15: 1, 19: 1, 21: 1, 34: 1, 36: 1, 32: 1, 45: 1}) 1
24


Fixed submission (verdict: Accepted):
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)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
A = list(map(int, input().split()))
dic = {}
ans = 0
for i, a in enumerate(A):
    L = i + a
    if L not in dic:
        dic[L] = 1
    else:
        dic[L] += 1
for j in range(n):
    R = j - a
    if R in dic:
        ans += dic[R]
print(ans)

Failing test case input:
32
3 1 4 1 5 9 4 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 4 2 6 3 8

Expected output:
31


Actual output:
20


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int, input().split()))
dic = {}
ans = 0
for i in range(n):
    L = i + A[i]
    if L not in dic:
        dic[L] = 1
    else:
        dic[L] += 1
for j in range(n):
    R = j - A[j]
    if R in dic:
        ans += dic[R]
print(ans)

Problem: p02691
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
goukei = 0

N = int(input()) * (-1)
Ai = list(map(int, input().split()))
number = [j for j in range(0, N, -1)]
new_ai = number + Ai
new_ai = [x + y for (x, y) in zip(Ai, number)]
for i in range(len(Ai)):
    goukei += new_ai.count(-(Ai[i] - 1))
print(goukei)

Failing test case input:
32
3 1 4 1 5 9 4 12 4 3 5 8 18 7 9 3 2 3 8 5 6 2 6 4 3 3 8 3 2 7 9 5

Expected output:
24


Actual output:
32


Fixed submission (verdict: Accepted):
import collections
goukei = 0

N = int(input())
Ai = list(map(int, input().split()))
number = [j for j in range(1, N+1, 1)]
plus_Ai = [x + y for (x, y) in zip(Ai, number)]
minus_Ai = [x - y for (y, x) in zip(Ai, number)]
c = collections.Counter(plus_Ai)

for i in minus_Ai:
    goukei += c[i]
print(goukei)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
from collections import defaultdict
a = list(map(int,input().split()))
ans = 0
dp = defaultdict(int)
for e,i in enumerate(a):
    dp[i+e]+=1
    if i - e >= 0 :ans += dp[i-e]
print(ans)


Failing test case input:
32
2 1 4 1 5 9 2 6 5 3 5 8 9 7 9 2 2 4 8 4 6 4 6 4 3 3 10 3 4 7 17 5

Expected output:
20


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
from collections import defaultdict
a = list(map(int,input().split()))
ans = 0
dp = defaultdict(int)
for e,i in enumerate(a,1):
    if  e - i>= 0 :ans += dp[e-i]
    dp[i+e]+=1
print(ans)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
nump=[0]*n
numm=[0]*n
setm=set()
for i in range(n):
    nump[i]=a[i]+i+1
    numm[i]=i+1-a[i]
    setm.add(i+1-a[i])
ans=0
for i in range(n):
    if nump[i]>n:
        break
    if nump[i] in setm:
        ans+=numm.count(nump[i])
print(ans)


Failing test case input:
32
3 1 4 1 8 9 4 6 5 3 5 8 9 7 9 3 3 3 8 4 6 2 6 4 3 3 8 3 3 7 2 1

Expected output:
24


Actual output:
23


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
num1=[0]*(2*(10**5)+10)
num2=[0]*(2*(10**5)+10)
for i in range(n):
    if a[i]+i+1<2*(10**5)+5:
        num1[a[i]+i+1]+=1
    if a[i]+1<i+1:
        num2[-a[i]+i+1]+=1
ans=0
for i in range(len(num1)):
    ans+=num1[i]*num2[i]
print(ans)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

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

p = [i+Ai for i, Ai in zip(range(1, N+1), A)]
q = [j-Aj for j, Aj in zip(range(1, N+1), A)]

pc = Counter(p)
qc = Counter(q)

r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys())

Failing test case input:
32
3 1 4 1 8 19 8 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 1 8 3 3 7 2 14

Expected output:
20


Actual output:

Fixed submission (verdict: Accepted):
from collections import Counter

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

p = [i+Ai for i, Ai in zip(range(1, N+1), A)]
q = [j-Aj for j, Aj in zip(range(1, N+1), A)]

pc = Counter(p)
qc = Counter(q)

r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys())

print(r)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")


def main():
    N = int(input())
    A_1 = list(map(int, input().split()))
    B_l = [1 - A_1[0]]

    sum = 0
    
    for i in range(1, N):
        if A_1[i] in B_l:
            sum += 1

        B_l = list(map(lambda x: x+1, B_l))
        B_l.append(1 - A_1[i])

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


Failing test case input:
32
3 1 4 1 8 11 4 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 3 7 2 14

Expected output:
19


Actual output:
16


Fixed submission (verdict: Accepted):
import logging
import collections

logging.basicConfig(level=logging.INFO, format="%(message)s")


def main():
    N = int(input())
    A_i = list(map(int, input().split()))
    
    Ai_plu_i = collections.Counter([i + 1 + A_i[i] for i in range(N)])
    ans = sum([Ai_plu_i.get(j + 1 - A_i[j], 0) for j in range(N)])
    
    print(ans)
    
if __name__ == "__main__":
    main()

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import bisect
N = int(input())
A = [0]
A += list(map(int, input().split()))
cnt = 0
L = [- 10 ** 6]
R = [- 10 ** 6]

for i in range(1, N + 1):
    L.append(i + A[i])
    R.append(i - A[i])
L.sort()
print(L)
print(R)
for j in range(1, N + 1):
    x = bisect.bisect_left(L, R[j])
    while R[j] == L[x]:
        cnt += 1
        x += 1
print(cnt)

Failing test case input:
32
3 1 4 1 5 9 4 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 3 8

Expected output:
25


Actual output:
[-1000000, 3, 4, 5, 7, 10, 11, 13, 14, 14, 15, 16, 19, 19, 20, 21, 21, 22, 24, 24, 24, 27, 27, 28, 28, 29, 29, 31, 31, 34, 35, 37, 40]
[-1000000, -2, 1, -1, 3, 0, -3, 3, 2, 4, 7, 6, 4, 4, 7, 6, 13, 15, 15, 11, 16, 15, 20, 17, 20, 22, 23, 19, 25, 27, 23, 28, 24]
25


Fixed submission (verdict: Accepted):
import collections
N = int(input())
A = [0]
A += list(map(int, input().split()))
cnt = 0
L = [- 10 ** 6]
R = [- 10 ** 6]

for i in range(1, N + 1):
    L.append(i + A[i])
    R.append(i - A[i])
c = collections.Counter(L)

for j in range(1, N + 1):
    cnt += c.get(R[j], 0)
print(cnt)

Problem: p02691
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
maxi = 2 * pow(10, 5)
A = [int(i) for i in input().split() if int(i) < maxi]
print(A)










counter = 0

for i in range(len(A)):
    gap = 0
    for j in range(i+1, len(A)):
        gap += 1
        if A[j] + A[i] == gap:
            counter += 1
print(counter)


Failing test case input:
32
3 1 1 1 5 9 7 6 5 3 5 8 9 7 9 3 2 1 16 4 6 2 1 4 1 3 8 4 2 8 3 8

Expected output:
33


Actual output:
[3, 1, 1, 1, 5, 9, 7, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 1, 16, 4, 6, 2, 1, 4, 1, 3, 8, 4, 2, 8, 3, 8]
33


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(i) for i in input().split()]






counter = 0
dic = {}
for j in range(N):
    if j-A[j] in dic:
        counter += dic[j - A[j]]
    if j + A[j] in dic:
        dic[j+A[j]] += 1
    else:
        dic[j+A[j]] = 1
print(counter)
Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
B = [0] * (n)
C = [0] * (n)
kouho = defaultdict(int)
ans = 0
for i in range(n):
    ans += kouho[abs(A[i] - (i + 1))]
    kouho[A[i] + (i + 1)] += 1

print(ans)


Failing test case input:
32
3 1 4 1 5 9 4 9 5 3 5 8 9 7 13 3 2 3 8 4 6 2 6 4 3 3 3 3 2 7 2 5

Expected output:
25


Actual output:
26


Fixed submission (verdict: Accepted):
from collections import defaultdict

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

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

print(ans)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=list(map(int, input().split()))
D={}
E={}
for i in range(N):
  a=i+1+A[i]
  b=i+1-A[i]
  D.setdefault(a-1,0)
  E.setdefault(b-1,0)
  D[a-1]+=1
  E[b-1]+=1
print(D,E)
ans=0
for i in D:
  if i in E:
    ans+=D[i]*E[i]
print(ans)
    

Failing test case input:
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 17 5

Expected output:
23


Actual output:
{3: 1, 2: 1, 6: 1, 4: 1, 9: 1, 14: 1, 8: 1, 13: 2, 12: 1, 15: 1, 19: 1, 21: 1, 20: 2, 23: 3, 18: 2, 26: 2, 28: 2, 27: 2, 34: 1, 30: 2, 36: 2, 47: 1} {-3: 1, 0: 1, -2: 1, 2: 1, -1: 1, -4: 1, 4: 1, 1: 1, 3: 3, 6: 2, 5: 2, 12: 1, 14: 3, 10: 1, 15: 1, 19: 2, 16: 1, 21: 1, 22: 2, 18: 1, 24: 1, 26: 2, 13: 1}
23


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int, input().split()))
D={}
E={}
for i in range(N):
  a=i+A[i]
  b=i-A[i]
  D.setdefault(a,0)
  E.setdefault(b,0)
  D[a]+=1
  E[b]+=1
ans=0
for i in D:
  if i in E:
    ans+=D[i]*E[i]
print(ans)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


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

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

Failing test case input:
32
3 1 4 1 5 9 4 6 5 3 5 13 9 7 9 3 2 3 8 5 6 2 6 4 3 3 8 3 2 7 9 5

Expected output:
22


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
l = list(map(int, input().split()))

d = [0] * n

cnt = 0
for i in range(len(l)):
    if i + l[i] + 1 < n:
        d[i + l[i]] += 1
    if i - l[i] + 1 > 0:
        cnt += d[i - l[i]]
print(cnt)

Problem: p02691
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
from collections import defaultdict
a = list(map(int,input().split()))
ans = 0
dp = defaultdict(int)
for e,i in enumerate(a,1):
    if i - e >= 0 :ans += dp[i-e]
    dp[i+e]+=1
print(ans)


Failing test case input:
32
3 1 4 1 5 14 4 6 5 3 5 6 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 2 5

Expected output:
20


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
from collections import defaultdict
a = list(map(int,input().split()))
ans = 0
dp = defaultdict(int)
for e,i in enumerate(a,1):
    if  e - i>= 0 :ans += dp[e-i]
    dp[i+e]+=1
print(ans)