Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(sum(range(n)))



Fixed submission:
n = int(input())
print(n * (n - 1) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)


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

p = [0] * n
for _ in range(q):
    i, x = map(int, input().split())
    p[i-1] += x

parent = [0] * n
res = [0] * n
visited = [False] * n
def dfs(x, n):
    res[x] += n
    visited[x] = True
    for ne in adj[x]:
        if not visited[ne]:
            dfs(ne, n + p[ne])

dfs(0, p[0])
print(' '.join([str(x) for x in res]))



Fixed submission:
import sys

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

res = [0] * n
for _ in range(q):
    i, x = map(int, input().split())
    res[i-1] += x

parent = [0] * n
stack = [0]
while len(stack) > 0:
    i = stack.pop()
    for j in adj[i]:
        res[j] += res[i]
        stack.append(j)

print(' '.join([str(x) for x in res]))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)


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

p = [0] * n
for _ in range(q):
    i, x = map(int, input().split())
    p[i-1] += x

parent = [0] * n
res = [0] * n
visited = [False] * n
def dfs(x, n):
    res[x] += n
    visited[x] = True
    for ne in adj[x]:
        if not visited[ne]:
            dfs(ne, n + p[ne])

dfs(0, p[0])
print(' '.join([str(x) for x in res]))



Fixed submission:
import sys

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

res = [0] * n
for _ in range(q):
    i, x = map(int, input().split())
    res[i-1] += x

parent = [0] * n
stack = [0]
while len(stack) > 0:
    i = stack.pop()
    for j in adj[i]:
        res[j] += res[i]
        stack.append(j)

print(' '.join([str(x) for x in res]))
Buggy python submission (verdict: Runtime Error):
from math import gcd


def make_divisors(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(reverse=True)
    return divisors


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

div = make_divisors(sum(a))

for x in div:
    s = sum([ai % x for ai in a])

    if s % 2 == 1:
        s -= k

    if s % 2 == 0 and 0 <= s <= 2 * k:
        print(x)
        break

# 3 | 3 1 2 1 | 7
# 4 | 1 2 0 1 3 2 1 0 | 10


Fixed submission:
def make_divisors(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(reverse=True)
    return divisors


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

div = make_divisors(sum(a))

for x in div:
    aa = [ai % x for ai in a]
    aa.sort()
    ss = aa[:len(aa) - sum(aa) // x]
    s = sum(ss)

    if 0 <= s <= k:
        print(x)
        break

# 2 | 3 5 | 8 _ 3
# 3 | 3 1 2 1 | 7 _ 4
# 4 | 1 2 0 1 3 2 1 0 | 10 _ 5
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s_base = int(s.replace('?', '0'))
digit = reversed(list(s))
sumd = 0
s10 = 4 # Before 1
hatena = []
for i, x in enumerate(digit):
    s10 = (10 * s10) % 13
    if x == '?':
        hatena.append(s10)
    else:
        sumd += int(x) * s10
        sumd %= 13

# sum( hatena[i] * x ) を満たすxの組み合わせを求める
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(len(hatena) + 2)]
# dp[i][x] hatena[:i]の和を13で割った余りがxである整数の数
dp[0][0] = 1

for i in range(len(hatena)):
    for x in range(13):
        for num in range(10):
            j = (x + num*hatena[i]) % 13
            dp[i+1][j] += dp[i][x]
            dp[i+1][j] %= mod

print(dp[len(hatena)][(5-sumd)%13])
"""
print(hatena)
print(sumd)
print(dp)
"""


Fixed submission:
s = input()
s_base = int(s.replace('?', '0'))
digit = reversed(list(s))
sumd = 0
s10 = 4 # Before 1
hatena = []
for i, x in enumerate(digit):
    s10 = (10 * s10) % 13
    if x == '?':
        hatena.append(s10)
    else:
        sumd += int(x) * s10
        sumd %= 13

# sum( hatena[i] * x ) を満たすxの組み合わせを求める
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(len(hatena) + 2)]
# dp[i][x] hatena[:i]の和を13で割った余りがxである整数の数
dp[0][0] = 1

for i in range(len(hatena)):
    for x in range(13):
        for num in range(10):
            j = (x + num*hatena[i]) % 13
            dp[i+1][j] += dp[i][x]
            dp[i+1][j] %= mod

print(dp[len(hatena)][(5-sumd)%13])
"""
print(hatena)
print(sumd)
print(dp)
"""
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

n = int(input())
a = [int(input()) for _ in range(n)]
res = [a[0]]
for x in a[1:]:
    if x <= res[0]:
        res.insert(0, x)
    else:
        res[bisect_left(res, x) - 1] = x

print(len(res))



Fixed submission:
from bisect import bisect_left
from collections import deque

n = int(input())
a = [int(input()) for _ in range(n)]
res = deque([a[0]])
for x in a[1:]:
    if x <= res[0]:
        res.appendleft(x)
    else:
        res[bisect_left(res, x) - 1] = x

print(len(res))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
res = 0
while len(a) > 0:
    last = a[0]
    del a[0]
    res += 1
    i = 0
    while i < len(a):
        if last < a[i]:
            last = a[i]
            del a[i]
        else:
            i += 1
print(res)



Fixed submission:
from bisect import bisect_left
from collections import deque

n = int(input())
a = [int(input()) for _ in range(n)]
res = deque([a[0]])
for x in a[1:]:
    if x <= res[0]:
        res.appendleft(x)
    else:
        res[bisect_left(res, x) - 1] = x

print(len(res))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

res = []
s = 0
for i in enumerate(range(n)):
    s += a[i] * [-1, 1][i % 2 ==0]
res.append(s)

for i in range(1, n):
    res.append(a[i] - 2*res[i-1])

print(' '.join(map(str, res)))


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

res = []
s = 0
for i in range(n):
    s += a[i] * [-1, 1][i % 2 ==0]
res.append(s)

for i in range(1, n):
    res.append(2*a[i-1] - res[i-1])

print(' '.join(map(str, res)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
res = []
for i in range(n):
    s = 0
    for pm, j in enumerate(range(i, i+n)):
        s += a[j%n] * [-1, 1][pm %2 ==0]
    res.append(s)

print(' '.join(map(str, res)))


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

res = []
s = 0
for i in range(n):
    s += a[i] * [-1, 1][i % 2 ==0]
res.append(s)

for i in range(1, n):
    res.append(2*a[i-1] - res[i-1])

print(' '.join(map(str, res)))
Buggy python submission (verdict: Runtime Error):
from collections import Collecter; print('YNeos'[Counter(sorted(list(input()))).values() != [2,2]::2])

Fixed submission:
from collections import Counter; print("YNeos"[list(Counter(list(input())).values()) != [2,2]::2])
Buggy python submission (verdict: Runtime Error):
a = sorted(list(map(int, input().split())))
print(a[len(a)] - a[len(a)-1])


Fixed submission:
input()
a = sorted(list(map(int, input().split())))
print(a[len(a)//2] - a[len(a)//2 - 1])
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
mod = 10**9+7
C = [[1], [1,1]]
for i in range(2, n+10):
  C.append([1] + [(C[i-1][j-1] + C[i-1][j])%mod for j in range(1, i)] + [1])
for i in range(1, k+1):
  print((C[n-k+1][i] * C[k-1][i-1])%mod)
 


Fixed submission:
n, k = map(int, input().split())
mod = 10**9+7
C = [[1], [1,1]]
for i in range(2, n+10):
  C.append([1] + [(C[i-1][j-1] + C[i-1][j])%mod for j in range(1, i)] + [1])
for i in range(1, k+1):
  if n-k+1 < i or k < i:
    print(0)
  else:
    print((C[n-k+1][i] * C[k-1][i-1])%mod)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
C = [[1], [1,1]]
for i in range(2, n+10):
  C.append([1] + [C[i-1][j-1] + C[i-1][j] for j in range(1, i)] + [1])
for i in range(1, k+1):
  print(C[n-k+1][i] * C[k-1][i-1])
  


Fixed submission:
n, k = map(int, input().split())
mod = 10**9+7
C = [[1], [1,1]]
for i in range(2, n+10):
  C.append([1] + [(C[i-1][j-1] + C[i-1][j])%mod for j in range(1, i)] + [1])
for i in range(1, k+1):
  if n-k+1 < i or k < i:
    print(0)
  else:
    print((C[n-k+1][i] * C[k-1][i-1])%mod)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
C = [[1], [1,1]]
for i in range(2, n):
  C.append([1])
  for j in range(1, i):
    C[i].append(C[i-1][j-1] + C[i-1][j])
for i in range(1, k+1):
  print(C[n-k+1][i] * C[k-1,i-1])
  


Fixed submission:
n, k = map(int, input().split())
mod = 10**9+7
C = [[1], [1,1]]
for i in range(2, n+10):
  C.append([1] + [(C[i-1][j-1] + C[i-1][j])%mod for j in range(1, i)] + [1])
for i in range(1, k+1):
  if n-k+1 < i or k < i:
    print(0)
  else:
    print((C[n-k+1][i] * C[k-1][i-1])%mod)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
C = [[1], [1,1]]
for i in range(2, n):
  C.append([1])
  for j in range(1, i):
    C[i].append(C[i-1, j-1] + C[i-1, j])
for i in range(1, k+1):
  print(C[n-k+1][i] * C[k-1,i-1])
  

Fixed submission:
n, k = map(int, input().split())
mod = 10**9+7
C = [[1], [1,1]]
for i in range(2, n+10):
  C.append([1] + [(C[i-1][j-1] + C[i-1][j])%mod for j in range(1, i)] + [1])
for i in range(1, k+1):
  if n-k+1 < i or k < i:
    print(0)
  else:
    print((C[n-k+1][i] * C[k-1][i-1])%mod)
Buggy python submission (verdict: Runtime Error):
import collections

def solve(n, points):
    a = []
    for i in range(n-1):
        for j in range(i + 1, n):
            x = points[i][0] - points[j][0]
            y = points[i][1] - points[j][1]
            if x > 0:
                a.append((x, y))
            elif x < 0:
                a.append((-x, -y))
            else:
                a.append((0, abs(y)))

    c = collections.Counter(a).most_common()[0][1]
    return n - c

n = int(input())
points = [list(map(int, input().split(' '))) for _ in range(n)]
print(solve(n, points))



Fixed submission:
import collections

def solve(n, points):
    if n == 1:
        return 1
    a = []
    for i in range(n-1):
        for j in range(i + 1, n):
            x = points[i][0] - points[j][0]
            y = points[i][1] - points[j][1]
            if x > 0:
                a.append((x, y))
            elif x < 0:
                a.append((-x, -y))
            else:
                a.append((0, abs(y)))

    c = collections.Counter(a).most_common()[0][1]
    return n - c

n = int(input())
points = [list(map(int, input().split(' '))) for _ in range(n)]
print(solve(n, points))
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True)

res = 0
fin = 0
for b, c in bc:
    count = bisect_right(a, c, lo=fin, hi=min(b, len(a))) - fin
    fin += count
    res += count * c
for i in range(fin, len(a)):
    res += a[i]

print(res)


Fixed submission:
a, b = map(int, input().split())
if a >= 13:
    print(b)
elif a >= 6:
    print(b//2)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
a = (sum(A)**2)
b =  sum([(a**2) for a in A])
print(((a-b)%(10**9+7))//2)

Fixed submission:
D, S, T = map(int, input().split())
if S*T >= D:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
path = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    path[a-1] += [b-1]
    path[b-1] += [a-1]
visited = [1] + [0] * (N-1)

u = 0
ans = 1
curr = 1
next_u = [u]
while True:
    if len(next_u) == 0:
        ans = max(ans, curr)
        curr = 1
        for i in range(N):
            if visited[i] == 0 and len(path[i])!= 0:
                visited[i] = 1
                next_u = path[i]
                break
        else:
            break
    u = next_u.pop()
    for v in path[u]:
        if visited[v] == 1:
            continue 
        visited[v] = 1
        next_u += [v]
        curr += 1

print(ans)

Fixed submission:
N, M = map(int, input().split())
path = [set() for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    path[a-1].add(b-1)
    path[b-1].add(a-1)
visited = [0] * N

ans = 1
for u in range(N):
    if visited[u] == 1:
        continue
    curr = 1
    visited[u] = 1
    next_u = path[u]
    while next_u:
        v = next_u.pop()
        if visited[v] == 1:
            continue
        visited[v] = 1
        curr += 1
        for w in path[v]:
            if visited[w] == 0:
                next_u.add(w)
    ans = max(ans, curr)

print(ans)
Buggy python submission (verdict: Runtime Error):
K = int(input())

i = 7%K
se = set(i)
cnt = 1
while True:
  if i == 0:
    print(cnt)
    break
  cnt += 1
  i = (i*10 + 7)%K
  if i in se:
    print(-1)
    break
  else:
    se.add(i)
  

Fixed submission:
K = int(input())

i = 7%K
se = set([i])
cnt = 1
while True:
  if i == 0:
    print(cnt)
    break
  cnt += 1
  i = (i*10 + 7)%K
  if i in se:
    print(-1)
    break
  else:
    se.add(i)
Buggy python submission (verdict: Runtime Error):
AC = 0
WA = 0
TLE = 0
RE = 0
from collections import defaultdict
d = defaultdict(0)
print(d[1])
N = int(input())
for i in range(N):
  s = input()

Fixed submission:
li = ["AC", "WA", "TLE", "RE"]
from collections import defaultdict
d = defaultdict(int)
N = int(input())
for i in range(N):
  s = input()
  d[s] += 1
for an in li:
  print(f"{an} x {d[an]}")
Buggy python submission (verdict: Runtime Error):
N= int(input())
ans = 0
for j in range(N):
  N_j = N//j
  ans += j*(1+N_j)*N_j//2
print(ans)

Fixed submission:
N= int(input())
ans = 0
for j in range(1,N+1):
  N_j = N//j
  ans += j*(1+N_j)*N_j//2
print(ans)
Buggy python submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if abs(A-B) - (V-W)*T <= 0:
  print("YES")
elif A==B:
  print("YES")
else:
  print("NO")

Fixed submission:
print(input()[:3])
Buggy python submission (verdict: Runtime Error):
T = int(input())

for t in range(T):
    N, A, B, C, D = map(int, input().split())
    memo = {}

    def dist(n):
        if n == 0:
            return 0
        if n in memo:
            return memo[n]
        
        ret = min(
            D * n,
            D * abs(n - n//5*5) + C + dist(n//5),
            D * abs(n - (n+4)//5*5) + C + dist((n+4)//5),
            D * abs(n - n//3*3) + B + dist(n//3),
            D * abs(n - (n+2)//3*3) + B + dist((n+2)//3),
            D * abs(n - n//2*2) + A + dist(n//2),
            D * abs(n - (n+1)//2*2) + A + dist((n+1)//2)
        )

        memo[n] = ret
        return ret
    print(dist(N))

Fixed submission:
T = int(input())

for t in range(T):
    N, A, B, C, D = map(int, input().split())
    memo = {}

    def dist(n):
        if n == 0:
            return 0
        if n == 1:
            return D
        if n in memo:
            return memo[n]
        
        ret = min(
            D * n,
            D * abs(n - n//5*5) + C + dist(n//5),
            D * abs(n - (n+4)//5*5) + C + dist((n+4)//5),
            D * abs(n - n//3*3) + B + dist(n//3),
            D * abs(n - (n+2)//3*3) + B + dist((n+2)//3),
            D * abs(n - n//2*2) + A + dist(n//2),
            D * abs(n - (n+1)//2*2) + A + dist((n+1)//2)
        )

        memo[n] = ret
        return ret
    print(dist(N))
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

A = 0
while True:
    for B in range(A+1):
        if A ** 5 + B ** 5 == X:
            print(A, B)
            break
        if A ** 5 - B ** 5 == X:
            print(A, B)
            break
    A += 1

Fixed submission:
import sys
X = int(input())

for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        if i**5 - j**5 == X:
            print(i,j)
            sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

A = 0
while True:
    for B in range(A):
        if A ** 5 + B ** 5 == X:
            print(A, B)
            break
        if A ** 5 - B ** 5 == X:
            print(A, B)
            break
    A += 1

Fixed submission:
import sys
X = int(input())

for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        if i**5 - j**5 == X:
            print(i,j)
            sys.exit()
Buggy python submission (verdict: Runtime Error):
N, *ABC = map(int, input().split())
s = [input() for _ in range(N)]

yes_flag = True
ans_list = []

if sum(ABC) == 0:
    yes_flag = False

for i in range(N):
    if not yes_flag:
        break
    u = ord(s[i][0]) - 65
    v = ord(s[i][1]) - 65
    if ABC[u] + ABC[v] == 0:
        yes_flag = False
    elif ABC[u] + ABC[v] == 1:
        if ABC[u] == 1:
            ans_list += [s[i][0]]
            ABC[u] -= 1
            ABC[v] += 1
        else:
            ans_list += [s[i][1]]
            ABC[v] -= 1
            ABC[u] += 1
    elif ABC[u] + ABC[v] == 2:
        # 両方1の場合だけケアが必要
        if ABC[u] * ABC[v] == 1:
            if i == N-1:
                ans_list += [s[i][0]]
            else:
                if ABC[u] in s[i+1]:
                    ans_list += [s[i][0]]
                    ABC[u] -= 1
                    ABC[v] += 1
                else:
                    ans_list += [s[i][1]]
                    ABC[v] -= 1
                    ABC[u] += 1
        else:
            if ABC[u] > 1:
                ans_list += [s[i][0]]
                ABC[u] -= 1
                ABC[v] += 1
            else:
                ans_list += [s[i][1]]
                ABC[v] -= 1
                ABC[u] += 1
    else:
        if ABC[u] > 1:
            ans_list += [s[i][0]]
            ABC[u] -= 1
            ABC[v] += 1
        else:
            ans_list += [s[i][1]]
            ABC[v] -= 1
            ABC[u] += 1

if yes_flag:
    print("Yes")
    print(*ans_list)

else:
    print("No")


Fixed submission:
N, *ABC = map(int, input().split())
s = [input() for _ in range(N)]

yes_flag = True
ans_list = []

if sum(ABC) == 0:
    yes_flag = False

for i in range(N):
    if not yes_flag:
        break
    u = ord(s[i][0]) - 65
    v = ord(s[i][1]) - 65
    if ABC[u] + ABC[v] == 0:
        yes_flag = False
    elif ABC[u] + ABC[v] == 1:
        if ABC[u] == 1:
            ans_list += [s[i][1]]
            ABC[u] -= 1
            ABC[v] += 1
        else:
            ans_list += [s[i][0]]
            ABC[v] -= 1
            ABC[u] += 1
    elif ABC[u] + ABC[v] == 2:
        # 両方1の場合だけケアが必要
        if ABC[u] * ABC[v] == 1:
            if i == N-1:
                if ABC[u] > 0:
                    ans_list += [s[i][1]]
                else:
                    ans_list += [s[i][0]]
            else:
                if s[i][1] in s[i+1]:
                    ans_list += [s[i][1]]
                    ABC[u] -= 1
                    ABC[v] += 1
                else:
                    ans_list += [s[i][0]]
                    ABC[v] -= 1
                    ABC[u] += 1
        else:
            if ABC[u] > 1:
                ans_list += [s[i][1]]
                ABC[u] -= 1
                ABC[v] += 1
            else:
                ans_list += [s[i][0]]
                ABC[v] -= 1
                ABC[u] += 1
    else:
        if ABC[u] > 1:
            ans_list += [s[i][1]]
            ABC[u] -= 1
            ABC[v] += 1
        else:
            ans_list += [s[i][0]]
            ABC[v] -= 1
            ABC[u] += 1

if yes_flag:
    print("Yes")
    print(*ans_list)
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
table = [1] + [0] * 2020

curr = 0
for i in range(N):
    curr += int(S[N-1-i])*(10**i)%2019
    curr %= 2019
    table[curr] += 1

ans = 0
for i in table:
    ans += i*(i-1)//2
print(ans)

Fixed submission:
S = input()
N = len(S)
table = [1] + [0] * 2020
exp = [1]
for i in range(N):
    exp += [exp[-1]*10 %2019]

curr = 0
for i in range(N):
    curr += int(S[N-1-i])*exp[i]
    curr %= 2019
    table[curr] += 1

ans = 0
for i in table:
    ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
table = [1] + [0] * 2020

curr = 0
for i in range(N):
    curr += int(S[N-1-i])*(10**i)
    curr %= 2019
    table[curr] += 1

ans = 0
for i in table:
    ans += i*(i-1)//2
print(ans)

Fixed submission:
S = input()
N = len(S)
table = [1] + [0] * 2020
exp = [1]
for i in range(N):
    exp += [exp[-1]*10 %2019]

curr = 0
for i in range(N):
    curr += int(S[N-1-i])*exp[i]
    curr %= 2019
    table[curr] += 1

ans = 0
for i in table:
    ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
table = [1] + [0] * 2020

curr = 0
for i in range(N):
    curr += int(S[N-1-i])*(10**i)
    curr %= 2019
    table[curr] += 1

ans = 0
for i in table:
    ans += i*(i-1)//2
print(ans)

Fixed submission:
S = input()
N = len(S)
table = [1] + [0] * 2020
exp = [1]
for i in range(N):
    exp += [exp[-1]*10 %2019]

curr = 0
for i in range(N):
    curr += int(S[N-1-i])*exp[i]
    curr %= 2019
    table[curr] += 1

ans = 0
for i in table:
    ans += i*(i-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
table = []

for i, a in enumerate(A):
    table.append([a,i])
table.sort(reverse=True)

# DP[i][j] 左端に i 個, 右端に j 個貪欲に詰めたときのうれしさ
DP = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
    # i 人目 table[i-1] の幼児を移動させる
    for x in range(i+1):
        y = i - x

        #左端に置く場合と右端に置く場合でmax
        DP[x][y] = max((DP[x-1][y] + table[i-1][0] * abs(table[i-1][1]  - x+1)) * (x>0),\
                     (DP[x][y-1] + table[i-1][0] * abs(table[i-1][1] - (N - y))*(y>0)))


ans = 0
for i in range(N+1):
    for j in range(N+1):
        ans = max(ans, DP[i][j])
print(ans)


Fixed submission:
print(int(input())*2*3.14)

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

print(max(N -sum(list(map(int, input().split()))), -1))

Fixed submission:
print(int(input())*2*3.14)

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

print(max(N -sum(A), -1))

Fixed submission:
print(int(input())*2*3.14)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

ans = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
  for j in range(i+1,N):
    if (i+j)%2 :
      continue
    k = (i+j)//2
    if len(set([S[i],S[k],S[j]])) == 3:
      ans -= 1
      
print(ans)

Fixed submission:
N = input()

if N[0] == '7' or N[1] == '7' or N[2] == '7':
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
  if y == 0:
    return x;
  else:
    return gcd(y, x % y)

N = int(input())

ans = 0

for a in range(1, N+1):
  for b in range(1, N+1):
    d = gcd(a,b)
    for c in range(1, N+1):
      ans += gcd(d,c)
      
print(ans)

Fixed submission:
from math import gcd

N = int(input())

ans = 0

for a in range(1, N+1):
  for b in range(1, N+1):
    d = gcd(a,b)
    for c in range(1, N+1):
      ans += gcd(d,c)
      
print(ans)