Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02953 (python)

Fixed submission:
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()
H = LI()

# 短調非減少 H[i] <= H[i+1]
# 隣接要素を比較して大きかったら、必ず-1しておく
H[0]-=1
for i in range(N-1):
  if H[i] < H[i+1]:
    H[i+1] -= 1
  elif H[i] > H[i+1]:
    print("No")
    exit()
print("Yes")



# if N ==1:
#     print('Yes')
#     exit()
# ans = True
# for i in range(N-1):
#     if H[i] <= H[i+1]:
#         # print(i,'1')
#         continue
#     elif (not i==0) and H[i]-1 == H[i+1]:
#         if not H[i-1] == H[i]:
#             H[i] -= 1
#             # print(i,'2')
#             continue
#     # print(i,'3')
#     ans = False
#     break

# if ans:
#     print('Yes')
# else:
#     print('No')

Buggy submission (verdict: Runtime Error):
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()
H = LI()

# 短調非減少 H[i] <= H[i+1]

if N ==1:
    print('Yes')
    break
ans = True
for i in range(N-1):
    if H[i] <= H[i+1]:
        # print(i,'1')
        continue
    elif (not i==0) and H[i]-1 == H[i+1]:
        if not H[i-1] == H[i]:
            H[i] -= 1
            # print(i,'2')
            continue
    # print(i,'3')
    ans = False
    break

if ans:
    print('Yes')
else:
    print('No')
Problem p03361 (python)

Fixed submission:
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

# grid
# N = I()
# 黒く塗りつぶす#が独立していたら不可
H,W = LI()
S = [list(_S()) for _ in range (H)]

def check(x, y):
    # 移動する4方向をループ
    res = False
    # for dx,dy in itertools.product([-1,0,1],repeat=2):
    dxs = [-1,1]
    dys = [-1,1]
    for dx in dxs:
        nx = x + dx
        ny = y
        if 0 <= nx and nx < H and S[nx][ny] == "#":
            res = True
    for dy in dys:
        nx = x
        ny = y + dy
        if 0 <= ny and ny < W and S[nx][ny] == "#":
            res = True
    return res

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            if not check(i,j):
                print('No')
                exit()

print('Yes')

Buggy submission (verdict: Runtime Error):
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

# grid
# N = I()
# 黒く塗りつぶす#が独立していたら不可
H,W = LI()
S = [list(_S()) for _ in range (H)]

def check(x, y):
    # 移動する4方向をループ
    res = False
    # for dx,dy in itertools.product([-1,0,1],repeat=2):
    dxs = [-1,1]
    dys = [-1,1]
    for dx in dxs:
        nx = x + dx
        ny = y
        if 0 <= nx and nx < H and S[nx][ny] == "#":
            res = True
    for dy in dys:
        nx = x
        ny = y + dy
        if 0 <= ny and ny < H and S[nx][ny] == "#":
            res = True
    return res

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            if not check(i,j):
                print('No')
                exit()

print('Yes')
Problem p03449 (python)

Fixed submission:
import math
import sys
import os
from operator import mul
import numpy as np

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


N = I()
A1 = LI()
A2 = LI()

if N == 1:
    print(A1[0]+A2[0])
    exit()

ans = 0
for i in range(N):
    ans = max(ans, sum(A1[:i])+sum(A2[i-1:]))


# A1n = np.zeros(N,dtype='int')
# A1n = np.array(A1)
# A2n = np.zeros(N,dtype='int')
# A2n = np.array(A2)

# A1_cum = np.zeros(N,dtype='int')
# A2_cum = np.zeros(N,dtype='int')
# A1_cum[1:] = A1n[1:].cumsum()
# A2_cum[1:] = A2n[:-1].cumsum()
# # print(A1_cum)
# # print(A2_cum)

# # 下に降りる最初の位置
# start = N - 2
# for i in range(N-1):
#     if A1_cum[N-1] - A1_cum[i] < A2_cum[N-1] - A2_cum[i]:
#         start = i
#         break

# ans = A1n[0] + A2n[-1] + A1_cum[start] + (A2_cum[-1] - A2_cum[start])

# # ans = sum(A1) + sum(A2) - min(A1[-1],A2[0]+A2[1])

print(ans)

Buggy submission (verdict: Runtime Error):
import math
import sys
import os
from operator import mul
import numpy as np

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


N = I()
A1 = LI()
A2 = LI()

A1n = np.zeros(N,dtype='int')
A1n = np.array(A1)
A2n = np.zeros(N,dtype='int')
A2n = np.array(A2)

A1_cum = np.zeros(N,dtype='int')
A2_cum = np.zeros(N,dtype='int')
A1_cum = A1n[1:].cumsum()
A2_cum = A2n[:-1].cumsum()
# print(A1_cum)
# print(A2_cum)

# 下に降りる最初の位置
start = N - 2
for i in range(N-1):
    if A1_cum[N-2] - A1_cum[i] < A2_cum[N-2] - A2_cum[i]:
        start = i
        break

ans = A1n[0] + A2n[-1] + A1_cum[start] + (A2_cum[N-2] - A2_cum[start])

print(ans)
Problem p03963 (python)

Fixed submission:
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N,K = LI()

ans = K*(K-1)**(N-1)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N,K = LI()

ans = K*(K-1)**(N-1)
print(ans)
Problem p02618 (python)

Fixed submission:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]

last = {}
for i in range(1,27):
    last[i] = 0

for d in range(1,D+1):
    ans = [1,0]
    for i in range(1,27):
        satisfaction = 0
        satisfaction += s[d-1][i-1]
        for j in range(1,27):
            if i != j:
                satisfaction -= c[j-1]*(d-last[j])
        if ans[1] <= satisfaction:
            ans = [i,satisfaction]
    last[ans[0]] = d
    print(ans[0])

Buggy submission (verdict: Runtime Error):
from math import randint
for i in range(365):
  print(randint(1,2))

Buggy submission (verdict: Runtime Error):
from math import randint()
for i in range(365):
  print(randint(1,26))
Problem p02619 (python)

Fixed submission:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]

last = {}
for i in range(1,27):
    last[i] = 0

satisfaction = 0
for d in range(1,D+1):
    satisfaction += s[d-1][t[d-1]-1]
    last[t[d-1]] = d
    for i in range(1,27):
        satisfaction -= c[i-1]*(d-last[i])
    print(satisfaction)

Buggy submission (verdict: Runtime Error):
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]

last = {}
for i in range(1,27):
    last[i] = 0

satisfaction = 0
for d in range(1,D+1):
    satisfaction += s[d-1][t[d-1]-1]
    last[t[d-1]] = d
    for i in range(26):
        satisfaction -= c[d-1]*(d-last[t[d-1]])
    print(satisfaction)
Problem p02713 (python)

Fixed submission:
from math import gcd

K = int(input())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        g = gcd(a,b)
        if g == 1:
            ans += K
        else:
            for c in range(1,K+1):
                ans += gcd(g,c)

print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd

K = int(input())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        g = gcd(a,b)
        if g == 1:
            ans += K
        else:
            for c in range(1,K+1):
                ans += gcd(g,c)
                cnt += 1
print(ans)
Problem p02787 (python)

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

magics = []
for i in range(N):
    magics.append(list(map(int,input().split())))

#どう考えてもTLEだけどとりあえず
DP = [10**9]*(H+1)
DP[0] = 0
for i in range(N):
    for j in range(min(magics[i][0],H+1)):
        DP[j] = min(DP[j],magics[i][1])
    for j in range(magics[i][0],H+1):
        DP[j] = min(DP[j],DP[j-magics[i][0]]+magics[i][1])

print(DP[H])

Buggy submission (verdict: Runtime Error):
H,N = list(map(int,input().split()))
INF = 10 ** 12

magics = []
for i in range(N):
    magics.append(list(map(int,input().split())))

#どう考えてもTLEだけどとりあえず
DP = [10**9]*(H+1)
DP[0] = 0
for i in range(N):
    for j in range(magics[i][0]):
        DP[j] = min(DP[j],magics[i][1])
    for j in range(magics[i][0],H+1):
        DP[j] = min(DP[j],DP[j-magics[i][0]]+magics[i][1])

print(DP[H])

Buggy submission (verdict: Runtime Error):
H,N = list(map(int,input().split()))
INF = 10 ** 12

magics = []
for i in range(N):
    magics.append(list(map(int,input().split())))

#どう考えてもTLEだけどとりあえず
DP = [10**9]*(H+1)
DP[0] = 0
for i in range(N):
    for j in range(magics[i][0]):
        DP[j] = min(DP[j],magics[i][1])
    for j in range(magics[i][0],H+1):
        DP[j] = min(DP[j],DP[j-magics[i][0]]+magics[i][1])

print(DP[H])
Problem p02838 (python)

Fixed submission:
from math import log
def main():
    N = int(input())
    A = list(map(int,input().split()))
    mod = 10**9+7
    
    digits_cnt1 = [0]*60
    for ai in A:
        if ai == 0:
            continue
        #2**60-1みたいな時にfloatの桁落ちが生じるが、元々の桁数を超えるとai>>dがfalseになるのでlist index out of rangeは生じない
        for d in range(int(log(ai)/log(2))+1):
            if ai>>d & 1:
                digits_cnt1[d] += 1
    
    ans = 0
    for i in range(60):
        ans += digits_cnt1[i]*(N-digits_cnt1[i])*pow(2,i,mod)
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from math import log2
def main():
    N = int(input())
    A = list(map(int,input().split()))
    mod = 10**9+7
    
    digits_cnt1 = [0]*60
    for ai in A:
        if ai == 0:
            continue
        #2**60-1みたいな時にfloatの桁落ちが生じるが、ai>>dが必ずfalseになるのでlist index out of rangeは生じない
        for d in range(int(log2(ai))+1):
            if ai>>d & 1:
                digits_cnt1[d] += 1
    
    ans = 0
    for i in range(60):
        ans += digits_cnt1[i]*(N-digits_cnt1[i])*pow(2,i,mod)
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from math import log2
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

digits_cnt1 = [0]*60
for ai in A:
    for d in range(int(log2(ai))+1):
        if ai>>d & 1:
            digits_cnt1[d] += 1

ans = 0
for i in range(60):
    ans += digits_cnt1[i]*(N-digits_cnt1[i])*2**i
    ans %= mod
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
def main():
    input = sys.stdin.readline
    N,Q = list(map(int,input().split()))
    edges = [[] for i in range(N+1)]
    for i in range(N-1):
        a,b = list(map(int,input().split()))
        edges[a].append(b)
        edges[b].append(a)

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

    stack = [(1,0)]
    ans = [0]*(N+1)
    not_checked = [True]*(N+1)
    while stack:
        v,cnt = stack.pop()
        ans[v] = cnt+add[v]
        not_checked[v] = False
        for edge in edges[v]:
            if not_checked[edge]:
                stack.append((edge,ans[v]))

    for i in range(1,N):
        print(ans[i],end=" ")
    print(ans[N])

if __name__ == "__main__":
    main()

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

connections = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = list(map(int,input().split()))
    connections[a].append(b)
    connections[b].append(a)

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

ans = [0]*(N+1)
checked = [False]*(N+1)

def add(point,num):
    ans[point] += num
    checked[point] = True
    for c in connections[point]:
        if checked[c]:
            continue
        else:
            add(c,num+add_list[c])
            
add(1,add_list[1])

for i in range(1,N):
    print(ans[i],end=' ')
print(ans[N])

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

connections = [[] for i in range(N+1)]

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

add_list = [0]*(N+1)

for i in range(Q):
    p,x = list(map(int,input().split()))
    add_list[p] += x

ans = [0]*(N+1)
checked = [False]*(N+1)
def add(point,num):
    ans[point] += num
    checked[point] = True
    for c in connections[point]:
        if checked[c]:
            continue
        else:
            add(c,num+add_list[c])
        
add(1,add_list[1])

for i in range(1,N):
    print(ans[i],end=' ')
print(ans[N])
Problem p02983 (python)

Fixed submission:
L,R = list(map(int, input().split()))
 
if R-L > 673:
    print(0)
else:
    min_mod = 2019
    for i in range(L,R):
        i_mod = i%2019
        for j in range(i+1,R+1):
            j_mod = j%2019
            mod = (i_mod*j_mod)%2019
            if mod < min_mod:
                min_mod = mod
        
    print(min_mod)

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

if R-L > 2019:
    print(0)
else:
    i_mod = 2019
    j_mod = 2019
    for k in range(L,R+1):
        mod = k%2019
        if mod < i_mod:
            j_mod = i_mod
            i_mod = mod
        elif mod < j_mod: #要るかこれ？
            j_mod = mod
print(i_mod*j_mod)
Problem p02995 (python)

Fixed submission:
import fractions

A,B,C,D = list(map(int, input().split()))

C_div = B//C - (A-1)//C
D_div = B//D - (A-1)//D
CandD = int(C*D/fractions.gcd(C, D))
CandD_div = B//CandD - (A-1)//CandD

print(B-(A-1)-C_div-D_div+CandD_div)

Buggy submission (verdict: Runtime Error):
import math

A,B,C,D = list(map(int, input().split()))

C_div = B//C - (A-1)//C
D_div = B//D - (A-1)//D
CandD = int(C*D/math.gcd(C, D))
CandD_div = B//CandD - (A-1)//CandD

print(B-(A-1)-C_div-D_div+CandD_div)
Problem p03076 (python)

Fixed submission:
menu = []
for i in range(5):
    menu.append(int(input()))

min_reminder = 10
min_menu = 5
for i in range(5):
    reminder = menu[i]%10
    if reminder < min_reminder and reminder != 0:
        min_reminder = reminder
        min_menu = i
 
total = 0
for i in range(5):
    if min_menu == i or menu[i]%10 == 0:
        total += menu[i]
    else:
        total += menu[i]+10-menu[i]%10
        
print(total)

Buggy submission (verdict: Runtime Error):
menu = []
for i in range(5):
    menu.append(int(input()))

menu_kiriage = []
min_reminder = 10
for i in range(5):
    reminder = menu[i]%10
    if reminder < min_reminder and reminder != 0:
        min_reminder = reminder
        min_menu = i

total = 0
for i in range(5):
    if min_menu == i:
        total += menu[i]
    else:
        total += menu[i]+10-menu[i]%10 if menu[i]%10 != 0 else menu[i]
        
print(total)
Problem p03210 (python)

Fixed submission:
year = int(input())
if year == 3 or year == 5 or year == 7:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
year = int(input())
if year == 3 or year == 5 or year == 7:
  print(YES)
else:
  print(NO)
Problem p03211 (python)

Fixed submission:
str_list = list(input())
min = 1000
for i in range(len(str_list)-2):
  str = str_list[i]+str_list[i+1]+str_list[i+2]
  dif = abs(int(str)-753)
  if dif < min:
    min = dif
print(min)

Buggy submission (verdict: Runtime Error):
str_list = list(input())
min = 1000
for i in range(len(list)-2):
  str = str_list[i]+str_list[i+1]+str_list[i+2]
  dif = abs(int(str)-753)
  if dif < min:
    min = dif
print(min)
Problem p03244 (python)

Fixed submission:
import collections

N = int(input())
v = list(map(int,input().rstrip().split()))
list_odd = v[0::2]
list_even = v[1::2]

odd_count = collections.Counter(list_odd).most_common()
even_count = collections.Counter(list_even).most_common()

if len(odd_count) == 1 and len(even_count) == 1:
    if odd_count[0][0] == even_count[0][0]:
        print(N//2)
    else:
        print(0)
elif odd_count[0][0] != even_count[0][0]:
    print(N-odd_count[0][1]-even_count[0][1])
elif len(odd_count) == 1:
    print(N//2-even_count[1][1])
elif len(even_count) == 1:
    print(N//2-odd_count[1][1])
else:
    print(min(N-odd_count[0][1]-even_count[1][1], N-even_count[0][1]-odd_count[1][1]))

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())
v = list(map(int,input().rstrip().split()))
list_odd = v[1::2]
list_even = v[0::2]

odd_count = collections.Counter(list_odd)
even_count = collections.Counter(list_even)


max_flq_odd = [kv for kv in odd_count.items() if kv[1] == max(odd_count.values())]
max_flq_even = [kv for kv in even_count.items() if kv[1] == max(even_count.values())]


if max_flq_odd[0][0] != max_flq_even[0][0] or len(max_flq_odd) > 1 or len(max_flq_even) > 1:
    #最大値のキーが違うものは最初にはじいた方が良い？
    print(N-max_flq_odd[0][1]-max_flq_even[0][1])
elif len(odd_count) == 1 and len(even_count) == 1:
    #数字が一種類しかない
    print(N//2)
elif len(odd_count) == 1:
    even_count.pop(max_flq_even[0][0])
    secondmax_even = max(even_count.values())
    print(N//2-secondmax_even)
elif len(even_count) == 1:
    odd_count.pop(max_flq_odd[0][0])
    secondmax_odd = max(odd_count.values())
    print(N//2-secondmax_odd)
else:
    even_count.pop(max_flq_even[0][0])
    secondmax_even = max(even_count.values())
    odd_count.pop(max_flq_odd[0][0])
    secondmax_odd = max(odd_count.values())
    print(min(N-max_flq_odd-secondmax_even, N-max_flq_even-secondmax_odd))

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())
v = list(map(int,input().rstrip().split()))
list_odd = v[0::2]
list_even = v[1::2]

odd_count = collections.Counter(list_odd)
even_count = collections.Counter(list_even)


max_flq_odd = [kv for kv in odd_count.items() if kv[1] == max(odd_count.values())]
max_flq_even = [kv for kv in even_count.items() if kv[1] == max(even_count.values())]

if odd_count == even_count and len(odd_count) == 1:
    #数字が一種類しかない
    print(N//2)
elif max_flq_odd == max_flq_even and len(max_flq_odd) == 1:
    #最大値が同じで一種類しかない
    odd_wo_max = [kv for kv in odd_count if kv[1] != max(odd_count.values())]
    secondmax_odd = [kv for kv in odd_wo_max.items() if kv[1] == max(odd_wo_max.values())]
    even_wo_max = [kv for kv in odd_count if kv[1] != max(odd_count.values())]
    secondmax_even = [kv for kv in even_wo_max.items() if kv[1] == max(even_wo_max.values())]
    secondmax = max(secondmax_odd,secondmax_even)
    print(N-max_flq_odd-secondmax)
else:
    #最大値が違うか、最大値をとるキーが複数あり代替がきく
    print(N-max_flq_odd[0][1]-max_flq_even[0][1])
Problem p03330 (python)

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

discomforts = [[0]*(N+1)]
for _ in range(C):
    row = [0]
    row.extend(list(map(int,input().split())))
    discomforts.append(row)
grid = [[0]*(N+1)]
for _ in range(N):
    row = [0]
    row.extend(list(map(int,input().split())))
    grid.append(row)

color_counts = [[0]*(C+1) for i in range(3)]

for i in range(1,N+1):
    for j in range(1,N+1):
        color_counts[(i+j)%3][grid[i][j]] += 1

ans = float('inf')
for c0 in range(1,C+1):
    for c1 in range(1,C+1):
        for c2 in range(1,C+1):
            if c0 != c1 and c1 != c2 and c2 != c0:
                total = 0
                for i in range(1,C+1):
                    total += discomforts[i][c0]*color_counts[0][i]
                    total += discomforts[i][c1]*color_counts[1][i]
                    total += discomforts[i][c2]*color_counts[2][i]
                ans = min(ans,total)
print(ans)

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

discomforts = [[0]*(N+1)]
for _ in range(C):
    discomforts.append([0,*map(int,input().split())])
print(discomforts)
grid = [[0]*(N+1)]
for _ in range(N):
    grid.append([0,*map(int,input().split())])

color_counts = [[0]*(C+1) for i in range(3)]

for i in range(1,N+1):
    for j in range(1,N+1):
        color_counts[(i+j)%3][grid[i][j]] += 1

ans = float('inf')
for c0 in range(1,C+1):
    for c1 in range(1,C+1):
        for c2 in range(1,C+1):
            if c0 != c1 and c1 != c2 and c2 != c0:
                total = 0
                for i in range(1,C+1):
                    total += discomforts[i][c0]*color_counts[0][i]
                    total += discomforts[i][c1]*color_counts[1][i]
                    total += discomforts[i][c2]*color_counts[2][i]
                ans = min(ans,total)
print(ans)