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



from collections import defaultdict
iim = lambda: map(int, input().rstrip().split())
 
def resolve():
    N = int(input())
    A = list(iim())

    ans = 0
    dp = [0]*N
    for i, ai in enumerate(A):
        x = i + ai
        if x < N:
            dp[x] += 1
            print(i)
            print("h1")
            print(dp)
        x = i - ai
        if x >= 0:
            ans += dp[x]
            print("h2")

    print(ans)
resolve()

Failing test case input:
32
3 1 4 1 8 11 7 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:
17


Actual output:
0
h1
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
1
h1
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
h2
2
h1
[0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
3
h1
[0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
h2
4
h1
[0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
5
h1
[0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
6
h1
[0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
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 1, 1, 0, 2, 1, 2, 1, 0, 3, 0, 0, 2, 2, 2, 0, 1, 0]
h2
28
h1
[0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 2, 3, 0, 1, 1, 0, 2, 1, 2, 1, 0, 3, 0, 0, 2, 2, 2, 0, 1, 1]
h2
h2
h2
h2
17


Fixed submission (verdict: Accepted):
from collections import defaultdict
iim = lambda: map(int, input().rstrip().split())
 
def resolve():
    N = int(input())
    A = list(iim())
    ans = 0
    dp = [0]*N
    for i, ai in enumerate(A):
        x = i + ai
        if x < N:
            dp[x] += 1
        x = i - ai
        if x >= 0:
            ans += dp[x]
    print(ans)
resolve()