Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

for i in range(1, n+1):
    print(l.count(i))

Fixed submission:
from collections import Counter

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

d = Counter(l)
for i in range(1, n+1):
    print(d[i])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

for i in range(0, n):
    print(l.count(i+1))

Fixed submission:
from collections import Counter

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

d = Counter(l)
for i in range(1, n+1):
    print(d[i])
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
    
k = int(input())
l1 = range(1, k+1)
s = 0

for a in l1:
    for b in l1:
        for c in l1:
            l2 = [a, b, c]
            g1 = gcd(a,b)
            g2 = gcd(g1, c)
            s += g2
print(s)

Fixed submission:
from math import gcd

k = int(input())
range(1, k+1)

l1 = range(1, k+1)
def loop(s):
    for a in l1:
        for b in l1:
            for c in l1:
                l2 = (a, b, c)
                g1 = gcd(a,b)
                g2 = gcd(g1, c)
                s += g2
    return s

print(loop(0))

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


k = int(input())
l = range(1, k+1)
s = 0

for a in l:
    for b in l:
        for c in l:
            t = [a, b, c]
            g = reduce(gcd, t)
            s += g
            
print(s)

Fixed submission:
from math import gcd

k = int(input())
range(1, k+1)

l1 = range(1, k+1)
def loop(s):
    for a in l1:
        for b in l1:
            for c in l1:
                l2 = (a, b, c)
                g1 = gcd(a,b)
                g2 = gcd(g1, c)
                s += g2
    return s

print(loop(0))

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from math import gcd
from itertools import product

k = int(input())
l = range(1, k+1)
s = 0

for a, b, c in product(l, l, l):
            l = [a, b, c]
            g = reduce(gcd, l)
            s += g
            
print(s)

Fixed submission:
from math import gcd

k = int(input())
range(1, k+1)

l1 = range(1, k+1)
def loop(s):
    for a in l1:
        for b in l1:
            for c in l1:
                l2 = (a, b, c)
                g1 = gcd(a,b)
                g2 = gcd(g1, c)
                s += g2
    return s

print(loop(0))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
from math import sqrt
#N mod K = 0 or 1 となるk をさがす
#K = Nの約数　or N-1 の約数
def divisor(num):
    max_num = int(sqrt(num))
    divisor_list = []
    for i in range(1, max_num + 1):
        if num % i == 0:
            if i != 1:
                divisor_list.append(i)
            divisor_list.append(num//i)
    sorted_divisor_list = sorted(divisor_list)
    return sorted_divisor_list

K_1 = divisor(N-1)
K_2 = divisor(N)
Ks = set(K_1 + K_2)
count = 0
for k in Ks:
    temp = N
    while temp % k == 0:
        temp //= k
    if temp == 1 or temp % k == 1:
        count += 1

ans = count
print(ans)

Fixed submission:
N = int(input())
from math import sqrt
#N mod K = 0 or 1 となるk をさがす
#K = Nの約数　or N-1 の約数
def divisor(num):
    max_num = int(sqrt(num))
    divisor_list = []
    for i in range(1, max_num + 1):
        if num % i == 0:
            if i != 1:
                divisor_list.append(i)
            if num // i != 1:
                divisor_list.append(num//i)
    #sorted_divisor_list = sorted(divisor_list)
    return divisor_list

K_1 = divisor(N-1)
K_2 = divisor(N)
K_3 = []
count = 0
for k in K_2:
    temp = N
    while temp % k == 0:
        temp //= k
    if temp == 1 or temp % k == 1:
        count += 1
        K_3.append(k)
kk = K_1 + K_3
ans = len(set(kk))
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

if s = 'AAA' or 'BBB':
    print('No')
else:
    print('Yes')

Fixed submission:
s = input()

if s == 'AAA' or s == 'BBB':
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = list(map(int, input().split()))

c = 0


for i in range(0, n//(a+b)):
    c = a * (n//(a+b))

if n%(a+b) > a:
    c += a
else:
    c += n%(a+b)
    
print(c)

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

cycles = n//(a+b)
count = 0
count += a*cycles
rest = n - (a+b)*cycles
if rest > a:
    count += a
else:
    count += rest
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
query = [0]*Q

for i in range(Q):
    inp = input()
    if inp == "1":
        query[i] = "1"
    else:
        query[i] = list(inp.split())

for i in range(Q):
    if query[i] == "1":
        S = S[::-1]
    else:
        if query[i][1] == "1":
            S = query[i][2] + S
        else:
            S = S + query[i][2]

print(S)

Fixed submission:
S = input()
Q = int(input())
query = [0]*Q

for i in range(Q):
    inp = input()
    if inp == "1":
        query[i] = "1"
    else:
        query[i] = list(inp.split())

left_head_if_even = 0
right = ""
left = ""

for i in range(Q):
    if query[i] == "1":
        left_head_if_even += 1
    else:
        if query[i][1] == "1":
            if left_head_if_even%2 == 0:
                left = query[i][2] + left
            else:
                right = right + query[i][2]

        else:
            if left_head_if_even%2 == 1:
                left = query[i][2] + left
            else:
                right = right + query[i][2]

if left_head_if_even%2==0:
    S = left + S + right
else:
    S = left + S + right
    S = S[::-1]

print(S)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))
p_exp = [(p[i] + 1)/2 for i in range(n)]
ans = -1


for i in range(0, n-k+1):
    k_start = i
    k_end = i + k - 1
    sum_exp = sum(p_exp[k_start: k_end+1])
    ans = max(sum_exp, ans)

print(ans)

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

p_exp = [(p[i] + 1)/2 for i in range(n)]

s = [0]
for i in range(n):
    s.append(s[i] + p_exp[i])

ans = -1

for i in range(0, n-k+1):
    k_start = i
    k_end = i + k
    
    sum_exp = s[k_end] - s[k_start]
    
    ans = max(sum_exp, ans)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))

ans = -1

for i in range(0, n-k+1):
    k_start = i
    k_end = i + k - 1
    sum_exp = 0
    for dice in range(k_start, k_end+1):
        pi = p[dice]
        sum_exp += (pi + 1)/2
    ans = max(sum_exp, ans)

print(ans)

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

p_exp = [(p[i] + 1)/2 for i in range(n)]

s = [0]
for i in range(n):
    s.append(s[i] + p_exp[i])

ans = -1

for i in range(0, n-k+1):
    k_start = i
    k_end = i + k
    
    sum_exp = s[k_end] - s[k_start]
    
    ans = max(sum_exp, ans)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    ans = 0
    def c(i, j):
        res = 0
        str_i = str(i)
        str_j = str(j)
        for k in range(1, N+1):
            if str(k)[0] == str_i and str(k)[-1] == str_j:
                res += 1
        return res

    for i in range(1, 10):
        for j in range(1, 10):
            ans += c(i,j) * c(j, i)

    print(ans)
main()

Fixed submission:
def main():
    N = int(input())
    ans = 0
    def c(i, j):
        res = 0
        str_i = str(i)
        str_j = str(j)
        for k in range(1, N+1):
            if str(k)[0] == str_i and str(k)[-1] == str_j:
                res += 1
        return res

    for i in range(1, 10):
        for j in range(1, 10):
            ans += c(i,j) * c(j, i)

    print(ans)
main()
Buggy python submission (verdict: Runtime Error):
C = input()
chars = "abcdefghijklmnopqrstuvwxyz"
ls = list(chars) + list(chars)
dic = {chars[i]:chars[i+1] for i in range(26)}
print(dic[C])

Fixed submission:
C = input()
chars = "abcdefghijklmnopqrstuvwxyz"
ls = list(chars) + list(chars)
dic = {ls[i]:ls[i+1] for i in range(26)}
print(dic[C])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [-10**9 -10] + list(map(int, input().split()))
A.sort()
cum_sum = [0]*(N+1)
cum_sum[1] = A[1]
for i in range(2, 1+N):
    cum_sum[i] = cum_sum[i-1] + A[i]
p = 10**9 + 7
def comb(n, r, p):
  X, Y = 1, 1
  for i in range(r):
    X *= n-i
    Y *= i+1
    X %= p
    Y %= p
  return int(X * pow(Y, p-2, p))

combs = [0]*(N+1)
ans = 0
for i in range(K-2, N-1):
    combs[i] = comb(i, K-2, p)
    ans += combs[i] * ((cum_sum[N] % p - cum_sum[i+1] % p) - (cum_sum[N-i-1] % p)) % p

print(ans % p)

Fixed submission:
N, K = map(int, input().split())
A=list(map(int, input().split()))
A.sort()
MOD=10**9+7
s_max = 0
s_min = 0
MAX = 10**5 + 100
def COMinit():
    """
    逆元テーブルをつくる前処理
    計算量はO(n)
    1 <= k <= n <= 1e7程度
    p: 素数
    """
    fac = [0]*MAX
    finv = [0]*MAX
    inv = [0]*MAX

    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[0], inv[1] = 1, 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD
    return fac, finv, inv



def comb(n, k):
    """
    nCk mod MODを求める.
    この部分はO(1)
    """
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return int(fac[n] * (finv[k] * finv[n-k] % MOD) % MOD)

fac, finv, inv = COMinit()

for i in range(N):
    s_min += comb(N-i-1, K-1) * A[i]
    s_min %= MOD
for i in range(N-1, -1, -1):
    s_max += comb(i, K-1) * A[i]
    s_max %= MOD
print((s_max - s_min)%MOD)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

from math import gcd


lcm = a * b // gcd(a, b)

print(lcm)

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

from fractions import gcd

lcm = a * b // gcd(a, b)

print(lcm)

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

from math import gcd

lcm = a * b // gcd(a, b)

print(lcm)

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

from fractions import gcd

lcm = a * b // gcd(a, b)

print(lcm)

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

from math import gcd

lcm = a * b // gcd(a, b)

print(lcm)

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

from fractions import gcd

lcm = a * b // gcd(a, b)

print(lcm)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
idx = [0]
k = 0

if n == 1:
    if a[0] == 1:
        print(0)
    else:
        print(-1)
else:
    for i in range(1, n):
        if i not in a:
            break

        a = a[idx[i-1]: n]
        idx.append(a.index(i))

        k += 1

    if k == 0:
        print(-1)
    else:
        print(n - k)

Fixed submission:
N = int(input())
a = [0] + list(map(int, input().split()))

if 1 not in a:
    ans = -1
    print(ans)
else:
    broken = []
    survived = []
    latest = 1
    for i in range(1,N+1):
        if a[i] != latest:
            broken.append(a[i])
        else:
            latest += 1
            survived.append(a[i])
    print(len(broken))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
p = 10**9 + 7
total = 0
for i in range(60):
    cnt_1, cnt_0 = 0, 0
    for j in range(N):
        if (A[j]>>i)&1:
            cnt_1 += 1
        else:
            cnt_0 += 1
    total += pow(2, i, p) * cnt_0 * cnt_1 %p
print(total%p)

Fixed submission:
import sys
input = sys.stdin.readline
def main():

    N = int(input())
    A = list(map(int, input().split()))
    p = 10**9 + 7
    total = 0
    for i in range(60):
        cnt_1, cnt_0 = 0, 0
        for j in range(N):
            if (A[j]>>i)&1:
                cnt_1 += 1
            else:
                cnt_0 += 1
        total += pow(2, i, p) * cnt_0 * cnt_1 %p
    print(total%p)
main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
p = 10**9 + 7
total = 0
for i in range(60):
    cnt_1, cnt_0 = 0, 0
    for j in range(N):
        if (A[j]>>i)&1:
            cnt_1 += 1
        else:
            cnt_0 += 1
    total += 2**i * cnt_0 * cnt_1
print(total%p)

Fixed submission:
import sys
input = sys.stdin.readline
def main():

    N = int(input())
    A = list(map(int, input().split()))
    p = 10**9 + 7
    total = 0
    for i in range(60):
        cnt_1, cnt_0 = 0, 0
        for j in range(N):
            if (A[j]>>i)&1:
                cnt_1 += 1
            else:
                cnt_0 += 1
        total += pow(2, i, p) * cnt_0 * cnt_1 %p
    print(total%p)
main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))

c=0
from itertools import combinations

combs = list(combinations(l, 3))

for comb in combs:
    if comb[0] < comb[1] + comb[2]:
        if comb[1] < comb[2] + comb[0]:
            if comb[2] < comb[0] + comb[1]:
                c += 1
print(c)

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

c=0

import bisect

for i in range(n-2):
    for j in range(i+1, n-1):
        c += bisect.bisect_left(l, l[i]+l[j]) - j - 1
print(c)
Buggy python submission (verdict: Runtime Error):
k, n, q = map(int, input().split())
a = [int(input()) for _ in range(q)]
import numpy as np
points = np.array([k]*n)

for i in range(q):
    winner = a[i]
    points -= np.array([1]*n)
    points[a[i]] += 1

for i in points:
    if i <= 0:
        print("No")
    else:
        print("Yes")


Fixed submission:
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

points = [k - q]*n
for i in range(q):
    points[a[i]-1] += 1
for i in range(n):
    if points[i] <= 0:
        print("No")
    else:
        print("Yes")
Buggy python submission (verdict: Runtime Error):
n = int(input())

ans = n*(n-1)//2
print(ans)

Fixed submission:
s = input()
t = input()

c=0
for i in range(3):
    if s[i]==t[i]:
        c+= 1
print(c)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(range(n))
print(sum(l))


Fixed submission:
n = int(input())

ans = n*(n-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
a = [0]*(N) #1 index
b = [0]*(N) #1 index
p = [0]*(Q+1) #1 index
x = [0]*(Q+1) #1 index
counter = [0]*(N+1) #1 index
for i in range(1, N):
    a[i], b[i] = map(int, input().split())
for i in range(1, Q+1):
    p[i], x[i] = map(int, input().split())
    counter[p[i]] += x[i]

from collections import deque
graph = {i: deque() for i in range(1, N+1)}
for i in range(1, N):
    graph[a[i]].append(b[i])
    graph[b[i]].append(a[i])


def dfs(v):
    seen = [0]*(N+1)
    stack = []
    seen[v] = 1
    stack.append(v)
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            continue
        g = graph[s].popleft()
        if seen[g]:
            continue
        seen[g] = 1
        stack.append(g)
        counter[g] += counter[s]

dfs(v=1)
print(*counter[1:])

Fixed submission:
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
a = [0]*(N) #1 index
b = [0]*(N) #1 index
p = [0]*(Q+1) #1 index
x = [0]*(Q+1) #1 index
counter = [0]*(N+1) #1 index
for i in range(1, N):
    a[i], b[i] = map(int, input().split())
for i in range(1, Q+1):
    p[i], x[i] = map(int, input().split())
    counter[p[i]] += x[i]

from collections import deque
graph = {i: deque() for i in range(1, N+1)}
for i in range(1, N):
    graph[a[i]].append(b[i])
    graph[b[i]].append(a[i])


def dfs(v):
    seen = [0]*(N+1)
    stack = []
    seen[v] = 1
    stack.append(v)
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            continue
        g = graph[s].popleft()
        if seen[g]:
            continue
        seen[g] = 1
        stack.append(g)
        counter[g] += counter[s]

dfs(v=1)
print(*counter[1:])
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
total = B - A + 1
num_C = B // C - (A-1)//C
num_D = B // D - (A-1)//D

from math import gcd
g = gcd(C, D)
l = C * D // g
num_CD = B//l - (A-1)//l
ans = total - (num_C + num_D - num_CD)
print(ans)


Fixed submission:
A, B, C, D = map(int, input().split())
total = B - A + 1
num_C = B // C - (A-1)//C
num_D = B // D - (A-1)//D

from fractions import gcd
g = gcd(C, D)
l = C * D // g
num_CD = B//l - (A-1)//l
ans = total - (num_C + num_D - num_CD)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7

L=input()
N = len(L)
ans = 0
num = 0 # Lの先頭iケタにおける1の個数
cum_one_cnt = [0]*(N+1)
for i in range(N):
    length = N-i-1
    if L[i] == "1":
        ans += pow(3, length) * pow(2, num)
        num += 1 # 1を発見したので1つ加算

# 最後のパターンのみ特殊(フリーなケタがない)
ans += pow(2, num)
print(ans%MOD)

Fixed submission:
MOD = 10**9+7

L=input()
N = len(L)
ans = 0
num = 0 # Lの先頭iケタにおける1の個数
cum_one_cnt = [0]*(N+1)
for i in range(N):
    length = N-i-1
    if L[i] == "1":
        ans += pow(3, length, MOD) * pow(2, num, MOD) % MOD
        ans %= MOD
        num += 1 # 1を発見したので1つ加算

# 最後のパターンのみ特殊(フリーなケタがない)
ans += pow(2, num, MOD)
print(ans%MOD)
Buggy python submission (verdict: Runtime Error):
N = int(input())
adj = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    adj[u].append((v, w))
    adj[v].append((u, w))

stack = [0]
color = [-1]*N
color[0] = 0
while stack:
    v = stack.pop()
    for child, w in adj[v]:
        if color[child] < 0:
            color[child] = (color[v] + w) % 2

for i in color:
    print(color)

Fixed submission:
N = int(input())
adj = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    adj[u].append((v, w))
    adj[v].append((u, w))

stack = [0]
color = [-1]*N
color[0] = 0
while stack:
    v = stack.pop()
    for child, w in adj[v]:
        if color[child] < 0:
            color[child] = (color[v] + w) % 2
            stack.append(child)

for i in color:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
total = 0
while True:
    count_10 = S.count("10")
    total += count_10 * 2
    S = S.replace("10", "")
    count_01 = S.count("01")
    total += count_01 * 2
    S = S.replace("01", "")
    if count_01 == 0 and count_10 == 0:
        break
print(total)

Fixed submission:
S = input()
total = 0
count_0 = S.count("0")
count_1 = S.count("1")
ans = min(count_0, count_1) * 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque
N,M=map(int, input().split())
G = {i: [] for i in range(1, N+1)}
for _ in range(M):
    x,y=map(int,input().split())
    G[x].append(y)

dp = [-1]*(N+1)
for s in range(1, N+1):
    if dp[s] != -1:
        continue
    que = deque([s])
    dp[s] = 0
# for node in range(1, N+1):
#     for nx in G[node]:
#         dp[nx] = max(dp[nx], dp[node]+1)
    while que:
        node = que.popleft()
        for nx in G[node]:
            dp[nx] = max(dp[nx], dp[node]+1)
            que.append(nx)
        
print(max(dp))

Fixed submission:
from collections import defaultdict, deque
N,M=map(int, input().split())
G = {i: [] for i in range(1, N+1)}
deg = [0]*(N+1)
for _ in range(M):
    x,y=map(int,input().split())
    G[x].append(y)
    deg[y] += 1

from collections import deque, defaultdict
S = [i for i in range(1, N+1) if deg[i]==0]
dp = [0]*(N+1)

def topological_sort(adj, indeg):
    """
    幅優先探索によるトポロジカルソート
    O(|V|+|E|)

    adj: 隣接リスト
    indeg: 各ノード入次数を管理するリスト

    ret: トポロジカルソートされたリスト
    """
    is_visited = [0]*(N+1)
    ret = []
    def bfs():
        """
        sからBFSする
        """
        queue = deque(S)
        while queue:
            u = queue.popleft()
            # queueには入次数0のノードが入っているのでretに追加
            # ret.append(u)

            for v in adj[u]: # uの子ノードを探索
                indeg[v] -= 1 #探索したら子の次数を減らす
                if (indeg[v] == 0):
                    # 入次数0かつ未訪問なら
                    queue.append(v)
                    dp[v] = max(dp[v], dp[u]+1)
                    is_visited[v] = 1
    
    bfs()
    
    # return ret

topological_sort(G, deg)
print(max(dp))
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
x = list(map(int, input().split()))

is_ok = True
# x[i] - X たちの最大公約数

from math import gcd
if N == 1:
    print(abs(x[0]-X))
elif N == 2:
    GCD = gcd(abs(x[0]-X), abs(x[1]-X))
    print(GCD)
else:
    GCD = gcd(abs(x[0]-X), abs(x[1]-X))
    for i in range(2, N):
        a = abs(x[i] - X)
        GCD = gcd(GCD, a)

    print(GCD)

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

is_ok = True
# x[i] - X たちの最大公約数

from fractions import gcd
if N == 1:
    print(abs(x[0]-X))
elif N == 2:
    GCD = gcd(abs(x[0]-X), abs(x[1]-X))
    print(GCD)
else:
    GCD = gcd(abs(x[0]-X), abs(x[1]-X))
    for i in range(2, N):
        a = abs(x[i] - X)
        GCD = gcd(GCD, a)

    print(GCD)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
INF = float("inf")
N,C=map(int, input().split())
D=[[INF]*(C+1) for _ in range(C+1)]
c = [[-1]*(N+1) for _ in range(N+1)]
for i in range(1, C+1):
    tmp=list(map(int, input().split()))
    for j in range(1, C+1):
        D[i][j] = tmp[j-1]
for i in range(1, N+1):
    tmp=list(map(int, input().split()))
    for j in range(1, N+1):
        c[i][j] = tmp[j-1]
res0 = []
res1 = []
res2 = []
for i in range(1, N+1):
    for j in range(1, N+1):
        if (i+j)%3==0:
            res0.append((i,j))
        elif (i+j)%3==1:
            res1.append((i,j))
        else:
            res2.append((i,j))
ans = INF
for c0, c1, c2 in permutations(range(1, C+1), 3):
    disgust = 0
    for i, j in res0:
        disgust += D[c[i][j]][c0]
    for i, j in res1:
        disgust += D[c[i][j]][c1]
    for i, j in res2:
        disgust += D[c[i][j]][c2]
    ans = min(ans, disgust)
print(ans)

Fixed submission:
from itertools import permutations, product
INF = float("inf")
N,C=map(int, input().split())
D=[[INF]*(C+1) for _ in range(C+1)]
c = [[-1]*(N+1) for _ in range(N+1)]
for i in range(1, C+1):
    tmp=list(map(int, input().split()))
    for j in range(1, C+1):
        D[i][j] = tmp[j-1]
for i in range(1, N+1):
    tmp=list(map(int, input().split()))
    for j in range(1, N+1):
        c[i][j] = tmp[j-1]
res0 = []
res1 = []
res2 = []
for i in range(1, N+1):
    for j in range(1, N+1):
        if (i+j)%3==0:
            res0.append((i,j))
        elif (i+j)%3==1:
            res1.append((i,j))
        else:
            res2.append((i,j))
ans = INF
dc0 = []
dc1 = []
dc2 = []
for nx in range(1,C+1):
    d0 = 0
    d1 = 0
    d2 = 0
    for i,j in res0:
        d0 += D[c[i][j]][nx]
    for i,j in res1:
        d1 += D[c[i][j]][nx]
    for i,j in res2:
        d2 += D[c[i][j]][nx]
    dc0.append((d0, nx))
    dc1.append((d1, nx))
    dc2.append((d2, nx))
dc0.sort()
dc1.sort()
dc2.sort()

for i, j, k in product(range(0, 3), repeat=3):
    c0 = dc0[i][1]
    c1 = dc1[j][1]
    c2 = dc2[k][1]
    if c0 == c1 or c1 == c2 or c2 == c0:
        continue
    disgust = 0
    for i, j in res0:
        disgust += D[c[i][j]][c0]
    for i, j in res1:
        disgust += D[c[i][j]][c1]
    for i, j in res2:
        disgust += D[c[i][j]][c2]
    ans = min(ans, disgust)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
num = n
f = 0
while True:
    if num == 0:
        break
    f += num%10
    num = num//10

if n%num==0:
    print("Yes")
else:
    print("No")


Fixed submission:
n = int(input())
num = n
f = 0
while True:
    if num == 0:
        break
    f += num%10
    num = num//10

if n%f==0:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n = int(input())
num = n
f = 0
while True:
    if num == 0:
        break
    f += num%10
    num = num//10

if n%num==0:
    print("Yes")
else:
    print("No")


Fixed submission:
n = int(input())
num = n
f = 0
while True:
    if num == 0:
        break
    f += num%10
    num = num//10

if n%f==0:
    print("Yes")
else:
    print("No")