Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]]==i+1:
      cnt+=1
      break
    else:
      cnt=cnt
print(cnt)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]-1]==i+1:
      cnt+=1
    else:
      cnt=cnt
print(cnt//2)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]]==i+1
      cnt+=1
      break
    else:
      cnt=cnt
print(cnt)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]-1]==i+1:
      cnt+=1
    else:
      cnt=cnt
print(cnt//2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  for j in range(i+1,n):
    if a[i]==j+1 and a[j]==i+1:
      cnt+=1
      break
    else:
      cnt=cnt
print(cnt)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]-1]==i+1:
      cnt+=1
    else:
      cnt=cnt
print(cnt//2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  for j in range(i+1,n):
    if a[i]==j+1 and a[j]==i+1:
      cnt+=1
      break
    else:
      cnt=cnt
print(cnt)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]-1]==i+1:
      cnt+=1
    else:
      cnt=cnt
print(cnt//2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  for j in range(i+1,n):
    if a[i]==j+1 and a[j]==i+1:
      cnt+=1
    else:
      cnt=cnt
print(cnt)
      


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]-1]==i+1:
      cnt+=1
    else:
      cnt=cnt
print(cnt//2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  for j in range(n):
    if a[i]==j+1 and a[j]==i+1:
      cnt+=1
    else:
      cnt=cnt
print(cnt//2)
      


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[a[i]-1]==i+1:
      cnt+=1
    else:
      cnt=cnt
print(cnt//2)
Buggy python submission (verdict: Runtime Error):
a = input()
if a.isupper():
  print('A')
 else:
  print('a')

Fixed submission:
#! -*- coding: utf-8 -*-
a = input()
if a.isupper():
    print('A')
else:
    print('a')
Buggy python submission (verdict: Runtime Error):
#! env/bin/local python3
# -*- coding:utf-8 -*-

is_first = False
while True:
    try:
        if is_first:
            n, m  = (int(i) for i in input().split())
            is_first = False
        else:
            arr = (int(i) for i in input().split())
    except EOFError:
        break

total_vote = sum(arr)
sorted_arr = sorted(arr)

list_up_arr = sorted_arr[-1: -m]

flag = False
for l in list_up_arr:
    if l >= 1 / (4 * m):
        flag = True

print('Yes' if flag else 'No')

Fixed submission:
#! env/bin/local python3
# -*- coding:utf-8 -*-

is_first = True
while True:
    try:
        if is_first:
            n, m  = [int(i) for i in input().split()]
            is_first = False
        else:
            arr = [int(i) for i in input().split()]
    except EOFError:
        break

total_vote = sum(arr)
sorted_arr = sorted(arr, reverse=True)

list_up_arr = sorted_arr[: m]

flag = True
for l in list_up_arr:
    if l < 1 / (4 * m) * total_vote:
        flag = False

print('Yes' if flag else 'No')
Buggy python submission (verdict: Runtime Error):
#! env/bin/local python3
# -*- coding: utf-8 -*-

s = input()
if s[2] == s[3] and s[4] == 2[6]:
    print('Yes')
else:
    print('No')

Fixed submission:
#! env/bin/local python3
# -*- coding: utf-8 -*-

s = input()
if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
#! env/bin/local python3
# -*- coding: utf-8 -*-

import numpy as np

a_1 = list(map(int, input().split()))
a_2 = list(map(int, input().split()))
a_3 = list(map(int, input().split()))
_ = input()
pickup_number = []
while True:
    try:
        pickup_number.append(int(input()))
    except EOFError:
        break

a = np.array([a_1, a_2, a_3])

for pn in pickup_number:
    a[a == pn] = -1

flag = False
if np.sum(a, axis=0)[0] == -3 or np.sum(a, axis=1)[0] == -3:
    flag = True
if np.sum(a.diagonal()) == -3 or a[0][2] + a[1][1] + a[2][0] == -3:
    flag = True

print('Yes' if flag else 'No')


Fixed submission:
#! env/bin/local python3
# -*- coding: utf-8 -*-

n = int(input())

print(n // 2 + n % 2)
Buggy python submission (verdict: Runtime Error):
#! env/bin/local python3

s, t = input().split()
a, b = map(int, input().split())
u = input()

balls = {
    s: a,
    t: b
}

balls[u] -= 1

print(f'{balls[s]} {balls[t]}')


Fixed submission:
#! env/bin/local python3

s, t = input().split()
a, b = map(int, input().split())
u = input()

balls = {
    s: a,
    t: b
}

balls[u] -= 1

print('{} {}'.format(balls[s], balls[t]))

Buggy python submission (verdict: Runtime Error):
#! env/bin/local python3

s, t = input().split()
a, b = map(int, input().split())
u = int(input())

balls = {
    s: a,
    t: b
}

balls[u] -= 1

print(f'{balls[s]} {balls[t]}')


Fixed submission:
#! env/bin/local python3

s, t = input().split()
a, b = map(int, input().split())
u = input()

balls = {
    s: a,
    t: b
}

balls[u] -= 1

print('{} {}'.format(balls[s], balls[t]))
Buggy python submission (verdict: Runtime Error):
#! -*- coding: utf -*-

import math

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

for i in range(n-1):
    monsters[i + 1] = math.gcd(monsters[i], monsters[i + 1])

print(monsters[-1])


Fixed submission:
#! -*- coding: utf -*-

import fractions

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

for i in range(n-1):
    monsters[i + 1] = fractions.gcd(monsters[i], monsters[i + 1])

print(monsters[-1])
Buggy python submission (verdict: Runtime Error):
#! env/bin/local python3
# -*- coding: utf-8 -*-

import numpy as np

inputs: list = []

while True:
    try:
        inputs.append([int(i) for i in input().split()])
    except EOFError:
        break

h, w = inputs[0]
c = inputs[1: 11]
a = inputs[11:]

number_of_edge = 10
number_of_node = 10

for k in range(number_of_node):
    for i in range(number_of_node):
        for j in range(number_of_node):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

target = []
for ca in a:
    target += ca
# delete -1
target = [ta for ta in target if np.abs(ta) != 1]
results = 0
for t in target:
    results += c[t][1]

print(results)



Fixed submission:
#! env/bin/local python3
# -*- coding: utf-8 -*-

import numpy as np

inputs = []

while True:
    try:
        inputs.append([int(i) for i in input().split()])
    except EOFError:
        break

h, w = inputs[0]
c = inputs[1: 11]
a = inputs[11:]

number_of_edge = 10
number_of_node = 10

for k in range(number_of_node):
    for i in range(number_of_node):
        for j in range(number_of_node):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

target = []
for ca in a:
    target += ca

target = [ta for ta in target if np.abs(ta) != 1]
results = 0
for t in target:
    results += c[t][1]

print(results)
Buggy python submission (verdict: Runtime Error):
s = input()
foo = s.split('/')
if foo[1] <= 4 and foo[2] <= 30:
  print('Heisei')
else:
  print('TBD')

Fixed submission:
s = input()
foo = s.split('/')
if int(foo[1]) <= 4 and int(foo[2]) <= 30:
  print('Heisei')
else:
  print('TBD')
Buggy python submission (verdict: Runtime Error):
N = input()

if N[0] != "7" and N[1] != "7" and N[2] != "7":
    print("No")
else:
    print("Yes")

Fixed submission:
import math
R = float(input())
print(2 * math.pi * R)
Buggy python submission (verdict: Time Limit Exceeded):
import math

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

def Word(i, a, b):
    if S[i] != S[i + a] and S[i] != S[i + a + b] and S[i + a] != S[i + a + b]:
        return True
    else:
        return False

ans = 0
for i in range(0, N - 1):
    for a in range(1, N - i - 1): #a=j-i
        for b in range(1, a): #b=k-j
            if a + b + i >= N:
                break
            if Word(i, a, b):
                ans += 1
            if Word(i, b, a):
                ans += 1

print(ans)

Fixed submission:
import math

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

def Word(i, a, b):
    if S[i] != S[i + a] and S[i] != S[i + a + b] and S[i + a] != S[i + a + b]:
        return True
    else:
        return False

R = S.count("R")
G = S.count("G")
B = S.count("B")

ans = R * G * B
for i in range(0, N - 1):
    for a in range(1, math.ceil(N / 2)):
        if i + a * 2 >= N:
            break
        if S[i] != S[i + a] and S[i] != S[i + a * 2] and S[i + a] != S[i + a * 2]:
            ans -= 1

print(ans)

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

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

def Word(i, a, b):
    if S[i] != S[i + a] and S[i] != S[i + a + b] and S[i + a] != S[i + a + b]:
        return True
    else:
        return False

ans = 0
for i in range(0, N):
    for a in range(1, N - 1): #a=j-i
        for b in range(1, a): #b=k-j
            if a + b + i >= N:
                break
            if Word(i, a, b):
                ans += 1
            if Word(i, b, a):
                ans += 1

print(ans)

Fixed submission:
import math

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

def Word(i, a, b):
    if S[i] != S[i + a] and S[i] != S[i + a + b] and S[i + a] != S[i + a + b]:
        return True
    else:
        return False

R = S.count("R")
G = S.count("G")
B = S.count("B")

ans = R * G * B
for i in range(0, N - 1):
    for a in range(1, math.ceil(N / 2)):
        if i + a * 2 >= N:
            break
        if S[i] != S[i + a] and S[i] != S[i + a * 2] and S[i + a] != S[i + a * 2]:
            ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

queue = [i for i in range(1, 10)]

for i in range(K - 1):
    N = queue.pop(0)
    if N % 10 == 0:
        queue.append(N * 10)
        queue.append(N * 10 + 1)
    elif N % 10 == 9:
        queue.append(N * 10 + 8)
        queue.append(N * 10 + 9)
    else:
        queue.append(N * 10 + (N % 10 - 1))
        queue.append(N * 10 + N % 10)
        queue.append(N * 10 + (N % 10 + 1))
print(queue.pop(0))

Fixed submission:
K = int(input())

queue = [i for i in range(1, 10)]

for i in range(K - 1):
    N = queue.pop(0)
    if i < K // 2:
        if N % 10 == 0:
            queue.append(N * 10)
            queue.append(N * 10 + 1)
        elif N % 10 == 9:
            queue.append(N * 10 + 8)
            queue.append(N * 10 + 9)
        else:
            queue.append(N * 10 + (N % 10 - 1))
            queue.append(N * 10 + N % 10)
            queue.append(N * 10 + (N % 10 + 1))

print(queue.pop(0))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

N, M = map(int, input().split())

num = [-1] * (N + 1)
fin = 0
for _ in range(M):
    s, c = map(int, input().split())
    if num[s] == -1:
        num[s] = c
    elif num[s] != c:
        fin = 1
        print(-1)
        break
if N == 1 and sum[1] == 0:
    print(0)
    fin = 1
if fin == 0:
    for i in range(1, N + 1):
        if i == 1:
            if num[i] == -1:
                print(1, end="")
            elif num[i] == 0:
                print(-1)
                break
            else:
                print(num[i], end="")
        else:
            if num[i] == -1:
                print(0, end="")
            else:
                print(num[i], end="")

Fixed submission:
# coding: utf-8
import sys

N, M = map(int, input().split())

if M == 0:
    if N == 1:
        print(0)
        sys.exit()
    else:
        print(10 ** (N - 1))
        sys.exit()

num = [-1] * (N + 1)
fin = 0
for _ in range(M):
    s, c = map(int, input().split())
    if num[s] == -1:
        num[s] = c
    elif num[s] != c:
        fin = 1
        print(-1)
        break

if fin == 0:
    for i in range(1, N + 1):
        if i == 1:
            if num[i] == -1:
                print(1, end="")
            elif num[i] == 0 and N == 1:
                print(0)
            elif num[i] == 0:
                print(-1)
                break
            else:
                print(num[i], end="")
        else:
            if num[i] == -1:
                print(0, end="")
            else:
                print(num[i], end="")
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

N, Y=(int(x) for x in input().split())

A = Y // 10000 #Yを越えない最大の10000円札の枚数
B = Y // 5000
C = Y // 1000

roop = 0
for i in range(A+1):
    if roop == 1:
        break
    for j in range(B+1):
        if i + j > N:
            break
        c = N - i - j #c:1000円札の枚数
        if 10*i + 5*j + c == Y//1000 and c >= 0:
            # a:10000円札、b:5000円札
            a = i
            b = j
            roop = 1
            break

if roop == 1:
    print("{0} {1} {2}".format(a, b, c))
else:
    a, b, c = -1, -1, -1
    print("{0} {1} {2}".format(a, b, c))

Fixed submission:
# coding: utf-8

S = input()

S = S.replace("2017","2018")
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

N, Y=(int(x) for x in input().split())

A = Y // 10000 #Yを越えない最大の10000円札の枚数
B = Y // 5000
C = Y // 1000

roop = 0
for i in range(A+1):
    if roop == 1:
        break
    for j in range(B+1):
        c = N - i - j #c:1000円札の枚数
        if 10*i + 5*j + c == Y//1000 and c >= 0:
            # a:10000円札、b:5000円札
            a = i
            b = j
            roop = 1
            break

if roop == 1:
    print("{0} {1} {2}".format(a, b, c))
else:
    a, b, c = -1, -1, -1
    print("{0} {1} {2}".format(a, b, c))

Fixed submission:
# coding: utf-8

N, Y=(int(x) for x in input().split())

A = Y // 10000 #Yを越えない最大の10000円札の枚数
B = Y // 5000
C = Y // 1000

roop = 0
for i in range(A+1):
    if roop == 1:
        break
    for j in range(B+1):
        if i + j > N:
            break
        c = N - i - j #c:1000円札の枚数
        if 10*i + 5*j + c == Y//1000 and c >= 0:
            # a:10000円札、b:5000円札
            a = i
            b = j
            roop = 1
            break

if roop == 1:
    print("{0} {1} {2}".format(a, b, c))
else:
    a, b, c = -1, -1, -1
    print("{0} {1} {2}".format(a, b, c))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

N, Y=(int(x) for x in input().split())

A = Y // 10000 #Yを越えない最大の10000円札の枚数
B = Y // 5000
C = Y // 1000

roop = 0
for i in range(A+1):
    if roop == 1:
        break
    for j in range(B+1):
        if roop == 1:
            break
        for k in range(C+1):
            if 10 * i + 5 * j + k == Y // 1000 and i + j + k == N:
                # a:10000円札、b:5000円札、c:1000円札の枚数
                a = i
                b = j
                c = k
                roop = 1
if roop == 1:
    print("{0} {1} {2}".format(a, b, c))
else:
    print("-1 -1 -1")

Fixed submission:
# coding: utf-8

N, Y=(int(x) for x in input().split())

A = Y // 10000 #Yを越えない最大の10000円札の枚数
B = Y // 5000
C = Y // 1000

roop = 0
for i in range(A+1):
    if roop == 1:
        break
    for j in range(B+1):
        if i + j > N:
            break
        c = N - i - j #c:1000円札の枚数
        if 10*i + 5*j + c == Y//1000 and c >= 0:
            # a:10000円札、b:5000円札
            a = i
            b = j
            roop = 1
            break

if roop == 1:
    print("{0} {1} {2}".format(a, b, c))
else:
    a, b, c = -1, -1, -1
    print("{0} {1} {2}".format(a, b, c))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

s = input()

sum = int(0)

if s[0] = 1:
    sum++
if s[1] = 1:
    sum++
if s[2] = 1:
    sum++

print(sum)

Fixed submission:
# coding: utf-8

s = input()

sum = 0

if s[0] == "1":
    sum = sum + 1
if s[1] == "1":
    sum = sum + 1
if s[2] == "1":
    sum += 1

print(sum)
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [int(input()) for _ in range(N)]

ans = 0
for i in range(N):
  for j in range(i+1, N):
    for k in range(j+1, N):
      if L[i] != L[j] and L[j] != L[k] and L[i] != L[k]:
        if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j]:
          ans += 1

print(ans)

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

ans = 0
for i in range(N):
  for j in range(i+1, N):
    for k in range(j+1, N):
      if L[i] != L[j] and L[j] != L[k] and L[i] != L[k]:
        if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[i] + L[k] > L[j]:
          ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
# 最小公倍数
def lcm(x, y):
    return x // gcd(x, y) * y

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

x = A[0]
for i in range(N):
    x = lcm(x, A[i]) 


sums = 0
mod = 10 ** 9 + 7
for i in range(N):
    sums += x // A[i]
    sums %= mod

print(sums)


Fixed submission:
from fractions import gcd
# 最小公倍数
def lcm(x, y):
    return x // gcd(x, y) * y

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

x = A[0]
for i in range(N):
    x = lcm(x, A[i]) 


sums = 0
mod = 10 ** 9 + 7
for i in range(N):
    sums += x // A[i]

print(sums % mod)

Buggy python submission (verdict: Time Limit Exceeded):
# 最大公約数
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

# 最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

x = A[0]
for i in range(N):
    x = lcm(x, A[i])

sums = 0
mod = 10 ** 9 + 7
for i in range(N):
    sums += x // A[i]
    sums %= mod

print(sums)


Fixed submission:
from fractions import gcd
# 最小公倍数
def lcm(x, y):
    return x // gcd(x, y) * y

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

x = A[0]
for i in range(N):
    x = lcm(x, A[i]) 


sums = 0
mod = 10 ** 9 + 7
for i in range(N):
    sums += x // A[i]

print(sums % mod)

Buggy python submission (verdict: Time Limit Exceeded):
# 最大公約数
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

# 最小公倍数


def lcm(x, y):
    return (x * y) // gcd(x, y)

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

x = A[0]
for i in range(N):
    x = lcm(x, A[i])

sums = 0
for i in range(N):
    sums += x // A[i]
    sums %= 10 ** 9 + 7

print(sums)

Fixed submission:
from fractions import gcd
# 最小公倍数
def lcm(x, y):
    return x // gcd(x, y) * y

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

x = A[0]
for i in range(N):
    x = lcm(x, A[i]) 


sums = 0
mod = 10 ** 9 + 7
for i in range(N):
    sums += x // A[i]

print(sums % mod)

Buggy python submission (verdict: Time Limit Exceeded):
# 最大公約数
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

# 最小公倍数


def lcm(x, y):
    return (x * y) // gcd(x, y)

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

x = A[0]
for i in range(N):
    x = lcm(x, A[i])

sums = 0
for i in range(N):
    sums += x // A[i]
    sums %= 10 ** 9 + 7

print(sums)

Fixed submission:
from fractions import gcd
# 最小公倍数
def lcm(x, y):
    return x // gcd(x, y) * y

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

x = A[0]
for i in range(N):
    x = lcm(x, A[i]) 


sums = 0
mod = 10 ** 9 + 7
for i in range(N):
    sums += x // A[i]

print(sums % mod)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def dfs(v, p):
    for u in link[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

N, Q = map(int, input().split())
link = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

ans = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

dfs(0, -1)

print(*ans)


Fixed submission:
a = int(input())
s = input()
if a >= 3200:
    print(s)
else:
    print('red')
Buggy python submission (verdict: Runtime Error):
import copy

S = input()

dp = [0] * 13

dp[0] = 1

mod = 10 ** 9 + 7
mul = 1
for i in range(len(S)-1, -1, -1):
    # 二次元dpの代わり
    ndp = [0] * 13
    
    if S[i] == '?':
        for k in range(10):
            for j in range(13):
                # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
                # ただし、0-9までの値をその桁が取る可能性があるので、
                #　それぞれの場合全てを加算する
                ndp[(k * mul + j) % 13] += dp[j]
                ndp[(k * mul + j) % 13] %= mod
    else:
        k = int(S[i])
        for j in range(13):
            # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
            ndp[(k * mul + j) % 13] += dp[j]
            ndp[(k * mul + j) % 13] %= mod

    mul *= 10
    mul %= 13
    dp = copy.deepcopy(ndp)

# 13で割って5で余るものを出力
print(dp[5])


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

K = (A + B) / 2
if K == int(K):
    print(int(K))
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
import copy

S = input()

dp = [0] * 13

dp[0] = 1

mod = 10 ** 9 + 7
mul = 1
for i in range(len(S)-1, -1, -1):
    # 二次元dpの代わり
    ndp = [0] * 13
    
    if S[i] == '?':
        for k in range(10):
            for j in range(13):
                # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
                # ただし、0-9までの値をその桁が取る可能性があるので、
                #　それぞれの場合全てを加算する
                ndp[(k * mul + j) % 13] += dp[j]
                ndp[(k * mul + j) % 13] %= mod
    else:
        k = int(S[i])
        for j in range(13):
            # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
            ndp[(k * mul + j) % 13] += dp[j]
            ndp[(k * mul + j) % 13] %= mod

    mul *= 10
    mul %= 13
    dp = copy.deepcopy(ndp)

# 13で割って5で余るものを出力
print(dp[5])


Fixed submission:
import copy

S = input()

dp = [0] * 13

dp[0] = 1

mod = 10 ** 9 + 7
mul = 1
for i in range(len(S)-1, -1, -1):
    # 二次元dpの代わり
    ndp = [0] * 13
    
    if S[i] == '?':
        for k in range(10):
            for j in range(13):
                # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
                # ただし、0-9までの値をその桁が取る可能性があるので、
                #　それぞれの場合全てを加算する
                ndp[(k * mul + j) % 13] += dp[j]
                ndp[(k * mul + j) % 13] %= mod
    else:
        k = int(S[i])
        for j in range(13):
            # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
            ndp[(k * mul + j) % 13] += dp[j]
            ndp[(k * mul + j) % 13] %= mod

    mul *= 10
    mul %= 13
    dp = copy.deepcopy(ndp)

# 13で割って5で余るものを出力
print(dp[5])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

def perm(n, k):
    return fact[n] * ifact[n-k] % mod

def dfs(v, p):
    global ans
    for nv in link[v]:
        if nv == p:
            continue
        dfs(nv, v)
    # p = -1の時は根である。根も含めて塗り分け方を考えるので、
    # n = K、c = 子の数+根の数で塗り分け方を求める
    # 見るのが子の時はその上の頂点とその親が塗られているので、
    # n = K-2、c = 子の数となる
    if p == -1:
        n = K
    else:
        n = K - 2
    if p == -1:
        k = len(link[v]) + 1
    else:
        k = len(link[v]) - 1

    ans *= perm(n, k)
    ans %= mod

N, K = map(int, input().split())
link = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

mod = 10 ** 9 + 7
ans = 1

fact = [0] * (10**5+1)
fact[0] = 1
fact[1] = 1
for i in range(2, 10**5+1):
    fact[i] = fact[i-1] * i
    fact[i] %= mod
ifact = [0] * (10**5+1)
for i in range(10**5+1):
    ifact[i] = pow(fact[i], mod-2, mod)
    ifact[i] %= mod

dfs(0, -1)

print(ans % mod)


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

print(min(N*A, B))

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

a = R % 2019
b = L % 2019

if a > 2019 // 2:
    a = 2019 - a
if b > 2019 // 2:
    b = 2019 - b

print(a * (a+1) % 2019)


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

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

sums = 0
for i in range(N):
  sums += L + i

ans = 10 ** 9
for i in range(N):
  num = L + i
  if cnt >= abs(num):
    cnt = abs(num)
    ans = sums - num

print(ans)


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

sums = 0
for i in range(N):
  sums += L + i

ans = 10 ** 9
cnt = 10 ** 9
for i in range(N):
  num = L + i
  if cnt >= abs(num):
    cnt = abs(num)
    ans = sums - num

print(ans)