Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
H, W, A, B = map(int, input().split())
p = 10 ** 9 + 7
ans = 0
def fac(a, b):
  a = math.factorial(a + b) // math.factorial(a) // math.factorial(b)
  return a % p
for h in range(H - A):
  ans += fac(h, B - 1) * fac(H - h - 1, W - B - 1) % p
print(ans % p)

Fixed submission:
import math
H, W, A, B = map(int, input().split())
p = 10 ** 9 + 7
F = [1 for i in range(H + W + 1)]
for i in range(1, H + W + 1):
  F[i] = F[i - 1] * i % p
def fac(a, b):
  a = F[a + b] * pow(F[a], p - 2, p) * pow(F[b], p - 2, p)
  return a % p
if H - A < B:
  ans = 0
  for h in range(H - A):
    ans += fac(h, B - 1) * fac(H - h - 1, W - B - 1) % p
else:
  ans = fac(H - 1, W- 1)
  for w in range(B):
    ans -= fac(H - A - 1, w) * fac(A - 1, W - w - 1) % p
print(ans % p)
Buggy python submission (verdict: Runtime Error):
def main():

    n = int(input())
    a = n//1000
    print(n%(a*1000))
    
if __name__ == "__main__":
    main()

Fixed submission:
import math
import sys

def main():

    input = sys.stdin.buffer.readline
    n = int(input())
    if(n%1000 == 0):
        print(0)
    else:
        a = n // 1000
        print((a+1)*1000-n)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import math
import sys

def main():

    n = int(input())
    a = n//1000
    print(n%(a*1000))
    

if __name__ == "__main__":
    main()

Fixed submission:
import math
import sys

def main():

    input = sys.stdin.buffer.readline
    n = int(input())
    if(n%1000 == 0):
        print(0)
    else:
        a = n // 1000
        print((a+1)*1000-n)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
 
input = sys.stdin.readline
 
n = int(input())
a = list(map(int, input().strip().split()))
if(0 in a):
 print(0)
 return
else:
 ans = 1
 for ai in a:
  ans *= ai
  if(ans > 10**18):
   print(-1)
   return

 print(ans)

Fixed submission:
import sys

input = sys.stdin.readline
 
n = int(input())
a = list(map(int, input().strip().split()))
if(0 in a):
 print(0)
 sys.exit()
else:
 ans = a[0]
 for i in range (1,n):
  ans = ans*a[i]
  if(ans > 10**18):
   print(-1)
   sys.exit()
 print(ans)

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

input = sys.stdin.readline
 
n = int(input())
a = list(map(int, input().strip().split()))
ans = a[0]
for i in range (1,n):
 ans = ans*a[i]
if(ans > 10**18):
  print(-1)
else:
  print(ans)

Fixed submission:
import sys

input = sys.stdin.readline
 
n = int(input())
a = list(map(int, input().strip().split()))
if(0 in a):
 print(0)
 sys.exit()
else:
 ans = a[0]
 for i in range (1,n):
  ans = ans*a[i]
  if(ans > 10**18):
   print(-1)
   sys.exit()
 print(ans)

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

n = int(input())
a = list(map(int, input().strip().split()))
ans = a[0]
for i in range (1,n):
 ans = ans*a[i]
if(ans > 10**18):
 print(-1)
 sys.exit()
else:
 print(ans)

Fixed submission:
import sys

input = sys.stdin.readline
 
n = int(input())
a = list(map(int, input().strip().split()))
if(0 in a):
 print(0)
 sys.exit()
else:
 ans = a[0]
 for i in range (1,n):
  ans = ans*a[i]
  if(ans > 10**18):
   print(-1)
   sys.exit()
 print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
def main():
    n,m = map(int, input().split())
    p_list = []
    ans_ac = 0
    ans_pn = 0
    for i in range (m):
        a,b=input().split()
        p_list.append((int(a), b))
        if p_list[i][1] == 'AC':
            ans_ac += 1
        elif p_list[i][1] == 'WA':
            ans_pn += 1
    if p_list[m-1][1] == 'WA':
        ans_pn -= 1

    print(ans_ac,ans_pn)
    
   
if __name__ == "__main__":
    main()

Fixed submission:
import sys

def main():
    n,m = map(int, input().split())
    pn_list = [0]*n
    a = [0]*m
    b = [0]*m
    ans_ac = 0
    ans_pn = 0
    pn_list[0]== -1
    
    for i in range (m):
        a[i],b[i]=input().split()
        a[i] = (int(a[i]))
        # print(a[i])
        if pn_list[a[i]-1] != -1:
            if b[i]== "AC":
                ans_pn += pn_list[a[i]-1]
                ans_ac +=1
                pn_list[a[i]-1] = -1 #ペナルティリスト初期化
            else:
                pn_list[a[i]-1] += 1

    print(ans_ac,ans_pn)
    
   
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    
    a,b,k = map(int, input().split())
    if a + b <= k:
        print(0,0)
        sys.exit()
    else:    
        for i in range(k):
            if a > 0:
                a = a-1
            if a <= 0 and b > 0:
                b = b-1
                break
        print(a,b)

if __name__ == "__main__":
    main()


Fixed submission:
import sys

def main():
    
    input = sys.stdin.readline
    a,b,k = map(int, input().split())
    if a + b <= k:
        print(0,0)
        sys.exit()
    else:    
        if a < k:
            b = b-(k-a)
            a = 0
        else:
            a = a-k
        print(a,b)
            

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = ''
for i in range(1, 99):
if N <= 26 ** i:
N -= 1
for j in range(i):
ans += chr(ord('a') + N % 26)
N //= 26
break
else:
N -= 26 ** i
print(ans[::-1]) # reversed

Fixed submission:
N = int(input())
ans = ''
while N > 0:
  N -= 1
  ans += chr(ord('a') + N % 26)
  N //= 26
print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().split()
ans = 1
#float
for i in range(N):
    A = int(S[i])
    ans *= A
if ans>1000000000000000000:
    ans = -1
print (ans)

Fixed submission:
N = int(input())
S = input().split()
S.sort()
ans = 1
#float
for i in range(N):
    A = int(S[i])
    if(A==0):
        ans = 0
        break
    else:
        ans *= A
    if ans>1000000000000000000:
        ans = -1
        break
print (ans)
Buggy python submission (verdict: Runtime Error):
my_range = int(input())
data_in = list(map(int,input().split()))
n_of_odd = 0
for ind in range(int(my_range/2)+1):
  rem = data_in[2*ind] % 2
  n_of_odd = n_of_odd + rem
print(n_of_odd)

Fixed submission:
my_range = int(input())
data_in = list(map(int,input().split()))
n_of_odd = 0
for ind in range(my_range):
  if (ind % 2) == 0:
    rem = data_in[ind] % 2
    n_of_odd = n_of_odd + rem
print(n_of_odd)
Buggy python submission (verdict: Time Limit Exceeded):
iteration_count = int(input())
for my_target in range(1,iteration_count+1):
  guess_max_range = int((my_target + 2) ** 0.5)
  number_of_match = 0
  for xx in range(1,guess_max_range):
    xxxx = xx**2
    for yy in range(1,guess_max_range):
      yyyy = yy**2
      xxyy = xx*yy
      for zz in range(1,guess_max_range):
        result = xxxx + yyyy + (zz)**2 + xxyy + (yy)*(zz) + (zz)*(xx)
        if result == my_target:
          number_of_match = number_of_match + 1
  print(number_of_match)

Fixed submission:
nn = int(input())
number_of_match = [0 for _ in range(10005)]
for xx in range(1,105):
  xxxx = xx**2
  for yy in range(1,105):
    yyyy = yy**2
    xxyy = xx*yy
    for zz in range(1,105):
      result = xxxx + yyyy + (zz)**2 + xxyy + (yy)*(zz) + (zz)*(xx)
      if result < 10005:
        number_of_match[result] += 1
for i in range(1,nn+1):
  print(number_of_match[i])

Buggy python submission (verdict: Time Limit Exceeded):
iteration_count = int(input())
for my_target in range(1,iteration_count+1):
  guess_max_range = int((my_target + 50) ** 0.5)
  number_of_match = 0
  for xx in range(1,guess_max_range):
    xxxx = xx**2
    for yy in range(1,guess_max_range):
      yyyy = yy**2
      xxyy = xx*yy
      for zz in range(1,guess_max_range):
        result = xxxx + yyyy + (zz)**2 + xxyy + (yy)*(zz) + (zz)*(xx)
        if result == my_target:
          number_of_match = number_of_match + 1
  print(number_of_match)

Fixed submission:
nn = int(input())
number_of_match = [0 for _ in range(10005)]
for xx in range(1,105):
  xxxx = xx**2
  for yy in range(1,105):
    yyyy = yy**2
    xxyy = xx*yy
    for zz in range(1,105):
      result = xxxx + yyyy + (zz)**2 + xxyy + (yy)*(zz) + (zz)*(xx)
      if result < 10005:
        number_of_match[result] += 1
for i in range(1,nn+1):
  print(number_of_match[i])

Buggy python submission (verdict: Time Limit Exceeded):
iteration_count = int(input())
for my_target in range(1,iteration_count+1):
  guess_max_range = int((my_target + 50) ** 0.5)
  number_of_match = 0
  for xx in range(1,guess_max_range):
    for yy in range(1,guess_max_range):
      for zz in range(1,guess_max_range):
        result = (xx)**2 + (yy)**2 + (zz)**2 + (xx)*(yy) + (yy)*(zz) + (zz)*(xx)
        if result == my_target:
          number_of_match = number_of_match + 1
  print(number_of_match)

Fixed submission:
nn = int(input())
number_of_match = [0 for _ in range(10005)]
for xx in range(1,105):
  xxxx = xx**2
  for yy in range(1,105):
    yyyy = yy**2
    xxyy = xx*yy
    for zz in range(1,105):
      result = xxxx + yyyy + (zz)**2 + xxyy + (yy)*(zz) + (zz)*(xx)
      if result < 10005:
        number_of_match[result] += 1
for i in range(1,nn+1):
  print(number_of_match[i])
Buggy python submission (verdict: Runtime Error):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

nn = int(input())
aa = list(map(int,input().split()))

ne = [0]*200000
cn = [0]*200000
cnminus1 = [0]*nn
#print(nn,aa)
#print(len(ne))
for i in range(nn):
    ne[aa[i]] += 1

for i in range(nn):
 #   print(ne[i])
    if ne[i] == 0:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 1:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 2:
        cn[i] = 1
        cnminus1[i] = 0
    else:
        cn[i] = combinations_count(ne[i],2)
        cnminus1[i] = combinations_count(ne[i]-1,2)

sum_cn = sum(cn)

for i in range(nn):
    print(sum_cn - cn[aa[i]] + cnminus1[aa[i]])



Fixed submission:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

nn = int(input())
aa = list(map(int,input().split()))

ne = [0]*(nn+1)
cn = [0]*(nn+1)
cnminus1 = [0]*(nn+1)
#print(nn,aa)
#print(len(ne))
for i in range(nn):
    ne[aa[i]] += 1

for i in range(nn+1):
 #   print(ne[i])
    if ne[i] == 0:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 1:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 2:
        cn[i] = 1
        cnminus1[i] = 0
    else:
        cn[i] = combinations_count(ne[i],2)
        cnminus1[i] = combinations_count(ne[i]-1,2)

sum_cn = sum(cn)

for i in range(nn):
    print(sum_cn - cn[aa[i]] + cnminus1[aa[i]])

Buggy python submission (verdict: Runtime Error):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

nn = int(input())
aa = list(map(int,input().split()))

ne = [0]*nn
cn = [0]*nn
cnminus1 = [0]*nn
#print(nn,aa)

for i in range(nn):
    ne[aa[i]] += 1

for i in range(nn):
 #   print(ne[i])
    if ne[i] == 0:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 1:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 2:
        cn[i] = 1
        cnminus1[i] = 0
    else:
        cn[i] = combinations_count(ne[i],2)
        cnminus1[i] = combinations_count(ne[i]-1,2)

sum_cn = sum(cn)

for i in range(nn):
    print(sum_cn - cn[aa[i]] + cnminus1[aa[i]])



Fixed submission:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

nn = int(input())
aa = list(map(int,input().split()))

ne = [0]*(nn+1)
cn = [0]*(nn+1)
cnminus1 = [0]*(nn+1)
#print(nn,aa)
#print(len(ne))
for i in range(nn):
    ne[aa[i]] += 1

for i in range(nn+1):
 #   print(ne[i])
    if ne[i] == 0:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 1:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 2:
        cn[i] = 1
        cnminus1[i] = 0
    else:
        cn[i] = combinations_count(ne[i],2)
        cnminus1[i] = combinations_count(ne[i]-1,2)

sum_cn = sum(cn)

for i in range(nn):
    print(sum_cn - cn[aa[i]] + cnminus1[aa[i]])
Buggy python submission (verdict: Time Limit Exceeded):
nn, kk = list(map(int,input().split()))
pp = list(map(int,input().split()))

expectation = [0]*(nn-kk+1)

for i in range(nn-kk+1):
    for j in range(kk):
        expectation[i] += pp[i+j]

print((max(expectation)+kk)/2)


Fixed submission:
nn, kk = list(map(int,input().split()))
pp = list(map(int,input().split()))

expectation = [0]*(nn-kk+1)
expectation[0] = sum(pp[0:kk])

for i in range(1,nn-kk+1):
    expectation[i] = expectation[i-1] - pp[i-1] + pp[i+kk-1]

print((max(expectation)+kk)/2)
Buggy python submission (verdict: Runtime Error):
import math


def chmax(a, b):
    if a >= b:
        return a
    return b


def chmin(a, b):
    if a <= b:
        return a
    return b


def main():
    nn = int(input())
    hh = list(map(int, input().split()))

    dp = [math.inf]*nn
    dp[0] = 0
    dp[1] = chmin(dp[1],dp[0]+abs(hh[1]-hh[0]))
    for i in range(2,nn):
        dp[i] = chmin(dp[i],dp[i-1]+abs(hh[i]-hh[i-1]))
        dp[i] = chmin(dp[i],dp[i-2]+abs(hh[i]-hh[i-2]))

    print(dp[nn-1])


main()


Fixed submission:
import math


def chmax(a, b):
    if a >= b:
        return a
    return b


def chmin(a, b):
    if a <= b:
        return a
    return b


def main():
    nn = int(input())
    arr = [list(map(int, input().split())) for l in range(nn)]
    dp = [[0] * 3 for i in range(nn+1)]

    for i in range(nn):
        for j in range(3):
            for k in range(3):
                if j == k:
                    continue
                dp[i+1][j] = chmax(dp[i+1][j],dp[i][k]+arr[i][k])

    print(max(dp[nn][0],dp[nn][1],dp[nn][2]))


main()
Buggy python submission (verdict: Runtime Error):
din = map(int, raw_input().split())
if (din[0]*din[1]) % 2 == 0:
  print("Even")
else:
  print("Odd")
  

Fixed submission:
din = list(map(int,input().split()))
if (din[0]*din[1]) % 2 == 0:
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

n, x, m = list(map(int, input().split()))

data = [-1]*(m)

ans = x
data[x] = 0
count = 0
num = x

flag = 0
while(count < n-1):
    count += 1
    num = (num**2) % m
    if data[num] == -1 or flag == 1:
        data[num] = (count, ans)
        ans += num
    else:
        diff = ans-data[num][1]
        kaisuu = count - data[num][0]

        x = (n-(count)-1)//kaisuu

        count += kaisuu*x
        ans += diff*x
        flag = 1

# print(count, n)
# print(flag, ans)
print(ans)


Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

n, x, m = list(map(int, input().split()))

data = [-1]*(m+1)

ans = x

num = x
data[x] = (1, 0)
count = 2

flag = 0
while(count <= n):
    # print(count)
    num_new = (num**2) % m
    if data[num_new] == -1 or flag == 1:
        data[num_new] = (count, ans)
        ans += num_new
        num = num_new
    else:
        diff = ans-data[num_new][1]
        frec = count - data[num_new][0]

        kaisuu = (n-(count-1))//frec

        if kaisuu > 0:
            count = count-1 + frec*kaisuu
            ans += kaisuu*diff
        else:
            ans += num
            num = num_new
        flag = 1
    count += 1

# print(count, n)
# print(flag, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

n = str(input())

ans = 0
count = 1
for i in reversed(n):
    ans += count*int(i)
    ans = ans % 9
    count *= 10
if ans == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
#!/usr/bin/env python3

n = str(input())

ans = 0
count = 1
for i in reversed(n):
    ans += int(i)
    ans = ans % 9
    count *= 10
if ans == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from collections import deque

H, W = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))

ch -= 1
cw -= 1
dh -= 1
dw -= 1

S = [list((str(input()))) for i in range(H)]


def check(h, w):
    if h < 0 or h >= H:
        return False
    if w < 0 or w >= W:
        return False
    if S[h][w] == "#":
        return False
    return True


def main():

    map_ = [[10**10]*W for i in range(H)]
    # map_[ch][cw] = 0

    dq = deque([[ch, cw, 0]])

    while(len(dq) > 0):
        # print(dq)
        h, w, value = dq.popleft()
        map_value = map_[h][w]
        if map_value <= value:
            continue
        map_[h][w] = value

        for i in [-2, -1, 0, 1, 2]:
            for j in [-2, -1, 0, 1, 2]:
                if i == 0 and j == 0:
                    continue
                if abs(i)+abs(j) == 1:
                    if check(h+i, w+j):
                        # print(h+i, w+)
                        if map_[h+i][w+j] > value:
                            dq.appendleft([h+i, w+j, value])
                else:
                    if check(h+i, w+j):
                        if map_[h+i][w+j] > value+1:
                            dq.append([h+i, w+j, value+1])
    # for i in map_:
        # print(i)
    ans = map_[dh][dw]
    if ans == 10**10:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
from collections import deque

H, W = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))

ch -= 1
cw -= 1
dh -= 1
dw -= 1

S = [list((str(input()))) for i in range(H)]


def check(h, w):
    if h < 0 or h >= H:
        return False
    if w < 0 or w >= W:
        return False
    if S[h][w] == "#":
        return False
    return True


def main():

    map_ = [[10**10]*W for i in range(H)]
    # map_[ch][cw] = 0

    dq = deque([[ch, cw, 0]])

    while(len(dq) > 0):
        # print(dq)
        h, w, value = dq.popleft()
        map_value = map_[h][w]
        if map_value <= value:
            continue
        map_[h][w] = value

        for i in [-2, -1, 0, 1, 2]:
            for j in [-2, -1, 0, 1, 2]:
                if i == 0 and j == 0:
                    continue
                if abs(i)+abs(j) == 1:
                    if check(h+i, w+j):
                        # print(h+i, w+)
                        if map_[h+i][w+j] > value:
                            dq.appendleft([h+i, w+j, value])
                else:
                    if check(h+i, w+j):
                        if map_[h+i][w+j] > value+1:
                            dq.append([h+i, w+j, value+1])
    # for i in map_:
        # print(i)
    ans = map_[dh][dw]
    if ans == 10**10:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import statistics.median()

n = int(input())

a = []
b = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    a.append(a)
    b.append(b)

a_median = statistics.median(a)
b_median = statistics.median(b)

if n % 2 == 0:
    print(b_median-a_median+1)
else:
    print(b_median*2-a_median*2+1)



Fixed submission:
#!/usr/bin/env python3
import statistics

n = int(input())

a_list = []
b_list = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    a_list.append(a)
    b_list.append(b)

a_median = statistics.median(a_list)
b_median = statistics.median(b_list)

# print(a_median)
# print(b_median)
if n % 2 != 0:
    print(int(b_median-a_median+1))
else:
    print(int(b_median*2-a_median*2+1))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# import itertools
# import numpy as np

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

mod = 998244353

dp = [[0]*(s+1) for _ in range(n+1)]

dp[0][0] = 1

for i in range(0, n):
    for j in range(0, s+1):
        dp[i+1][j] += dp[i][j]*2 % mod

        if j+a[i] <= s:
            dp[i + 1][j + a[i]] += dp[i][j] % mod


print(dp[n][s] % mod)


Fixed submission:
#!/usr/bin/env python3
# import itertools
# import numpy as np

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

mod = 998244353

dp = [[0]*(s+1) for _ in range(n+1)]

dp[0][0] = 1

for i in range(0, n):
    for j in range(0, s+1):
        dp[i+1][j] += dp[i][j]*2 % mod

        if j+a[i] <= s:
            dp[i + 1][j + a[i]] += dp[i][j] % mod


print(dp[n][s] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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

ans = 0
for x in range(1, min(b+1, n+1)):
    ans_tmp = math.floor(a*x/b) - a * math.floor(x/b)
    ans = max(ans, ans_tmp)
print(ans)


Fixed submission:
#!/usr/bin/env python3

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

if b-1 <= n:
    x = b-1
    ans = math.floor(a*x/b) - a * math.floor(x/b)
else:
    x = n
    ans = math.floor(a*x/b) - a * math.floor(x/b)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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


ans = 0
for x in range(1, n+1):
    ans = max((a*x//b)-a*(x//b), ans)
print(ans)


Fixed submission:
#!/usr/bin/env python3

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

if b-1 <= n:
    x = b-1
    ans = math.floor(a*x/b) - a * math.floor(x/b)
else:
    x = n
    ans = math.floor(a*x/b) - a * math.floor(x/b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
s = str(input())

mod = 2019

div_memo = [0 for _ in range(mod)]
for i in range(1, len(s)+1):
    # print(s[len(s)-i:])
    div = (int(s[len(s)-i:]) % mod)
    div_memo[div] += 1

ans = 0
for i in range(len(div_memo)):
    ans += div_memo[i]*(div_memo[i]-1)//2

ans += div_memo[0]
print(int(ans))


Fixed submission:
#!/usr/bin/env python3
s = str(input())

mod = 2019

div_memo = [0 for _ in range(mod)]

num = 0
d = 1
for n in reversed(s):
    num += int(n)*d
    num %= 2019
    div_memo[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(len(div_memo)):
    ans += div_memo[i]*(div_memo[i]-1)//2

ans += div_memo[0]
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import numpy as np

s = str(input())

mod = 2019

div_memo = []
for i in range(1, len(s)+1):
    # print(s[len(s)-i:])
    div_memo.append(int(s[len(s)-i:]) % mod)

u, counts = np.unique(div_memo, return_counts=True)

ans = np.sum(counts*(counts-1)/2)

if u[0] == 0:
    ans += counts[0]
print(int(ans))


Fixed submission:
#!/usr/bin/env python3
s = str(input())

mod = 2019

div_memo = [0 for _ in range(mod)]

num = 0
d = 1
for n in reversed(s):
    num += int(n)*d
    num %= 2019
    div_memo[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(len(div_memo)):
    ans += div_memo[i]*(div_memo[i]-1)//2

ans += div_memo[0]
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import numpy as np

s = str(input())

mod = 2019

div_memo = []
for i in range(1, len(s)+1):
    # print(s[len(s)-i:])
    div_memo.append(int(s[len(s)-i:]) % mod)

u, counts = np.unique(div_memo, return_counts=True)

ans = 0
for i in range(len(counts)):
    ans += counts[i]*(counts[i]-1)//2

if u[0] == 0:
    ans += counts[0]
print(ans)


Fixed submission:
#!/usr/bin/env python3
s = str(input())

mod = 2019

div_memo = [0 for _ in range(mod)]

num = 0
d = 1
for n in reversed(s):
    num += int(n)*d
    num %= 2019
    div_memo[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(len(div_memo)):
    ans += div_memo[i]*(div_memo[i]-1)//2

ans += div_memo[0]
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

s = str(input())

mod = 2019

ans = 0
for i in range(1, len(s)+1):
    for j in range(0, len(s)-i+1):
        num = int(s[j:j+i])
        if num % mod == 0:
            ans += 1
            # print(j, j+i)
print(ans)


Fixed submission:
#!/usr/bin/env python3
s = str(input())

mod = 2019

div_memo = [0 for _ in range(mod)]

num = 0
d = 1
for n in reversed(s):
    num += int(n)*d
    num %= 2019
    div_memo[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(len(div_memo)):
    ans += div_memo[i]*(div_memo[i]-1)//2

ans += div_memo[0]
print(int(ans))