Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, c = map(int, input().split())
cnt = [[0 for _ in range(c)] for j in range(10 ** 5 + 1)]
cnt_sum = [0] * (10 ** 5 + 1)
for _ in range(n):
    s, t, _c = map(int, input().split())
    cnt[s - 1][_c - 1] += 1
    cnt[t][_c - 1] -= 1
for i in range(1, 10 ** 5 + 1):
    for j in range(c):
        cnt[i][j] += cnt[i - 1][j]
for i in range(10 ** 5 + 1):
    for j in range(c):
        cnt_sum[i] += (cnt[i][j] >= 1)
print(max(cnt_sum))

Fixed submission:
n, c = map(int, input().split())
cnt = [[0 for _ in range(10 ** 5 + 1)] for _ in range(c)]

for _ in range(n):
    s, t, _c = map(int, input().split())
    for j in range(s, t + 1):
        cnt[_c - 1][j] = 1
ans = 0
for i in range(10 ** 5 + 1):
    ans = max(ans, sum(cnt[j][i] for j in range(c)))
print(ans)

Buggy python submission (verdict: Runtime Error):
n, c = map(int, input().split())
cnt = [0] * (10 ** 5 + 1)
cnt_sum = [0] * (10 ** 5 + 1)
for _ in range(n):
    s, t, _c = map(int, input().split())
    cnt[s] += 1
    cnt[t + 1] -= 1
cnt_sum[0] = cnt[0]
for i in range(1, 10 ** 5 + 1):
    cnt_sum[i] = cnt_sum[i - 1] + cnt[i]
print(max(cnt_sum))

Fixed submission:
n, c = map(int, input().split())
cnt = [[0 for _ in range(10 ** 5 + 1)] for _ in range(c)]

for _ in range(n):
    s, t, _c = map(int, input().split())
    for j in range(s, t + 1):
        cnt[_c - 1][j] = 1
ans = 0
for i in range(10 ** 5 + 1):
    ans = max(ans, sum(cnt[j][i] for j in range(c)))
print(ans)
Buggy python submission (verdict: Runtime Error):
n = list(input())
if list[0] == list[1] == list[2] or list[1] == list[2] == list[3]:
    print('Yes')
else:
    print('No')

Fixed submission:
n = list(input())
if n[0] == n[1] == n[2] or n[1] == n[2] == n[3]:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
n = list(input())
if (list[0] == list[1] and list[1] == list[2]) or (list[1] == list[2] and list[2] == list[3]):
    print('Yes')
else:
    print('No')

Fixed submission:
n = list(input())
if n[0] == n[1] == n[2] or n[1] == n[2] == n[3]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
x, y = input().split()
if x = y:
    print('=')
elif x < y:
    print('<')
else:
    print('>')


Fixed submission:
x, y = input().split()
 
if x > y:
    print('>')
elif x < y:
    print('<')
else:
    print('=')
Buggy python submission (verdict: Runtime Error):
c1 = input()
c2 = input()
print('Yes' if c1 == c2.reverse() else 'No')

Fixed submission:
c1 = list(input())
c2 = list(input())
c1.reverse()
print('YES' if c1 == c2 else 'NO')
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(n.count(9))

Fixed submission:
n = input()
print('Yes' if n.count('9') else 'No')
Buggy python submission (verdict: Runtime Error):
n = list(input())
m = n.reverse()
print('Yes' if ''.join(n) == ''.join(m) else 'No')

Fixed submission:
n = input()
if n == n[::-1]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
x, a, b = map(int, input().split)
if a >= b:
    print('delicious')
elif x + a < b:
    print('dangerous')
else:
    print('safe')

Fixed submission:
x, a, b = map(int, input().split())
if a >= b:
    print('delicious')
elif x + a < b:
    print('dangerous')
else:
    print('safe')
Buggy python submission (verdict: Runtime Error):
x = ''.join(input().split())
if x % 4 == 0:
    print('YES')
else:
    print('NO')

Fixed submission:
x = int(''.join(input().split()))
if x % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
x = ''.join(input().split())
if x % 4 = 0:
    print('YES')
else:
    print('NO')

Fixed submission:
x = int(''.join(input().split()))
if x % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
l = list(map(int, input().split(' ')))
if int(''.join(l)) % 4 == 0:
    print('YES')
else:
    print('NO')

Fixed submission:
x = int(''.join(input().split()))
if x % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
l = list(map(int, input().split(' ')))
if int(''.join(l)) % 4 = 0:
    print('YES')
else:
    print('NO')

Fixed submission:
x = int(''.join(input().split()))
if x % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
l = list(map(int, input().split()))
if int(''.join(a)) % 4 = 0:
    print('YES')
else:
    print('NO')

Fixed submission:
x = int(''.join(input().split()))
if x % 4 == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input(),split())
if c >= a and c <= b:
    print('Yes')
else:
    print('No')
  

Fixed submission:
a, b, c = map(int, input().split())
if c >= a and c <= b:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a, b, c = list(input().split(' '))
if a[-1] = b[0] and b[-1] = c[0]:
    print('YES')
else:
    print('NO')

Fixed submission:
a, b, c = list(input().split(' '))
if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
a, b, c = map(list, input().split(' '))
if a[-1] = b[-1] and b[-1] = c[-1]:
    print('YES')
else:
    print('NO')

Fixed submission:
a, b, c = list(input().split(' '))
if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
a, b, c = list(input().split(' '))
if a[-1] = b[-1] and b[-1] = c[-1]:
    print('YES')
else:
    print('NO')

Fixed submission:
a, b, c = list(input().split(' '))
if a[-1] == b[0] and b[-1] == c[0]:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
n = int(input())
cb = int((n // 15) * 200
print(800 * n - cb)


Fixed submission:
n = int(input())
cb = int((n // 15) * 200)
print(800 * n - cb)
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
n, m = map(int, input().split())
ab = [[] for i in range(n)]
for i in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    ab[a].append(b)
    ab[b].append(a)
cnt = 0
if n == 2:
    if 1 in ab[0]:
        print(1)
    else:
        print(0)
    exit()
for p in permutations(range(1, n)):
    if p[0] in ab[0]:
        flag = True
        for i in range(n - 2):
            if p[i + 1] not in ab[p[i]]:
                flag = False
                break
        if flag:
            cnt += 1
print(cnt)

Fixed submission:
a, b = map(int, input().split())
if a == b:
    print('Draw')
elif (a > b and not b == 1) or a == 1:
    print('Alice')
else:
    print('Bob')
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
k, s = map(int, input().split())
ans = 0
for i in list(itertools.product(range(k + 1), repeat=3)):
    if sum(i) == s:
        ans += 1
print(ans)

Fixed submission:
k, s = map(int, input().split())
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z and z <= k:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if a + b == c or b + c == a or c + a == b:
    print('Yes')
else:
    prtnt('No')


Fixed submission:
a, b, c = map(int, input().split())
if a + b == c or b + c == a or c + a == b:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if a + b = c or b + c = a or c + a = b:
    print('Yes')
else:
    prtnt('No')


Fixed submission:
a, b, c = map(int, input().split())
if a + b == c or b + c == a or c + a == b:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, n+1)
    ans += i
print(ans)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n+1):
    ans += i
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, n)
    ans += 1
print(ans)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n+1):
    ans += i
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, n+1)
    ans += 1
print(ans)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n+1):
    ans += i
print(ans)
Buggy python submission (verdict: Runtime Error):
a = map(int, input().split())
if a.count(5) == 2 and a.count(7) == 1:
    print('YES')
else:
    print('NO')

Fixed submission:
a = list(map(int, input().split()))
if a.count(5) == 2 and a.count(7) == 1:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
mod = 998244353
move = []

for _ in range(K):
  L, R = map(int, input().split())
  move.append((L, R))

dp = [0]*(2*N+1)
dp[0] = 1

for i in range(N):
  for l, r in move:
    dp[i+l] += dp[i]
    dp[i+r+1] -= dp[i]
  if i:
    dp[i+1] += dp[i]
  dp[i] %= mod

print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
mod = 998244353
move = []

for _ in range(K):
  L, R = map(int, input().split())
  move.append((L, R))

S = [0]*K
dp = [0]*(2*N)
dp[N] = 1

for i in range(N+1, 2*N):
  for k, (l, r) in enumerate(move):
    S[k] -= dp[i-r-1]
    S[k] += dp[i-l]
    dp[i] += S[k]
  dp[i] %= mod

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

MOD = 998244353

def fft_convolve(f, g):
  Lf, Lg = f.shape[-1], g.shape[-1]
  L = Lf + Lg - 1
  fft_len = 1 << L.bit_length()
  fh, fl = f >> 15, f & (1 << 15) - 1
  gh, gl = g >> 15, g & (1 << 15) - 1
  def conv(f, g):
    Ff = np.fft.rfft(f, fft_len)
    Fg = np.fft.rfft(g, fft_len)
    h = np.fft.irfft(Ff * Fg)
    return np.rint(h)[..., :L].astype(np.int64) % MOD
  x = conv(fl, gl)
  z = conv(fh, gh)
  y = conv(fl + fh, gl + gh) - x - z
  return (x + (y << 15) + (z << 30)) % MOD

def coef_of_generating_function(P, Q, N):
  assert Q[0] == 1 and len(Q) == len(P) + 1
  def convolve(f, g):
    return fft_convolve(f, g)
  while N:
    Q1 = np.empty_like(Q)
    Q1[::2] = Q[::2]
    Q1[1::2] = MOD - Q[1::2]
    P = convolve(P, Q1)[N & 1::2]
    Q = convolve(Q, Q1)[::2]
    N >>= 1
  return P[0]

N, K = map(int, input().split())
Q = np.array([0]*(N+2), np.int64)
Q[0] = 1
Q[1] = -1
for _ in range(K):
  L, R = map(int, input().split())
  Q[L] -= 1
  Q[R+1] += 1

P = np.zeros_like(Q)[:-1]
P[0] = 1
P[1] = -1

print(coef_of_generating_function(P, Q, N-1))

Fixed submission:
N, K = map(int, input().split())
mod = 998244353
move = []

for _ in range(K):
  L, R = map(int, input().split())
  move.append((L, R))

S = [0]*K
dp = [0]*(2*N)
dp[N] = 1

for i in range(N+1, 2*N):
  for k, (l, r) in enumerate(move):
    S[k] -= dp[i-r-1]
    S[k] += dp[i-l]
    dp[i] += S[k]
  dp[i] %= mod

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())

HL, WL = [0]*H, [0]*W
B = []

for _ in range(M):
  h, w = map(lambda x:int(x)-1, input().split())
  B.append((h, w))
  HL[h] += 1
  WL[w] += 1

HM, WM = max(HL), max(WL)
K = HL.count(HM) * WM.count(WL)

cnt = 0
for h, w in B:
  if HL[h] == HM and WL[w] == WM:
    cnt += 1

if K > cnt:
  print(HM+WM)
else:
  print(HM+WM-1)

Fixed submission:
from itertools import product

H, W, M = map(int, input().split())

HL = [0]*H
WL = [0]*W
B = []

for _ in range(M):
  h, w = map(int, input().split())
  B.append((h, w))
  HL[h-1] += 1
  WL[w-1] += 1

HM = max(HL)
WM = max(WL)

H_ans = [0]*H
W_ans = [0]*W

for i in range(H):
  if HL[i] == HM:
    H_ans[i] += 1

for j in range(W):
  if WL[j] == WM:
    W_ans[j] += 1

if sum(H_ans)*sum(W_ans) > M:
  print(HM+WM)
else:
  cnt = 0
  for h, w in B:
    if H_ans[h-1] + W_ans[w-1] == 2:
      cnt += 1
  if sum(H_ans)*sum(W_ans) > cnt:
    print(HM+WM)
  else:
    print(HM+WM-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))

ans = -float("inf")

for st in range(N):
  S = []
  temp = P[st]
  S.append(C[temp])
  while temp != st:
    temp = P[temp]
    S.append(S[-1] + C[temp])
  cnt = len(S)
  loop, k = divmod(K, cnt)
  point = 0
  if S[-1] >= 0:
    if k == 0:
      loop -= 1
      k += cnt
    point += S[-1] * loop
  else:
    if loop >= 1:
      k = cnt
  ans = max(ans, point + max(S[:k]))

print(ans)

Fixed submission:
N, K = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))

ans = -float("inf")

for st in range(N):
  S = []
  temp = P[st]
  S.append(C[temp])
  while temp != st:
    temp = P[temp]
    S.append(S[-1] + C[temp])
  cnt = len(S)
  loop, k = divmod(K, cnt)
  point = 0
  if S[-1] >= 0:
    if k == 0:
      loop -= 1
      k += cnt
    point += S[-1] * loop
  else:
    if loop >= 1:
      k = cnt
  ans = max(ans, point + max(S[:k]))

print(ans)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left,bisect
import math

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

def is_ok(arg):
  L = bisect(A, arg)
  cnt = 0
  for i in range(L, N):
    p, q = divmod(A[i], arg)
    if q == 0:
      cnt += p-1
    else:
      cnt += p
  return cnt <= K

ng = -1
ok = max(A) + 1

def m_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(m_bisect(ng, ok))

Fixed submission:
from bisect import bisect_left,bisect
import math

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

m = 0
M = max(A) + 1

while M - m > 1:
  temp = (M + m) // 2
  L = bisect(A, temp)
  cnt = 0
  for i in range(L, N):
    p, q = divmod(A[i], temp)
    if q == 0:
      cnt += p-1
    else:
      cnt += p
  if cnt > K:
    m = temp
  else:
    M = temp

print(M)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = [0]*(N)

M = int((N-2)**0.5)

for x in range(1, M+1):
  for y in range(1, M+1):
    for z in range(1, M+1):
      a = (x+y+z)**2 - (x*y + y*z + z*x)
      if a <= N:
      	ans[a-1] += 1

for i in range(N):
  print(ans[i])

Fixed submission:
N = int(input())
ans = [0]*(N)

if N <= 3:
  for i in range(N):
    print(0)
  exit()

M = int((N-2)**0.5)
 
for x in range(1, M+1):
  for y in range(1, M+1):
    for z in range(1, M+1):
      a = (x+y+z)**2 - (x*y + y*z + z*x)
      if a <= N:
      	ans[a-1] += 1
 
for i in range(N):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10**9 + 7

Am, Ap = [], []
pm = [0, 0, 0]
Flag = True

for x in A:
  if x < 0:
    Am.append(-x)
    pm[0] += 1
  elif x == 0:
    pm[1] += 1
  else:
    Ap.append(x)
    pm[2] += 1

Am.sort()
Ap.sort()
ans = 1

if N-K < pm[1]:
  print(0)
  exit()

if pm[0] == N:
  for i in range(K):
    ans *= Am[i]
    ans %= mod
  ans *= (-1)
  print(ans%mod)
  exit()

Bm = sorted(zip(Am, [1]*pm[0]))
Bp = sorted(zip(Ap, [0]*pm[2]))

B = Bm + Bp
B.sort(reverse = True)
cnt = 0

for i in range(K):
  if i == K-1:
    cnt %= 2
    if cnt != B[i][1]:
      break
    else:
      ans *= B[i][0]
      ans %= mod
      print(ans)
      exit()
  else:
    ans *= B[i][0]
    ans %= mod
    cnt += B[i][1]

ans1 = ans
ans2 = ans * B[K][0] % mod

mcnt1 = 0
for i in range(K, N-pm[1]):
  if B[i][1] == cnt:
    mcnt1 += 1
    ans1 *= B[i][0]
    ans1 %= mod
    break

#mcnt2 = 0
for i in range(K-1, -1, -1):
  if B[i][1] == cnt:
    #mcnt2 += 1
    r = pow(B[i][0], mod-2, mod)
    ans1 *= r
    ans1 %= mod
    break

if mcnt1 == 1:
  print(max(ans1, ans2))
else:
  print(ans2)

Fixed submission:
import copy

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

mod = 10**9 + 7

Am, Ap = [], []
pm = [0, 0]
B = []

def ans(A):
  ans = 1
  for x in A:
    ans *= x
    ans %= mod
  return ans

if N == K:
  print(ans(A))
  exit()

for x in A:
  if x < 0:
    Am.append(-x)
    B.append((-x, 1))
    pm[0] += 1
  else:
    Ap.append(x)
    B.append((x, 0))
    pm[1] += 1

Am.sort()

if pm[0] == N:
  if K%2 == 0:
    print(ans(Am[N-K:]))
  else:
    print((-1 * ans(Am[:K]))%mod)
  exit()

P = []
B.sort(reverse = True)

cnt = 0

p_min = (-1, -1)
m_min = (-1, -1)

for i in range(K):
  P.append(B[i][0])
  cnt ^= B[i][1]
  if B[i][1] == 0:
    p_min = (B[i][0], i)
  else:
    m_min = (B[i][0], i)

if cnt == 0:
  print(ans(P))
  exit()

P1 = copy.deepcopy(P)
P2 = copy.deepcopy(P)

p_max = (-1, -1)
m_max = (-1, -1)

for i in range(K, N):
  if B[i][1] == 0:
    p_max = (B[i][0], i)
    break

for i in range(K, N):
  if B[i][1] == 1:
    m_max = (B[i][0], i)
    break

Flag1 = False
Flag2 = False

if p_min[1] != -1 and m_max[1] != -1:
  Flag1 = True
  P1[p_min[1]] = 1
  P1.append(m_max[0])
  ans1 = ans(P1)

if m_min[1] != -1 and p_max[1] != -1:
  Flag2 = True
  P2[m_min[1]] = 1
  P2.append(p_max[0])
  ans2 = ans(P2)

if Flag1 and Flag2:
  if m_min[0]*m_max[0] > p_min[0]*p_max[0]:
    print(ans1)
  else:
    print(ans2)
elif Flag1:
  print(ans1)
else:
  print(ans2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = 0

for i in range(1, N+1):
  for j in range(N//i):
    ans += i*(j+1)

print(ans)


Fixed submission:
N = int(input())

ans = 0

for i in range(1, N+1):
  for j in range(N//i):
    ans += i*(j+1)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

#O(N)
def imos(x):
  global N
  B = np.zeros_like(x)
  for i in range(N):
    p = x[i]
    L = max(i-p, 0)
    R = min(i+p, N-1)
    B[L] += 1
    if R < N-1:
      B[R+1] -= 1
  B = np.cumsum(B)
  return B

for i in range(K):
  if i >= 50:
    break
  A = imos(A)

print(*A)

Fixed submission:
import numpy as np

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

from numba import jit

@jit
def imos(x):
  global N
  B = np.zeros_like(x)
  for i in range(N):
    p = x[i]
    L = max(i-p, 0)
    R = min(i+p, N-1)
    B[L] += 1
    if R < N-1:
      B[R+1] -= 1
  B = np.cumsum(B)
  return B

for i in range(K):
  if i >= 50:
    break
  A = imos(A)

print(*A)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
print(A*B)

Fixed submission:
A, B = map(int, input().split())

print(A*B)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

print(int(A*B))

Fixed submission:
from decimal import *
getcontext().prec = 18

a, b = input().split()
ans = int(a) * Decimal(b)
print(int(str(ans)[:-3]))
Buggy python submission (verdict: Runtime Error):
X = int(input())

import sympy
x = sympy.Symbol('x')

def make_div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

for i in make_div(X):
  sol = sympy.solve(x**5 - (x-i)**5 - 33)[0]
  if sympy.im(sol) == 0:
    print(sol, sol - i)
  else:
    continue

Fixed submission:

X = int(input())

def make_div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def f(x, y):
  return x**5 - y**5 - X

Flag = True

for A in range(-1000, 1000):
  if Flag:
    for i in make_div(X):
      B = A - i
      if f(A, B) == 0:
        print(A, B)
        Flag = False
        break
  else:
    break
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
count = 0

for i in range(len(S)-3):
  count += len([S[i:j+1] for j in range(i+3, len(S)) if int(S[i:j+1]) % 2019 == 0])

print(count)

Fixed submission:
from collections import defaultdict

S = list(input())
S = [int(i) for i in S]
D = defaultdict(int)
mod = 2019

N = len(S)
Mlis = [0]*N
Mlis[-1] = S[-1] % mod

for i in range(N-2, -1, -1):
  Mlis[i] = (Mlis[i+1] + pow(10, N-1-i, mod) * S[i]) % mod

for i in Mlis:
  D[i] += 1

ans = D[0] + sum([i*(i-1)//2 for i in D.values()])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
count = 0

for i in range(len(S)-3):
  count += len([S[i:j+1] for j in range(i+3, len(S)) if int(S[i:j+1]) % 2019 == 0])

print(count)

Fixed submission:
from collections import defaultdict

S = list(input())
S = [int(i) for i in S]
D = defaultdict(int)
mod = 2019

N = len(S)
Mlis = [0]*N
Mlis[-1] = S[-1] % mod

for i in range(N-2, -1, -1):
  Mlis[i] = (Mlis[i+1] + pow(10, N-1-i, mod) * S[i]) % mod

for i in Mlis:
  D[i] += 1

ans = D[0] + sum([i*(i-1)//2 for i in D.values()])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
count = 0

for i in range(len(S)-3):
  for j in range(i+3, len(S)):
    if int(S[i:j+1]) % 2019 == 0:
      count += 1

print(count)

Fixed submission:
from collections import defaultdict

S = list(input())
S = [int(i) for i in S]
D = defaultdict(int)
mod = 2019

N = len(S)
Mlis = [0]*N
Mlis[-1] = S[-1] % mod

for i in range(N-2, -1, -1):
  Mlis[i] = (Mlis[i+1] + pow(10, N-1-i, mod) * S[i]) % mod

for i in Mlis:
  D[i] += 1

ans = D[0] + sum([i*(i-1)//2 for i in D.values()])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
count = 0

for i in range(len(S)):
  for j in range(i+1, len(S)):
    if int(S[i:j+1]) % 2019 == 0:
      count += 1

print(count)

Fixed submission:
from collections import defaultdict

S = list(input())
S = [int(i) for i in S]
D = defaultdict(int)
mod = 2019

N = len(S)
Mlis = [0]*N
Mlis[-1] = S[-1] % mod

for i in range(N-2, -1, -1):
  Mlis[i] = (Mlis[i+1] + pow(10, N-1-i, mod) * S[i]) % mod

for i in Mlis:
  D[i] += 1

ans = D[0] + sum([i*(i-1)//2 for i in D.values()])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0

for i in range(1, K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      ans += gcd(i, j, k)

print(ans)

Fixed submission:
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0

for i in range(1, K+1):
  for j in range(i, K+1):
    for k in range(j, K+1):
      if i == k:
        ans += gcd(i, j, k)
      elif i == j or j == k:
        ans += 3 * gcd(i, j, k)
      else:
        ans += 6 * gcd(i, j, k)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N = int(input())
S = input()

S = S.replace("R", "1")
S = S.replace("G", "2")
S = S.replace("B", "3")
count = 0

if N < 3:
  print(count)
else:
  for i in range(2, N):
    #選択した部分より手前と後ろに分ける
    a, b = list(S[:i-1]), list(S[i:])
    #手前反転
    a.reverse()
    A = np.array([int(j) for j in a])
    C = np.reshape(A, (len(a), 1))
    B = np.array([int(k) for k in b])
    D = np.reshape(B, (1, len(b)))
    E = np.dot(C, D) * int(S[i-1])
    F = np.diag(E)
    count += np.count_nonzero(E == 6) - np.count_nonzero(F == 6)
  print(count)

Fixed submission:

N = int(input())
S = list(input())
R = []
G = []
B = []

cnt = 0

for i in range(N):
  if S[i] == "R":
    R.append(i)
  elif S[i] == "G":
    G.append(i)
  else:
    B.append(i)

B = set(B)
b = len(B)  

for i in R:
  for j in G:
    check = 0
    m = min(i, j)
    M = max(i, j)
    r = M - m
    left = m - r
    right = M + r
    if r % 2 == 0:
      center = m + r//2
      if center in B:
        check += 1
    if left in B:
      check += 1
    if right in B:
      check += 1
    cnt += b - check

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

N, M = map(int, imput().split())
count = 0

def nCr(n):
  if n >= 2:
    return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
  else:
    return 0

print(nCr(N)+nCr(M))

Fixed submission:
N, M = map(int, input().split())

print( (N*(N-1))//2 + (M*(M-1))//2 )