Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
num = int(input())
d = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13,"n":14,"o":15,"p":16,"q":17,"r":18,"s":19,"t":20,"u":21,"v":22,"w":23,"x":24,"y":25,"z":0}
op_d = {}
for i,j in d.items():
    op_d[j] = i
ans =""
for i in list(range(0,12))[::-1]:
    if(int(num/(26**i)) == 0 ):
        pass
    else:
        ans += op_d[int(num/(26**i))]
        num = num % 26**i;
print(ans)

Fixed submission:
a =input()
if(a.islower()):
    print("a")
else:
    print("A")
Buggy python submission (verdict: Time Limit Exceeded):
_ = input()
l = list(map(int,input().split()))
ans = 1
for i in l:
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
_ = input()
l = list(map(int,input().split()))
flag = True
if 0 in l:
    print(0)
else:
    ans = 1
    for i in l:
        ans *= i
        if ans > 10**18:
            print(-1)
            flag = False
            break
    if(flag):
        print(ans)
Buggy python submission (verdict: Runtime Error):
from decimal import *
import math
A,B = input().split()
A = Decimal(float(A))
B = Decimal(float(B))
print(math.floor(A*B))

Fixed submission:
from collections import defaultdict

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def Fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b

N = int(input())
if(N == 1):
    print(0)
else:
    fact = factorization(N)
    l = [i for i in range(1,1000)]
    count = 0
    d = {}
    for n in fact:
        num = n[1]
        for f in l:
            num -= f
            if(num < 0):
                break
            count += 1
    print(count)
Buggy python submission (verdict: Runtime Error):
import math
A,B,H,M = map(int,input().split())
H_pos = H/12 + M/720
M_pos = M/60
print("{:.9f}".format((A**2+B**2-2*A*B*math.cos(math.radians(360*(H_pos-M_pos)))))**0.5)

Fixed submission:
import math
A,B,H,M = map(int,input().split())
H_pos = H/12 + M/720
M_pos = M/60
deg = 360*(H_pos-M_pos)
if deg > 180: deg = 360-deg
rad = math.radians(deg)
co = math.cos(rad)
print("{:.9f}".format(math.sqrt(A**2+B**2-2*A*B*co)))

Buggy python submission (verdict: Runtime Error):
import math
A,B,H,M = map(int,input().split())
H_pos = H/12 + M/720
M_pos = M/60
print("{:.9f}".format((A**2+B**2-2*A*B*math.cos(math.radians(360*(H_pos-M_pos)))))**0.5)

Fixed submission:
import math
A,B,H,M = map(int,input().split())
H_pos = H/12 + M/720
M_pos = M/60
deg = 360*(H_pos-M_pos)
if deg > 180: deg = 360-deg
rad = math.radians(deg)
co = math.cos(rad)
print("{:.9f}".format(math.sqrt(A**2+B**2-2*A*B*co)))
Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy

def move(A,now):
    return A[now-1]

N, K = map(int,input().split())
A = list(map(int,input().split()))
now = 1
dp  = [deepcopy([0 for _ in range(N)]) for _ in range(N)]
history = []
count = 0
while True:
    history.append(now)
    next_pos = move(A,now)
    if dp[now-1][next_pos-1] == 0:
        dp[now-1][next_pos-1] = 1
    else:
        remainder_array = history[history.index(next_pos):]
        print(remainder_array[(K - history.index(next_pos))%len(remainder_array)])
        break
    if count == K:
        print(now)
        break
    now = next_pos


Fixed submission:
from collections import defaultdict

N,K = map(int,input().split())
A = list(map(int,input().split()))
position = 1
past_path = defaultdict(lambda : -1)
loop_pos = -1

def move(position):
	return A[position-1]

for i in range(1,K+1):
	if(past_path[position] != -1):
		loop_pos = past_path[position]
		break
	past_path[position] = i-1
	position = move(position)

new_past_path = defaultdict(lambda : -1)
for k,v in past_path.items():
	if v >= loop_pos:
		new_past_path[v-loop_pos] = k

if loop_pos != -1:
	print(new_past_path[(K-loop_pos)%len(new_past_path)])
else:
	print(position)
Buggy python submission (verdict: Runtime Error):
_ = input()
 s = input()
place_holder = s[0]
count = 1
for letter in s[1:]:
  if place_holder == letter:
    continue
  else:
    place_holder = letter
    count += 1

Fixed submission:
_ = input()
s = input()
place_holder = s[0]
count = 1
for letter in s[1:]:
    if place_holder == letter:
        continue
    else:
        place_holder = letter
        count +=1
print(count)

Buggy python submission (verdict: Runtime Error):
_ = input()
 s = input()
 place_holder = s[0]
 count = 1
 for letter in s[1:]:
     if place_holder == letter:
         continue
     else:
         place_holder = letter
         count += 1

Fixed submission:
_ = input()
s = input()
place_holder = s[0]
count = 1
for letter in s[1:]:
    if place_holder == letter:
        continue
    else:
        place_holder = letter
        count +=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

prefecture_d = defaultdict(list)

prefecture_num,data_num = map(int,input().split())
py_data = []
for _ in range(data_num):
    prefecture,year = map(int,input().split())
    py_data.append([prefecture,year])
    prefecture_d[prefecture].append(year)
for data in py_data:
    prefecture,year = data
    id = sorted(prefecture_d[prefecture]).index(year) + 1
    print("0"*(6-len(str(prefecture))) + str(prefecture) +"0"*(6-len(str(id))) + str(id))

Fixed submission:
from collections import defaultdict

N,M = map(int,input().split())
question = []
number = {}
counts = defaultdict(int)
for i in range(M):
    city,value = map(int,input().split())
    question.append([i,city,value])
sorted_question = sorted(question,key=lambda x: x[2])
for i,city,value in sorted_question:
    counts[city] += 1
    number[i] = "{:06}{:06}".format(city,counts[city])
for i in range(M):
    print(number[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

prefecture_d = defaultdict(list)

prefecture_num,data_num = map(int,input().split())
py_data = []
for _ in range(data_num):
    prefecture,year = map(int,input().split())
    py_data.append([prefecture,year])
    prefecture_d[prefecture].append(year)
for data in py_data:
    prefecture,year = data
    id = sorted(prefecture_d[prefecture]).index(year) + 1
    print("0"*(6-len(str(prefecture))) + str(prefecture) +"0"*(6-len(str(id))) + str(id))

Fixed submission:
from collections import defaultdict

N,M = map(int,input().split())
question = []
number = {}
counts = defaultdict(int)
for i in range(M):
    city,value = map(int,input().split())
    question.append([i,city,value])
sorted_question = sorted(question,key=lambda x: x[2])
for i,city,value in sorted_question:
    counts[city] += 1
    number[i] = "{:06}{:06}".format(city,counts[city])
for i in range(M):
    print(number[i])
Buggy python submission (verdict: Time Limit Exceeded):
import re

S = input()
T = input()

def func(T,S,count=0):
    if count > len(T):
        return 'No'
    for i,j in zip(T,S):
        if i == j:
            pass
        else:
            new_str = ''
            for letter in T:
                if letter == i:
                    new_str += j
                elif letter == j:
                    new_str += i
                else:
                    new_str += letter
            return func(new_str,S,count+1)
    return 'Yes'

print(func(T,S))

Fixed submission:
S = input()
T = input()

StoT = {}
TtoS = {}

for s,t in zip(S,T):
    if s in StoT.keys():
        if StoT[s] != t:
            print('No')
            exit()
    elif t in TtoS.keys():
        if TtoS[t] != s:
            print('No')
            exit()
    else:
        StoT[s] = t
        TtoS[t] = s
print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
import re

S = input()
T = input()

def func(T,S,count=0):
    if count > len(T):
        return 'No'
    for i,j in zip(T,S):
        if i == j:
            pass
        else:
            new_str = ''
            for letter in T:
                if letter == i:
                    new_str += j
                elif letter == j:
                    new_str += i
                else:
                    new_str += letter
            return func(new_str,S,count+1)
    return 'Yes'

print(func(T,S))

Fixed submission:
S = input()
T = input()

StoT = {}
TtoS = {}

for s,t in zip(S,T):
    if s in StoT.keys():
        if StoT[s] != t:
            print('No')
            exit()
    elif t in TtoS.keys():
        if TtoS[t] != s:
            print('No')
            exit()
    else:
        StoT[s] = t
        TtoS[t] = s
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
ignore = input()
num = map(int,input().split())
count = 0
while True:
    if(sum([0 if i%2 == 0 else 1 for i in num]) == 0):
        num = [i/2 for i in num]
        count += 1
    else:
        print(count)
        break

Fixed submission:
import math

ignore = input()
num = map(int,input().split())
score = []
for i in num:
    temp = i
    while i%2 == 0:
        i = i/2
    score.append(temp/i)
print(int(math.log(min(score),2)))
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    alphabets = [None] + [chr(ord("a") + x) for x in range(26)]
    # 1~26:１桁
    # 27 ~ 702(26**2*"1"+26**1*"1"+ 0):2桁
    # 27 ~ 52番：aa ~ az(26+1~26)
    # 53 ~ 78番：ba ~ bz(26*"2"+"1~26")
    # 703 ~ 18278(26+26*26+26*26*26):３桁
    # 703 ~ 726: aaa ~ aaz(26**2*"1"+26*"1"+"1~26")

    #何桁か？
    cnt = 0
    m = n
    while m > 0:
        cnt += 1
        m -= 26 ** cnt
    #print(cnt)

    # 各桁がどの文字か？
    num = []
    for i in range(cnt):
        # 最初は、26で割り、次は
        y = n % (26 ** (i+1))
        #print("amari:", y, "nokori:", n)
        if y == 0:
          num += [26]
        else:
          n -= y
          num += [y // (26**i)]

    #print(num)

    ans = ""
    for s in num[::-1]:
        ans += alphabets[s]
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    s = input()
    alphabets = [chr(ord("a") + x) for x in range(26)]
    if s in alphabets:
        print("a")
    else:
        print("A")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    alphabets = [None] + [chr(ord("a") + x) for x in range(26)]
    # 1~26:１桁
    # 27 ~ 702(26**2*"1"+26**1*"1"+ 0):2桁
    # 27 ~ 52番：aa ~ az(26+1~26)
    # 53 ~ 78番：ba ~ bz(26*"2"+"1~26")
    # 703 ~ 18278(26+26*26+26*26*26):３桁
    # 703 ~ 726: aaa ~ aaz(26**2*"1"+26*"1"+"1~26")

    #何桁か？
    cnt = 0
    m = n
    while m > 0:
        cnt += 1
        m -= 26 ** cnt
    #print(cnt)

    # 各桁がどの文字か？
    num = []
    for i in range(cnt):
        # 最初は、26で割り、次は
        y = n % (26 ** (i+1))
        if y == 0:
          y = 26
        #print("amari:", y, "nokori:", n)
        n -= y
        num += [y // (26**i)]

    #print(num)

    ans = ""
    for s in num[::-1]:
        ans += alphabets[s]
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    alphabets = [None] + [chr(ord("a") + x) for x in range(26)]
    # 1~26:１桁
    # 27 ~ 702(26**2*"1"+26**1*"1"+ 0):2桁
    # 27 ~ 52番：aa ~ az(26+1~26)
    # 53 ~ 78番：ba ~ bz(26*"2"+"1~26")
    # 703 ~ 18278(26+26*26+26*26*26):３桁
    # 703 ~ 726: aaa ~ aaz(26**2*"1"+26*"1"+"1~26")

    #何桁か？
    cnt = 0
    m = n
    while m > 0:
        cnt += 1
        m -= 26 ** cnt
    #print(cnt)

    # 各桁がどの文字か？
    num = []
    for i in range(cnt):
        # 最初は、26で割り、次は
        y = n % (26 ** (i+1))
        #print("amari:", y, "nokori:", n)
        if y == 0:
          num += [26]
          n -= 26 ** (i+1)
        else:
          n -= y
          num += [y // (26**i)]

    #print(num)

    ans = ""
    for s in num[::-1]:
        ans += alphabets[s]
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    alphabets = ["z"] + [chr(ord("a") + x) for x in range(26)]
    # 1~26:１桁
    # 27 ~ 702(26*26 + 26):2桁
    # 703 ~ 18278(26+26*26+26*26*26):３桁

    #何桁か？
    cnt = 0
    m = n
    while m > 0:
        cnt += 1
        m -= 26 ** cnt
    #print(cnt)

    # 各桁がどの文字か？
    num = []
    for i in range(cnt):
        y = n % (26 ** (i + 1))
        n -= y * (26 ** i)
        num += [y]
    #print(num)
    ans = ""
    for s in num[::-1]:
        ans += alphabets[s]
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    alphabets = [None] + [chr(ord("a") + x) for x in range(26)]
    # 1~26:１桁
    # 27 ~ 702(26**2*"1"+26**1*"1"+ 0):2桁
    # 27 ~ 52番：aa ~ az(26+1~26)
    # 53 ~ 78番：ba ~ bz(26*"2"+"1~26")
    # 703 ~ 18278(26+26*26+26*26*26):３桁
    # 703 ~ 726: aaa ~ aaz(26**2*"1"+26*"1"+"1~26")

    #何桁か？
    cnt = 0
    m = n
    while m > 0:
        cnt += 1
        m -= 26 ** cnt
    #print(cnt)

    # 各桁がどの文字か？
    num = []
    for i in range(cnt):
        # 最初は、26で割り、次は
        y = n % (26 ** (i+1))
        #print("amari:", y, "nokori:", n)
        if y == 0:
          num += [26]
          n -= 26 ** (i+1)
        else:
          n -= y
          num += [y // (26**i)]

    #print(num)

    ans = ""
    for s in num[::-1]:
        ans += alphabets[s]
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import numpy as np


def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    A = np.array(list(map(int, input().split())))
    limit = 10 ** 18

    if np.any(A == 0):
        print(0)
    elif np.any(A > limit):
        print(-1)
    else:
        ans = 1

        for i in range(n):
            ans *= A[i]
            if ans > limit:
                print(-1)
                exit()

        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    limit = 10 ** 18
    #print(A)

    if A[-1] == 0:
        print(0)
    elif A[0] > limit:
        print(-1)
    else:
        ans = A[0]
        for i in range(1, n):
            ans *= A[i]
            if ans > limit:
                print(-1)
                exit()

        print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np
def main():
    n = int(input())
    A = np.array(list(map(int, input().split())))
    limit = 10 ** 18

    if np.any(A=0):
        print(0)
    else:
        ans = 1
        for i in range(n):
            ans *= A[i]
            if ans > limit:
                print(-1)
                exit()

        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    limit = 10 ** 18
    #print(A)

    if A[-1] == 0:
        print(0)
    elif A[0] > limit:
        print(-1)
    else:
        ans = A[0]
        for i in range(1, n):
            ans *= A[i]
            if ans > limit:
                print(-1)
                exit()

        print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    limit = 10 ** 18
    ans = 1
    for i in range(n):
        ans *= A[i]
        #print(ans)

    if ans > limit:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    limit = 10 ** 18
    #print(A)

    if A[-1] == 0:
        print(0)
    elif A[0] > limit:
        print(-1)
    else:
        ans = A[0]
        for i in range(1, n):
            ans *= A[i]
            if ans > limit:
                print(-1)
                exit()

        print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    a, b = input().split()
    cnt = 1
    a = int(a)
    a1 = a
    while True:
        if a % 10 == 0:
            a /= 10
            cnt += 1
        else:
            break

    if cnt >= 2:
        b = float(b)
        #print(a, b, a*b)
        ans = int(a * b * 100) * (10 ** (cnt-2))
        print(ans)
    else:
        print(int(a1 * b))



if __name__ == "__main__":
    main()


Fixed submission:
from decimal import *

def main():
    a, b = input().split()
    a = Decimal(a)
    b = Decimal(b)
    print(int(a * b))





if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    a, b = input().split()
    a = int(a)
    b = int(float(b) * 100)
    ans = str(a * b)
    ans = int(ans[:-2])
    print(ans)



if __name__ == "__main__":
    main()


Fixed submission:
from decimal import *

def main():
    a, b = input().split()
    a = Decimal(a)
    b = Decimal(b)
    print(int(a * b))





if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = [0] * (n+1)
    if n == 1 and A[0] != 0:
        print(-1)
        exit()
        
    # Adが葉の個数、Bdが葉でないものの個数
    # A0 + B0 = 1
    # Bd ≤ Ad+1 + Bd+1 ≤ 2Bd --> B[d-1] - A[d] ≤ B[d] ≤ 2B[d-1] - A[d]
    # Bd ≤ Ad+1 + Ad+2 + · · · + AN = s - (A1 + ... + Ad)

    # now_s :葉の数
    now_s = sum(A)
    s = now_s
    for i in range(n+1):
        if i == 0:
            B[i] = 1 - A[i]
        else:
            now_s -= A[i]
            B[i] = min(now_s, 2 * B[i - 1] - A[i])
            #print(A,B,now_s)
            if B[i] < 0:
                print(-1)
                exit()

    print(sum(B) + s)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    h1, m1, h2, m2, k = map(int, input().split())
    time = (h2 * 60 + m2) - (h1 * 60 + m1)
    ans = time - k
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

cnt = 0
L = []
R = []
# j - i = Ai + Aj --> i + Ai = j - Aj
for i in range(n):
    L.append(i + A[i])
    R.append(i - A[i])
    cnt += L.count(R[i])
#print(L, R)
print(cnt)


Fixed submission:
from collections import defaultdict

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

cnt = 0
d = defaultdict(int)
# j - i = Ai + Aj --> i + Ai = j - Aj
for i in range(n):
    cnt += d[i - A[i]]
    d[i + A[i]] += 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

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

cnt = 0
combination = combinations(range(1, n+1), 2)
for comb in combination:
    x, y = comb[0], comb[1]
    if abs(x - y) == A[x] + A[y]:
        cnt += 1
print(cnt)


Fixed submission:
from collections import defaultdict

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

cnt = 0
d = defaultdict(int)
# j - i = Ai + Aj --> i + Ai = j - Aj
for i in range(n):
    cnt += d[i - A[i]]
    d[i + A[i]] += 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations_with_replacement
# n個の数列、1~mの中で数列を作る
n, m, q = map(int, input().split())

comb = combinations_with_replacement(range(1, m + 1), n)
abcd = [list(map(int, input().split())) for _ in [0] * q]

ans = 0
for A in comb:
    cnt = 0
    for i in range(q):
        a, b, c, d = abcd[i][0], abcd[i][1], abcd[i][2], abcd[i][3]
        if A[b - 1] - A[a - 1] == c:
            cnt += d
    ans = max(ans, cnt)

print(ans)


Fixed submission:
from itertools import combinations_with_replacement
# n個の数列、1~mの中で数列を作る
# 2<=n<=10
# 1<=m<=10
n, m, q = map(int, input().split())

comb = combinations_with_replacement(range(1, m + 1), n)
abcd = [list(map(int, input().split())) for _ in [0] * q]

ans = 0
for A in comb:
    cnt = 0
    for a,b,c,d in abcd:
        if A[b - 1] - A[a - 1] == c:
            cnt += d
    ans = max(ans, cnt)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import numpy as np
def main():
    s = input()
    n = len(s)
    d = np.zeros(2019,np.int64)
    ans = 0
    num = 0
    d[0] += 1
    for i in reversed(range(n)):
        num += int(s[i]) * 10 ** (n - 1 - i)
        #print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
from collections import defaultdict
import numpy as np
def main():
    s = input()
    n = len(s)
    d = np.zeros(2019,np.int64)
    ans = 0
    num = 0
    pow10 = 1
    d[0] = 1
    for i in reversed(range(n)):
        pow10 = pow10 * 10 % 2019
        num += int(s[i]) * pow10
        #print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

def main():
    s = input()
    n = len(s)
    d = defaultdict(int)
    ans = 0
    num = 0
    d[0] += 1
    for i in reversed(range(n)):
        num += int(s[i]) * 10 ** (n - 1 - i)
        #print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
from collections import defaultdict
import numpy as np
def main():
    s = input()
    n = len(s)
    d = np.zeros(2019,np.int64)
    ans = 0
    num = 0
    pow10 = 1
    d[0] = 1
    for i in reversed(range(n)):
        pow10 = pow10 * 10 % 2019
        num += int(s[i]) * pow10
        #print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

def main():
    s = input()
    n = len(s)
    d = defaultdict(int)
    num = 0
    d[0] += 1
    for i in reversed(range(n)):
        num += int(s[i]) * 10 ** (n - 1 - i)
        #print(num, num % 2019, i)
        d[num % 2019] += 1

    ans = 0
    for _, cnt in d.items():
        ans += cnt * (cnt - 1) // 2
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
from collections import defaultdict
import numpy as np
def main():
    s = input()
    n = len(s)
    d = np.zeros(2019,np.int64)
    ans = 0
    num = 0
    pow10 = 1
    d[0] = 1
    for i in reversed(range(n)):
        pow10 = pow10 * 10 % 2019
        num += int(s[i]) * pow10
        #print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)

if __name__ == "__main__":
    main()