Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
X = list(map(int,input().split()))
X.sort()

X_diff = [X[i+1]-X[i] for i in range(m-1)]
X_diff.sort(reverse=True)

if n >= m:
    print(0)
else:
    print(X[-1] - X[0] - sum(X_diff[:N-1]))

Fixed submission:
n,m = map(int,input().split())
X = list(map(int,input().split()))
X.sort()

X_diff = [X[i+1]-X[i] for i in range(m-1)]
X_diff.sort(reverse=True)

if n >= m:
    print(0)
else:
    print(X[-1] - X[0] - sum(X_diff[:n-1]))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = [0]+list(map(int,input().split()))
dp = [10**10]*(N+1)
dp[1] = 0
for i in range(1,N+1):
    for j in range(1,K+1):
        if i-j>0:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])
        else:
            break
print(dp[N])


Fixed submission:
N,K = map(int,input().split())
h = [0]+list(map(int,input().split()))
dp = [10**10]*(N+1)
dp[1] = 0
for i in range(1,N+1):
    for j in range(1,K+1):
        if i-j>0:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])
        else:
            break
print(dp[N])
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
dp = [[0]*(w+1) for i in range(h+1)]
a = list(input() for _ in range(h))
dp[0][0] = 1
#配るDP
for i in range(h):
    for j in range(w):
        if i+1 < h and a[i+1][j] ==".":
            dp[i+1][j] =(dp[i+1][j] + dp[i][j])%mod
        if j+1 < w and a[i][j+1] ==".":
            dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod
print(dp[h-1][w-1])


Fixed submission:
from itertools import accumulate
from math import*
from collections import deque
from collections import defaultdict
from itertools import permutations
from heapq import*
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

h,w = map(int,input().split())
dp = [[0]*(w+1) for i in range(h+1)]
a = list(input() for _ in range(h))
dp[0][0] = 1
#配るDP
for i in range(h):
    for j in range(w):
        if i+1 < h and a[i+1][j] ==".":
            dp[i+1][j] =(dp[i+1][j] + dp[i][j])%mod
        if j+1 < w and a[i][j+1] ==".":
            dp[i][j+1] = (dp[i][j+1]+dp[i][j])%mod
print(dp[h-1][w-1])
Buggy python submission (verdict: Runtime Error):
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
inf = 10**10
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a,b):
  return a*b //gcd(a,b)
n,m = map(int,input().split())
s = input()
t = input()
d = gcd(n,m)
l = lcm(n,m)
a = n//d 
b = m//d 
for i in range(d):
    if s[a*i]!= t[b*i]:
        print(-1)
        break
    else:
        print(l)

Fixed submission:
N,M = map(int,input().split())
S = input()
T = input()
#良い文字列は存在するならば長さはN,Mの最小公倍数になる
#異なる文字が同じ場所に来たらダメ
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a,b):
  return a*b //gcd(a,b)
L = lcm(N,M)
n = N//gcd(N,M)
m = M//gcd(N,M)
for k in range(gcd(N,M)):
    if S[k*n] != T[k*m]:
        print(-1)
        exit()
print(L)

Buggy python submission (verdict: Runtime Error):
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
inf = 10**10
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def gcd_list(numbers):
    return reduce(gcd,numbers)
def lcm(a,b):
  return a*b //gcd(a,b)
n,m = map(int,input().split())
s = input()
t = input()
d = gcd(n,m)
l = lcm(n,m)
a = n//d 
b = m//d 
for i in range(d):
    if s[a*i]!= t[b*i]:
        print(-1)
        break
    else:
        print(l)

Fixed submission:
N,M = map(int,input().split())
S = input()
T = input()
#良い文字列は存在するならば長さはN,Mの最小公倍数になる
#異なる文字が同じ場所に来たらダメ
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a,b):
  return a*b //gcd(a,b)
L = lcm(N,M)
n = N//gcd(N,M)
m = M//gcd(N,M)
for k in range(gcd(N,M)):
    if S[k*n] != T[k*m]:
        print(-1)
        exit()
print(L)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

def solve(x):
    if m % x == 0:
        return True
    else:
        return False
for i in range(m//n,-1,-1):
    if solve(i):
        print(i)
        exit()
    else:
        continue

Fixed submission:
n,m = map(int,input().split())
 
def solve(x):
    if m % x == 0:
        return True
    else:
        return False
for i in range(m//n,-1,-1):
    if solve(i):
        print(i)
        exit()
    else:
        continue
Buggy python submission (verdict: Runtime Error):
n = input()
for i in range(len(n)):
  if n[i] == "1":
    n[i] = "9"
  else:
    n[i] = "1"
print(n)

Fixed submission:
n = list(input())
for i in range(len(n)):
  if n[i] == "1":
    n[i] = "9"
  else:
    n[i] = "1"
l = map(str,n)
print("".join(l))
Buggy python submission (verdict: Runtime Error):
n = int(input())
V = list(map(int,input().split()))
even = [0] * 100001
odd  = [0] * 100001

for v in V[1::2]:
    even[v] += 1
for v in V[::2]:
    odd[v]  += 1
maxeven = max(even)
maxodd  = max(odd)
if(even.index(maxeven) != odd.index(maxodd)):
    print(n - maxeven - maxodd)
else:
    even.sort()
    odd.sort()
    print(min(n-even[-1]-odd[-2]),n-even[-2]-odd[-1])

Fixed submission:
n = int(input())
V = list(map(int,input().split()))
even = [0] * 100001
odd  = [0] * 100001

for v in V[1::2]:
    even[v] += 1
for v in V[::2]:
    odd[v]  += 1
maxeven = max(even)
maxodd  = max(odd)
if(even.index(maxeven) != odd.index(maxodd)):
    print(n - maxeven - maxodd)
else:
    even.sort()
    odd.sort()
    print(min(n-even[-1]-odd[-2],n-even[-2]-odd[-1]))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())
if a == 2 or b==2:
  print("Yes")
else:
  print("No")

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

Buggy python submission (verdict: Runtime Error):
import math
N,X = map(int,input().split())
x = list(map(int,input().split()))

x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(1,N):
    ans = math.gcd(ans,x[i+1]-x[i])
print(ans)

Fixed submission:
a,b = map(int,input().split())
if a == 2 or b==2:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
import math
N,X = map(int,input().split())
x = list(map(int,input().split()))

x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(1,N):
    ans = math.gcd(ans,x[i+1]-x[i])
print(ans)

Fixed submission:
N = int(input())
W = list(input() for _ in range(N))
for i in range(1,N):
    n = len(W[i-1])
    for j in range(0,i):
        if W[i] == W[j]:
            print("No")
            exit()
    if W[i-1][n-1] != W[i][0]:
        print("No")
        exit()
    else:
        continue
print("Yes")
Buggy python submission (verdict: Runtime Error):
N,X = map(int,input().split())
x = list(map(int,input().split()))

x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(1,N):
    ans = math.gcd(ans,x[i+1]-x[i])
print(ans)


Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
N,X = map(int,input().split())
x = list(map(int,input().split()))

x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(1,N):
    ans = gcd(ans,x[i+1]-x[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
ans = 0
for a in range(1,N+1):
    for b in range(1,N+1):
        for c in range(1,N+1):
            if ((a+b) % K == 0) and ((a+c) % K == 0) and ((b+c) % K == 0):
                ans += 1
            else:
                continue
print(ans)

Fixed submission:
N,K = map(int,input().split())
if K % 2 != 0:
    case1 = len([n for n in range(1,N+1) if n % K ==0])
    print(case1 ** 3)
else:
    case1 = len([n for n in range(1,N+1) if n % K ==0])
    case2 = len([n for n in range(1,N+1) if n % K == K //2])
    print(case1**3 + case2**3)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N < 105:
    print(0)
elif N < 135:
    print(1)
elif N < 165:
    print(2)
elif N < 188
    print(3)
elif N < 195:
    print(4)
else:
    print(5)

Fixed submission:
N = int(input())
if N < 105:
    print(0)
elif N < 135:
    print(1)
elif N < 165:
    print(2)
elif N < 189:
    print(3)
elif N < 195:
    print(4)
else:
    print(5)
Buggy python submission (verdict: Runtime Error):
S = list(input())
K = int(input())
n = 0
for i in range(len(S)):
    if S[i] != "1":
        n = i +1
        break

if K < n:
    print(1)
else:
    print(int(S[n-1])

Fixed submission:
S = list(input())
K = int(input())
n = 0
for i in range(len(S)):
    if S[i] != "1":
        n = i +1
        break

if K < n:
    print(1)
else:
    print(int(S[n-1]))

Buggy python submission (verdict: Runtime Error):
S = list(input())
K = int(input())
n = 0
for i in range(len(S)):
    if S[i] != "1":
        break
    else:
        n += 1

if K < n-1:
    print(S[1])
else:
    print(S[n])

Fixed submission:
S = list(input())
K = int(input())
n = 0
for i in range(len(S)):
    if S[i] != "1":
        n = i +1
        break

if K < n:
    print(1)
else:
    print(int(S[n-1]))

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
n = 0
for i in range(len(S)):
    if S[i] != "1":
        break
    else:
        n += 1

if K < n-1:
    print(S[1])
else:
    print(S[n])

Fixed submission:
S = list(input())
K = int(input())
n = 0
for i in range(len(S)):
    if S[i] != "1":
        n = i +1
        break

if K < n:
    print(1)
else:
    print(int(S[n-1]))

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
index = 0
for i in range(len(S)):
    if S[i] != "1":
        break
    else:
        n += 1

if K < n-1:
    print(S[n])
else:
    print(S[n])

Fixed submission:
S = list(input())
K = int(input())
n = 0
for i in range(len(S)):
    if S[i] != "1":
        n = i +1
        break

if K < n:
    print(1)
else:
    print(int(S[n-1]))

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
n = 0
for i in range(len(S)):
    if S[i] != "1":
        break
    else:
        n += 1

if K < n:
    print(S[n])
else:
    print(S[n])

Fixed submission:
S = list(input())
K = int(input())
n = 0
for i in range(len(S)):
    if S[i] != "1":
        n = i +1
        break

if K < n:
    print(1)
else:
    print(int(S[n-1]))
Buggy python submission (verdict: Runtime Error):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

 N,M = map(int,input().split())
 A = list(map(int,input().split()))
 S = [0]*N
 sum = 0
 ans = 0
 #二項係数とその逆元テーブルを作る前処理
 Max = N+1
 fac = [0]*(Max)
 finv = [0]*(Max)
 inv = [0]*(Max)
 fac[0]=fac[1]=1
 finv[0]=finv[1]=1
 inv[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
 #O(1)でmod計算した組合せ数を計算
 def Comb(n,r):
     if n < r:
         return 0
     if n < 0 or r < 0 :
         return 0
     return fac[n]*(finv[r]*finv[n-r]%mod)%mod
 
 for i in range(N):
     sum += A[i]
     if sum % M == 0:
         ans += 1
     S[i] = sum % M
 C = Counter(S)
 for n in C.values():
     ans += Comb(n,2)
 print(ans)

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
b = 0
d = {0:1}
ans = 0
for a in A:
    b = (b + a)%M
    ans += d.get(b,0)
    d[b] = d.get(b,0) + 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
ans = "WA"
tmp =""
if s[0] == 'A':
    if s[2:-1].count("C") ==1:
        tmp = s.replace("A","a").replace("C."c)
        if tmp = s.lower():
            ans = "AC"
print(ans)

Fixed submission:
s = input()
ans = "WA"
tmp =""
if s[0] == 'A':
    if s[2:-1].count("C") ==1:
        tmp = s.replace("A","a").replace("C","c")
        if tmp == s.lower():
            ans = "AC"
print(ans)
Buggy python submission (verdict: Runtime Error):
d,g = map(int,input().split())
"""
PC = []
for i in range(d):
    pc = list(map(int,input().split()))
    PC.append(pc)
"""
PC =[list(map(int,input().split())) for i in range(d)]

def solve(g,i):
    if i<=0:
        return float('inf')
    n = min(int(G/100*i),PC[i-1][0])
    score = 100 * i * n 
    if n == PC[i-1][0]:
        score += PC[i-1][1]
    if g > score:
        n += solve(g-score,i-1)
    return min(n,solve(g,i-1))

print(solve(g,d))

Fixed submission:
d,g = map(int,input().split())
"""
PC = []
for i in range(d):
    pc = list(map(int,input().split()))
    PC.append(pc)
"""
PC =[list(map(int,input().split())) for i in range(d)]

def solve(g,i):
    if i<=0:
        return float('inf')
    n = min(int(g/(100*i)),PC[i-1][0])
    score = 100 * i * n
    if n == PC[i-1][0]:
        score += PC[i-1][1]
    if g > score:
        n += solve(g-score,i-1)
    return min(n,solve(g,i-1))

print(solve(g,d))

Buggy python submission (verdict: Runtime Error):
d,g = map(int,input().split())
"""
PC = []
for i in range(d):
    pc = list(map(int,input().split()))
    PC.append(pc)
"""
PC =[list(map(int,input().split())) for i in range(d)]

def solve(G,i):
    if i<=0:
        return float('inf')
    n = min(int(G/100*i),PC[i-1][0])
    score = 100 * i * n 
    if n == PC[i-1][0]:
        score += PC[i-1][1]
    if G > score:
        n += solve(G-score,i-1)
    return min(n,solve(G,i-1))

print(solve(G,D))

Fixed submission:
d,g = map(int,input().split())
"""
PC = []
for i in range(d):
    pc = list(map(int,input().split()))
    PC.append(pc)
"""
PC =[list(map(int,input().split())) for i in range(d)]

def solve(g,i):
    if i<=0:
        return float('inf')
    n = min(int(g/(100*i)),PC[i-1][0])
    score = 100 * i * n
    if n == PC[i-1][0]:
        score += PC[i-1][1]
    if g > score:
        n += solve(g-score,i-1)
    return min(n,solve(g,i-1))

print(solve(g,d))
Buggy python submission (verdict: Runtime Error):
S = input()
l = len(S)
d = {"A":1,"B":2,"C":3}

dp = [0 for _ in range(4)]
dp[0] = 1
for i in range(l):
    if S[i] == "?":
        dp = [dp[0]*3,dp[1]*3+dp[0],dp[2]*3+dp[1],dp[3]*3+dp[2]]
        for j in range(4):
            dp[j] %= mod
    else:
        j = d[S[i]]
        dp[j] += dp[j-1] % mod

print(dp[3]%mod)

Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

S = input()
l = len(S)
d = {"A":1,"B":2,"C":3}

dp = [0 for _ in range(4)]
dp[0] = 1
for i in range(l):
    if S[i] == "?":
        dp = [dp[0]*3,dp[1]*3+dp[0],dp[2]*3+dp[1],dp[3]*3+dp[2]]
        for j in range(4):
            dp[j] %= mod
    else:
        j = d[S[i]]
        dp[j] += dp[j-1] % mod

print(dp[3]%mod)
Buggy python submission (verdict: Runtime Error):
def solve():
    s = input()
    t = input()
    for i in range(len(s)):
        if t == s[i:] + s[:i]:
            return True
        else False
if solve():
    print("Yes")
else:
    print("No")


Fixed submission:
def solve():
    s = input()
    t = input()
    for i in range(len(s)):
        if t == s[i:] + s[:i]:
            return True
        else:
            False
if solve():
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
m=1
ans =0
def gcd(a, b):
 if a < b:
    a, b = b, a
 if b == 0:
    return a
 c = a % b
 return gcd(b, c)
def lcm(a,b):
    return int(a*b/gcd(a,b))
for i in range(n):
    m = lcm(m,a[i])
for i in range(m):
    sum = 0
    for j in range(n):
        sum += i % a[j]
    ans = max(ans,sum)
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
m=1
sum = 0
def gcd(a, b):
 if a < b:
    a, b = b, a
 if b == 0:
    return a
 c = a % b
 return gcd(b, c)
def lcm(a,b):
    return int(a*b/gcd(a,b))
for i in range(n):
    m = m *a[i]
for i in range(n):
        sum += (m-1) % a[i]

print(sum)
Buggy python submission (verdict: Runtime Error):
#取り除く橋は西側が出来るだけ大きいやつから取り除いても無駄がない
#（なぜならそうでない橋を取り除いた後にも上の橋を取り除かねばならないので）
N,M = map(int,input().split())
ab =[list(map(int,input().split())) for i in range(M)]
ab.sort(reverse=True)
ans = 0
tmp = inf
for i in range(M):
    if ab[i][1] > tmp:
        continue
    else:
        ans += 1
        tmp = ab[i][0]
print(ans)


Fixed submission:
inf = 10**10

N,M = map(int,input().split())
ab =[list(map(int,input().split())) for i in range(M)]
ab.sort(reverse=True)
ans = 0
tmp = inf
for i in range(M):
    if ab[i][1] > tmp:
        continue
    else:
        ans += 1
        tmp = ab[i][0]
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
from collections import Counter
inf = 10**10
from itertools import*


n,m = map(int,input().split())
X = [list(map(int,input().split())) for i in range(n)]
res = 0
for (a,b,c) in product([-1,1],[-1,1],[-1,1]):
    tmp=[]
    for x,y,z in X:
        tmp.append(a*x+b*y+c*z)
    tmp.sort(reverse=True)
    res = max(res,sum(tmp[:m]))

print(res)

Fixed submission:
N,M = map(int,input().split())
x=[]
y=[]
z=[]
for i in range(N):
    xi,yi,zi = map(int,input().split())
    x.append(xi)
    y.append(yi)
    z.append(zi)
ppp =[]
ppm =[]
pmp =[]
mpp =[]
mmp =[]
mpm =[]
pmm =[]
mmm =[]
for i in range(N):
    xp = x[i]
    xm = -x[i]
    yp = y[i]
    ym = -y[i]
    zp = z[i]
    zm = -z[i]
    ppp.append(xp+yp+zp)
    ppm.append(xp+yp+zm)
    pmp.append(xp+ym+zp)
    mpp.append(xm+yp+zp)
    mmp.append(xm+ym+zp)
    mpm.append(xm+yp+zm)
    pmm.append(xp+ym+zm)
    mmm.append(xm+ym+zm)
ppp.sort(reverse=True)
ppm.sort(reverse=True)
pmp.sort(reverse=True)
mpp.sort(reverse=True)
mmp.sort(reverse=True)
mpm.sort(reverse=True)
pmm.sort(reverse=True)
mmm.sort(reverse=True)
print(max(sum(ppp[0:M]),sum(ppm[0:M]),sum(pmp[0:M]),sum(mpp[0:M]),sum(mmp[0:M]),sum(mpm[0:M]),sum(pmm[0:M]),sum(mmm[0:M])))

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
X = [list(map(int,input().split())) for i in range(n)]
res = 0
for (a,b,c) in product([-1,1],[-1,1],[-1,1]):
    tmp=[]
    for x,y,z in X:
        tmp.append(a*x+b*y+c*z)
    tmp.sort(reverse=True)
    res = max(res,sum(tmp[:m]))

print(res)


Fixed submission:
N,M = map(int,input().split())
x=[]
y=[]
z=[]
for i in range(N):
    xi,yi,zi = map(int,input().split())
    x.append(xi)
    y.append(yi)
    z.append(zi)
ppp =[]
ppm =[]
pmp =[]
mpp =[]
mmp =[]
mpm =[]
pmm =[]
mmm =[]
for i in range(N):
    xp = x[i]
    xm = -x[i]
    yp = y[i]
    ym = -y[i]
    zp = z[i]
    zm = -z[i]
    ppp.append(xp+yp+zp)
    ppm.append(xp+yp+zm)
    pmp.append(xp+ym+zp)
    mpp.append(xm+yp+zp)
    mmp.append(xm+ym+zp)
    mpm.append(xm+yp+zm)
    pmm.append(xp+ym+zm)
    mmm.append(xm+ym+zm)
ppp.sort(reverse=True)
ppm.sort(reverse=True)
pmp.sort(reverse=True)
mpp.sort(reverse=True)
mmp.sort(reverse=True)
mpm.sort(reverse=True)
pmm.sort(reverse=True)
mmm.sort(reverse=True)
print(max(sum(ppp[0:M]),sum(ppm[0:M]),sum(pmp[0:M]),sum(mpp[0:M]),sum(mmp[0:M]),sum(mpm[0:M]),sum(pmm[0:M]),sum(mmm[0:M])))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n,c = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(c)]
C = [list(map(int,input().split())) for _ in range(n)]
ans = inf
for (a,b,c) in permutations(range(c),3):
    cur = 0
    for i in range(n):
        for j in range(n):
            if (i+j)%3 == 0:
                cur += D[C[i][j]-1][a]
            elif (i+j)%3 == 1:
                cur += D[C[i][j]-1][b]
            else:
                cur += D[C[i][j]-1][c]
    ans = min(ans,cur)
print(ans)


Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n,c = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(c)]
C = [list(map(int,input().split())) for _ in range(n)]
C0,C1,C2 = [0]*c,[0]*c,[0]*c
for i in range(n):
    for j in range(n):
        if (i+j)%3 == 0:
            C0[C[i][j]-1] += 1
        elif (i+j)%3 == 1:
            C1[C[i][j]-1] += 1
        else:
            C2[C[i][j]-1] += 1
ans = inf
for (i,j,k) in permutations(range(c),3):
    cur = 0
    for l in range(c):
        cur += D[l][i]*C0[l]+D[l][j]*C1[l]+D[l][k]*C2[l]
    ans = min(ans,cur)
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
inf = 10**10

n = int(input())
ans = inf
def f(x):
    cur = 0
    while x >0:
        cur += x % 10
        x = x //10
    return cur
for a in range(1,n):
    b = n-a
    ans = min(ans,f(a)+f(b))
print(ans)

Fixed submission:
inf = 10**10

n = int(input())
ans = inf
def f(x):
    cur = 0
    while x >0:
        cur += x % 10
        x = x //10
    return cur
for a in range(1,n):
    b = n-a
    ans = min(ans,f(a)+f(b))
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = inf
def f(x):
    cur = 0
    while x >0:
        cur += x % 10
        x = x //10
    return cur
for a in range(1,n):
    b = n-a
    ans = min(ans,f(a)+f(b))
print(ans)


Fixed submission:
inf = 10**10

n = int(input())
ans = inf
def f(x):
    cur = 0
    while x >0:
        cur += x % 10
        x = x //10
    return cur
for a in range(1,n):
    b = n-a
    ans = min(ans,f(a)+f(b))
print(ans)
Buggy python submission (verdict: Runtime Error):

a,b = map(int().input().split())
print(max(a+b,a-b,a*b))

Fixed submission:
a,b = map(int,input().split())
print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
s = [0] * (n+1)
ans = 0
for i in range(n):
    s[i+1] = s[i] + a[i]
c = Counter(s)
for i in c:
    ans += int(c[i]*(c[i]-1)//2)
print(ans)


Fixed submission:
n = int(input()) 
a = [int(i) for i in input().split()]
d = dict()
d[0] = 1
ans = 0
t = 0
for i in range(n):
    t += a[i]

    s = d.get(t,0)
    ans += s 
    d[t] = s+1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
X = list(map(int,input().split()))


for i in range(N):
    Y = copy.copy(X)
    del Y[i]
    Y.sort()
    print(Y[N//2-1])


Fixed submission:
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
m1= Y[N//2-1]
m2 = Y[N//2]
for i in range(N):
    if X[i] <= m1:
        print(m2)
    else:
        print(m1)