Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

ac=[False]*N
wa=[0]*N

for _ in range(N):
    p,s=input().split()
    p=int(p)-1

    if s=="AC":
        ac[p]=True
    else:
        if not ac[p]:
            wa[p]+=1

a=0
b=0

for i in range(N):
    if ac[i]:
        a+=1
        b+=wa[i]

print(a,b,sep=" ")


Fixed submission:
n,m=map(int,input().split())

ac=[False]*n
wa=[0]*n

for i in range(m):
    p,s=input().split()
    p=int(p)-1

    if s=="AC":
        ac[p]=True
    else:
        if not ac[p]:
            wa[p]+=1

a=0
b=0

for i in range(n):
    if ac[i]:
        a+=1
        b+=wa[i]

print(a,b,sep=" ")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

ac=[False]*N
wa=[0]*N

for _ in range(N):
    p,s=input().split()
    p=int(p)-1

    if s=="AC":
        ac[p]=True
    else:
        wa[p]+=1

a=0
b=0

for i in range(N):
    if ac[i]:
        a+=1
        b+=wa[i]

print(a,b,sep=" ")


Fixed submission:
n,m=map(int,input().split())

ac=[False]*n
wa=[0]*n

for i in range(m):
    p,s=input().split()
    p=int(p)-1

    if s=="AC":
        ac[p]=True
    else:
        if not ac[p]:
            wa[p]+=1

a=0
b=0

for i in range(n):
    if ac[i]:
        a+=1
        b+=wa[i]

print(a,b,sep=" ")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

ac=[False]*N
wa=[0]*N

for i in range(N):
    p,s=input().split()
    p=int(p)-1

    if s=="AC":
        ac[p]=True
    else:
        wa[p]+=1

a=0
b=0

for i in range(N):
    if ac[i]==True:
        a+=1
        b+=wa[i]

print(a,b,sep=" ")


Fixed submission:
n,m=map(int,input().split())

ac=[False]*n
wa=[0]*n

for i in range(m):
    p,s=input().split()
    p=int(p)-1

    if s=="AC":
        ac[p]=True
    else:
        if not ac[p]:
            wa[p]+=1

a=0
b=0

for i in range(n):
    if ac[i]:
        a+=1
        b+=wa[i]

print(a,b,sep=" ")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

ac=[False]*N
wa=[0]*N

for i in range(N):
    p,s=input().split()
    p=int(p)-1

    if s=="AC":
        ac[p]=True
    else:
        wa[p]+=1

a=0
b=0

for i in range(N):
    if ac[p]==True:
        a+=1
        b+=wa[i]

print(a,b,sep=" ")


Fixed submission:
n,m=map(int,input().split())

ac=[False]*n
wa=[0]*n

for i in range(m):
    p,s=input().split()
    p=int(p)-1

    if s=="AC":
        ac[p]=True
    else:
        if not ac[p]:
            wa[p]+=1

a=0
b=0

for i in range(n):
    if ac[i]:
        a+=1
        b+=wa[i]

print(a,b,sep=" ")
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
num=0
if n<3:
    exit()
for i in range(n):
    if (s[i]=="A") and (s[i+1]=="B") and (s[i+2]=="C"):
        num+=1
print(num)


Fixed submission:
n=int(input())
s=list(input())
num=0
if n<3:
    exit()
for i in range(n-2):
    if (s[i]=="A") and (s[i+1]=="B") and (s[i+2]=="C"):
        num+=1
print(num)

Buggy python submission (verdict: Runtime Error):
s=list(input())
num=0
if n<3:
    exit()
for i in range(n):
    if (s[i]=="A") and (s[i+1]=="B") and (s[i+2]=="C"):
        num+=1
print(num)


Fixed submission:
n=int(input())
s=list(input())
num=0
if n<3:
    exit()
for i in range(n-2):
    if (s[i]=="A") and (s[i+1]=="B") and (s[i+2]=="C"):
        num+=1
print(num)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
num=0
for i in range(n):
    if (s[i]=="A") and (s[i+1]=="B") and (s[i+2]=="C"):
        num+=1
print(num)



Fixed submission:
n=int(input())
s=list(input())
num=0
if n<3:
    exit()
for i in range(n-2):
    if (s[i]=="A") and (s[i+1]=="B") and (s[i+2]=="C"):
        num+=1
print(num)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input(),split())
if a+b+c>=22:
    print("bust")
else:
    print("win")

Fixed submission:
a,b,c=map(int,input().split())
if a+b+c>=22:
    print("bust")
else:
    print("win")
Buggy python submission (verdict: Runtime Error):
I=["SUN","MON","TUE","WED","THU","FRI","SAT"]
for i in range(7):
    if I[i]==input():
        print(7-i)


Fixed submission:
s=input()
I=["SUN","MON","TUE","WED","THU","FRI","SAT"]
for i in range(7):
    if I[i]==s:
        print(7-i)
Buggy python submission (verdict: Runtime Error):
s=sort(input())
if (s[0]==s[1]) and (s[2]==s[3])　and (s[0]!=s[2]):
    print("Yes")
else:
    print("No")


Fixed submission:
s=sorted(input())
if (s[0]==s[1]) and (s[2]==s[3]) and (s[0]!=s[2]):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
s=sorted(input())
if (s[0]==s[1]) and (s[2]==s[3])　and (s[0]!=s[2]):
    print("Yes")
else:
    print("No")


Fixed submission:
s=sorted(input())
if (s[0]==s[1]) and (s[2]==s[3]) and (s[0]!=s[2]):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a,p=map(int,inputy().split())
print((3*a+p)//2)


Fixed submission:
a,p=map(int,input().split())
print((3*a+p)//2)

Buggy python submission (verdict: Runtime Error):
a,p=map(int,inputy().split())
a=3*p
print((a+p)//2)


Fixed submission:
a,p=map(int,input().split())
print((3*a+p)//2)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=str(input())
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
elif s[k-1]=="C":
    s[k-1]="c"
print(s)


Fixed submission:
n,k=map(int,input().split())
s=list(input())
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
elif s[k-1]=="C":
    s[k-1]="c"
print("".join(s))

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=str(input())
if s[k+1]=="A":
    s[k+1]="a"
elif s[k+1]=="B":
    s[k+1]="b"
elif s[k+1]=="C":
    s[k+1]="c"
print(s)


Fixed submission:
n,k=map(int,input().split())
s=list(input())
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
elif s[k-1]=="C":
    s[k-1]="c"
print("".join(s))

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()
if s[k+1]=="A":
    s[k+1]="a"
elif s[k+1]=="B":
    s[k+1]="b"
elif s[k+1]=="C":
    s[k+1]="c"
print(s)


Fixed submission:
n,k=map(int,input().split())
s=list(input())
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
elif s[k-1]=="C":
    s[k-1]="c"
print("".join(s))
Buggy python submission (verdict: Runtime Error):
a,b,t=map(int,input(),split())
print(((t+1/2)//a)*b)


Fixed submission:
a,b,t=map(int,input().split())
print(((t+1//2)//a)*b)
Buggy python submission (verdict: Runtime Error):
for i in range(5):
    I=list(map(int,input()))
k=int(input())
if I[4]-I[0]<=k:
    print("Yay!")
else:
    print(":(")


Fixed submission:
I=[]
for i in range(5):
    I.append(int(input()))
k=int(input())
if I[4]-I[0]<=k:
    print("Yay!")
else:
    print(":(")

Buggy python submission (verdict: Runtime Error):
or i in range(5):
    I=list(map(int,input().split()))
k=int(input())
if max(I)-min(I)<=k:
    print("Yay!")
else:
    print(":(")


Fixed submission:
I=[]
for i in range(5):
    I.append(int(input()))
k=int(input())
if I[4]-I[0]<=k:
    print("Yay!")
else:
    print(":(")

Buggy python submission (verdict: Runtime Error):
for i in range(5):
    I=list(int(input()))
k=int(input())
if max(I)-min(I)<=k:
    print("Yes")
else:
    print("No")


Fixed submission:
I=[]
for i in range(5):
    I.append(int(input()))
k=int(input())
if I[4]-I[0]<=k:
    print("Yay!")
else:
    print(":(")
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
if N>M:
    print(0)
lst=list(map(int,input().split()))
lst.sort()
sum_1=max(lst)-min(lst)
D=[]
for i in range(1,M):
    D.append(lst[i]-lst[i-1])
D.sort(reverse=True)
sum_2=0
for i in range(N-1):
    sum_2+=D[i]
ans=0
ans=sum_1-sum_2
print(ans)


Fixed submission:
N,M=map(int,input().split())
if N>M:
    print(0)
    exit()
lst=list(map(int,input().split()))
lst.sort()
sum_1=max(lst)-min(lst)
D=[]
for i in range(1,M):
    D.append(lst[i]-lst[i-1])
D.sort(reverse=True)
sum_2=0
for i in range(N-1):
    sum_2+=D[i]
ans=0
ans=sum_1-sum_2
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
sum_1=max(lst)-min(lst)
D=[]
for i in range(1,M):
    D.append(lst[i]-lst[i-1])
D.sort(reverse=True)
sum_2=0
for i in range(N-1):
    sum_2+=D[i]
ans=0
ans=sum_1-sum_2
print(ans)


Fixed submission:
N,M=map(int,input().split())
if N>M:
    print(0)
    exit()
lst=list(map(int,input().split()))
lst.sort()
sum_1=max(lst)-min(lst)
D=[]
for i in range(1,M):
    D.append(lst[i]-lst[i-1])
D.sort(reverse=True)
sum_2=0
for i in range(N-1):
    sum_2+=D[i]
ans=0
ans=sum_1-sum_2
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
lst=list(map(int,input().split()))
sort(lst)
sum_1=sum(lst)
D=[]
for i in range(1,M):
    D.append(lst[i]-lst[i-1])
sort(D,reverse=True)
sum_2=0
for i in range(N-1):
    sum_2+=D[i]
ans=0
ans=sum_1-sum_2
print(ans)


Fixed submission:
N,M=map(int,input().split())
if N>M:
    print(0)
    exit()
lst=list(map(int,input().split()))
lst.sort()
sum_1=max(lst)-min(lst)
D=[]
for i in range(1,M):
    D.append(lst[i]-lst[i-1])
D.sort(reverse=True)
sum_2=0
for i in range(N-1):
    sum_2+=D[i]
ans=0
ans=sum_1-sum_2
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
ans=[]
for i in range(n):
    ans.append(int(input()))
ans.sort()
print(min(ans[i+k-1]-ans[i] for j in range(n-k+1)))



Fixed submission:
n,k=map(int,input().split())
ans=[]
for i in range(n):
    ans.append(int(input()))
ans.sort()
print(min(ans[j+k-1]-ans[j] for j in range(n-k+1)))
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k=map(int,input().split())
for i in range(a,b+1):
    if i not in range(a+k,b+1-k):
        print(i)


Fixed submission:
a,b,k=map(int,input().split())
for i in range(a,b+1):
    if i not in range(a+k,b+1-k):
        print(i)
Buggy python submission (verdict: Runtime Error):
N,Y=map(int,input().split())
for x in range(N+1):
    for y in range(N+1):
        z=N-x-y
        if x+y+z==N and 10000*x+5000*y+1000*z==Y:
            print(x,y,z)
            exit()

print(-1,-1,-1,sep=" ")


Fixed submission:
S=list(input())
S[3]="8"
print(*S,sep="")

Buggy python submission (verdict: Runtime Error):
print(len(set(input()for i in range(int(input())))))


Fixed submission:
S=list(input())
S[3]="8"
print(*S,sep="")
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
print((a+b+1)/2))


Fixed submission:
a,b=map(int,input().split())
print((a+b+1)//2)
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N==1:
    print("1")
elif 2<=N<4:
    print("2")
elif 4<=N<8:
    print("4")
elif 8<=N<16:
    print("8")
elif 16<=N<32:
    prnit("16")
elif 32<=N<64:
    print("32")
elif 64<=N<=100:
    print("64")


Fixed submission:
N=int(input())
list=[]
for i in range(7):
    s=2**i
    if s<=N:
        list.append(s)
    else:
        break
print(max(list))

Buggy python submission (verdict: Runtime Error):
N=int(input())
if 1<=N<2:
    print("1")
elif 2<=N<4:
    print("2")
elif 4<=N<8:
    print("4")
elif 8<=N<16:
    print("8")
elif 16<=N<32:
    prnit("16")
elif 32<=N<64:
    print("32")
elif 64<=N<=100:
    print("64")
    


Fixed submission:
N=int(input())
list=[]
for i in range(7):
    s=2**i
    if s<=N:
        list.append(s)
    else:
        break
print(max(list))
Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
num=0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k==S:
                num+=1
print(num)


Fixed submission:
K,S=map(int,input().split())
num=0
for i in range(K+1):
    for j in range(K+1):
        k=S-i-j
        if 0<=k<=K:
            num+=1
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import Counter
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    S = int(input())
    MOD = 10 ** 9 + 7
    if S < 3:
        print(0)
        return
    ans = 0
    fact = [1] * (S+1)
    inv_fact = [1] * (S+1)
    for i in range(1, S+1):
        fact[i] = (fact[i-1] * i) % MOD
    inv_fact[-1] = pow(fact[-1], MOD-2, MOD)
    for i in range(S - 1, -1, -1):
        inv_fact[i] = (inv_fact[i+1] * (i + 1)) % MOD

    # def nCr_mod(n, r, MOD):
    #     return fact[n] * inv_fact[n-r] * inv_fact[r] % MOD

    def dp(l, p, s):
        # if s == S:
        # print(l, p, s)
        if s == 0:
            ret = fact[len(l)]
            for i in Counter(l).values():
                ret *= inv_fact[i]
                ret %= MOD
            # print('count {}'.format(ret))
            return ret
        elif s < 3:
            # print('s = {}, return'.format(s))
            return 0

        l_ = l[:]
        ret = 0
        for i in range(min(p, s), 2, -1):
            l_ = l + [i]
            ret += dp(l_, i, s-i)
            ret %= MOD
        return ret

    print(dp([], S, S))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import Counter
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    S = int(input())
    MOD = 10 ** 9 + 7
    if S < 3:
        print(0)
        return
    a, b, c, ans = 0, 0, 0, 0
    for i in range(3, S):
        d = (a + 1) % MOD
        a = (a + b) % MOD
        b, c = c, d
    print((a + 1) % MOD)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N = int(input())
    C = list(input().strip())
    invC = C[::-1]
    ans = 0
    leftW = C.index('W')
    rightR = N - 1 - invC.index('R')
    while leftW < rightR:
        # print('C={}, invC={}'.format(C, invC))
        # print('leftW={}, rightR={}'.format(leftW, rightR))
        ans += 1
        C[rightR] = 'W'
        invC[-1-rightR] = 'W'
        C[leftW] = 'R'
        invC[-1-leftW] = 'R'
        leftW = C.index('W')
        rightR = N - 1 - invC.index('R')
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N = int(input())
    C = list(input().strip())
    l, r = 0, N-1
    ans = 0
    if 'R' not in C or 'W' not in C:
        print(0)
        return True
    while l < r:
        while C[l] == 'R':
            l += 1
        while C[r] == 'W':
            r -= 1
        if l < r:
            ans += 1
            l += 1
            r -= 1
            
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    K = int(input())
    S = len(input().strip())
    mod = 10 ** 9 + 7
    fact = [1] * (K + S + 1)
    invfact = [1] * (K + S + 1)
    for i in range(K + S):
        fact[i+1] = (fact[i] * (i+1)) % mod
    invfact[-1] = pow(fact[-1], mod-2, mod)
    for i in range(K + S):
        invfact[-2-i] = (invfact[-1-i] * (K + S - i)) % mod
    def nCr(n, r):
        if r == n or r == 0:
            return 1
        r = min(r, n - r)
        return (fact[n] * invfact[n-r] * invfact[r]) % mod
    
    ans = 0
    for i in range(K+1):
        ans += pow(25, i, mod) * nCr(i+S-1, S-1) * pow(26, K-i, mod)
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    K = int(input())
    S = len(input().strip())
    mod = 10 ** 9 + 7
    fact = [1] * (K + S + 1)
    invfact = [1] * (K + S + 1)
    for i in range(K + S):
        fact[i+1] = (fact[i] * (i+1)) % mod
    invfact[-1] = pow(fact[-1], mod-2, mod)
    for i in range(K + S):
        invfact[-2-i] = (invfact[-1-i] * (K + S - i)) % mod
    def nCr(n, r):
        if r == n or r == 0:
            return 1
        r = min(r, n - r)
        return (fact[n] * invfact[n-r] * invfact[r]) % mod
    
    ans = 0
    for i in range(K+1):
        ans += pow(25, i, mod) * nCr(i+S-1, S-1) * pow(26, K-i, mod)
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    from collections import deque
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, M = [int(x) for x in input().strip().split()]
    G = [deque([]) for _ in range(M)]
    for m in range(M):
        a, b = [int(x) for x in input().strip().split()]
        G[a-1].append(b)
        G[b-1].append(a)
    
    vec = [-1] * N
    q = deque([(0, 1)])
    while q:
        cur, np = q.popleft()
        if vec[np-1] == -1:
            vec[np-1] = cur
            for g in G[np-1]:
                q.append((np, g))
    
    if -1 in vec:
        print(vec)
        print('No')
    else:
        print('Yes')
        for v in vec[1:]:
            print(v)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import deque
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, M = [int(x) for x in input().strip().split()]
    G = [deque([]) for _ in range(N)]
    for m in range(M):
        a, b = [int(x) for x in input().strip().split()]
        G[a-1].append(b)
        G[b-1].append(a)
    
    vec = [-1] * N
    q = deque([(0, 1)])
    while q:
        cur, np = q.popleft()
        if vec[np-1] == -1:
            vec[np-1] = cur
            for g in G[np-1]:
                q.append((np, g))
    
    if -1 in vec:
        print('No')
    else:
        print('Yes')
        for v in vec[1:]:
            print(v)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    A, B, C, K = [int(x) for x in input().strip().split()]
    if K <= A + B:
        print(min(K, A))
    else:
        print(A - (K - A - B)))
    
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    A, B, C, K = [int(x) for x in input().strip().split()]
    if K <= A + B:
        print(min(K, A))
    else:
        print(A - (K - A - B))
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    j_Aj = [j-Aj for j, Aj in enumerate(A, start=1)]
    ans = 0
    for i, a in enumerate(A[:-1], start=1):
        if a > N:
            continue
        api = a + i
        temp = Counter(j_Aj[i:])
        ans += temp[api]

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    j_Aj = Counter([j-Aj for j, Aj in enumerate(A, start=1)])
    ans = 0
    for i, a in enumerate(A[:-1], start=1):
        if a > N:
            continue
        ans += j_Aj[a+i]

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    j_Aj = [j-Aj for j, Aj in enumerate(A, start=1)]
    ans = 0
    for i, a in enumerate(A[:-1], start=1):
        if a > N:
            continue
        api = a + i
        temp = Counter(j_Aj[i:])
        ans += temp[api]

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    j_Aj = Counter([j-Aj for j, Aj in enumerate(A, start=1)])
    ans = 0
    for i, a in enumerate(A[:-1], start=1):
        if a > N:
            continue
        ans += j_Aj[a+i]

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    ans = 0
    for i, a in enumerate(A[:-1]):
        if a > N:
            continue
        api = a + i
        for j in range(a-1, N):
            if api + A[j] == j:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    j_Aj = Counter([j-Aj for j, Aj in enumerate(A, start=1)])
    ans = 0
    for i, a in enumerate(A[:-1], start=1):
        if a > N:
            continue
        ans += j_Aj[a+i]

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    import numpy as np
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    S = input().strip()
    Sn = np.array([int(x) for x in S])
    N = len(S)
    ans = 0
    T = Sn.cumsum()
    if N < 4:
        print(0)
        exit()
    for i in range(N-3):
        # print('i = {}'.format(i))
        NT = len(T)
        for j in range(3, NT):
            # print('  j = {}'.format(j))
            if T[j] % 3 == 0:
                if int(S[i:i+j+1]) % 2019 == 0:
                    # print(S[i:i+j+1])
                    ans += 1

        T = T[1:] - T[0]

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    S = [int(x) for x in input().strip()]
    N = len(S)
    ans = 0
    l = [0] * (N + 1)
    p = 1
    cumsum = [0] * (N + 1)
    for i in range(N-1, -1, -1):
        l[i] = (S[i] * p) % 2019
        p *= 10
        p %= 2019
    for i in range(N-1, -1, -1):
        cumsum[i] = (l[i] + cumsum[i+1]) % 2019
    cumsum = Counter(cumsum)
    for i in range(0, 2019):
        ans += (cumsum[i] * (cumsum[i] - 1)) // 2

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    import numpy as np
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    S = input().strip()
    Sn = np.array([int(x) for x in S])
    N = len(S)
    ans = 0
    if N < 4:
        print(0)
        exit()
    for i in range(N-3):
        # print('i = {}'.format(i))
        T = Sn[i:].cumsum()
        NT = len(T)
        for j in range(3, NT):
            # print('  j = {}'.format(j))
            if T[j] % 3 == 0:
                if int(S[i:i+j+1]) % 2019 == 0:
                    # print(S[i:i+j+1])
                    ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    S = [int(x) for x in input().strip()]
    N = len(S)
    ans = 0
    l = [0] * (N + 1)
    p = 1
    cumsum = [0] * (N + 1)
    for i in range(N-1, -1, -1):
        l[i] = (S[i] * p) % 2019
        p *= 10
        p %= 2019
    for i in range(N-1, -1, -1):
        cumsum[i] = (l[i] + cumsum[i+1]) % 2019
    cumsum = Counter(cumsum)
    for i in range(0, 2019):
        ans += (cumsum[i] * (cumsum[i] - 1)) // 2

    print(ans)

if __name__ == '__main__':
    main()