Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    #1. input
    m,n = map(int, input().split())
    
    #2. make the list of valid field
    valid_field = list()
    for i in range(1,m+1):
        for j in range(1, n+1):
            valid_field.append([i,j])
    
    #3. judge the number of being turned
    num_being_turned = [0]*len(valid_field)
    cnt = 0
    for i in range(1, m+1):
        for j in range(1, n+1):
            num_being_turned[cnt] = int([i-1,j-1] in valid_field) \
                                                      + int([i-1,j] in valid_field) \
                                                      + int([i-1,j+1] in valid_field) \
                                                      + int([i,j-1] in valid_field) \
                                                      + int([i,j] in valid_field) \
                                                      + int([i,j+1] in valid_field) \
                                                      + int([i+1,j-1] in valid_field) \
                                                      + int([i+1,j] in valid_field) \
                                                      + int([i+1,j+1] in valid_field)
            cnt = cnt+1
                                           
    #4. output
    for i in range(len(num_being_turned)):
        num_being_turned[i] = num_being_turned[i] % 2
    
    print(sum(num_being_turned))

if __name__ == "__main__":
    main()

Fixed submission:
#1. input
# set N<=M 
N, M = map(int, input().split())

if N>M:
    temp = N
    N = M
    M = temp

#2. N=1 -> M-2 (if M=1, ans=1)
#    N=2 -> ans = 0
#    N>3 -> ans = NM - {2(M+N)-4}
if N == 1:
    if M == 1:
        ans = 1
    else:
        ans = M-2
elif N == 2:
    ans = 0
else:
    ans = M*N - 2*(M+N) +4
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

cand = 0

def digit_sum(num:int, base:int) -> int:
    if num < base:
        return num
    else:
        return digit_sum(int(num/base), base) + (num % base)

def judge(n: int) -> int:
    if n < 10:
        return n
    
    else:
        # 先頭の位が1のとき、先頭の1を落として全部9にしたものが候補
        if str(n)[0:1] == '1':
            cand = n % 10**(len(str(n)) - 1)
            print(cand)
            
            cand_str = "9"*len(str(cand))
            cand = int(cand_str)
            
            print(cand)
            
            return max(digit_sum(n,10), digit_sum(cand,10))
        
        # そうでないとき、先頭の位を1小さくする
        else:
            top = n // 10**(len(str(n)) - 1)
            cand_str = str(top-1) + "9" * (len(str(n))-1)
            cand = int(cand_str)
            
            return max(digit_sum(n,10), digit_sum(cand,10))
            
        
    


print(ans)

Fixed submission:
def digit_sum(n:int) -> int:
    res = n
    ans = 0
    while res > 0:
        ans = ans + res%10
        res //= 10
    
    return ans

def keta(n:int) -> int:
    res = n
    ans = 0
    while res > 0:
        ans += 1
        res //= 10
    return ans

n = int(input())
n_keta = keta(n)

ans = 0
if n >= 2*10**(n_keta-1):
    ans = n // 10**(n_keta-1) - 1
    ans += 9 * (n_keta-1)
    
elif n == 2*10**(n_keta-1) - 1:
    ans = digit_sum(n)
    
else:
    ans = 9 * (n_keta-1)
    
ans = max(ans, digit_sum(n))
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

graph = [[] for _ in range(n)]


for _ in range(m):
    l, r, d = map(int, input().split())
    graph[l - 1].append(( d,r - 1))
    graph[r - 1].append((-d,l - 1))

INF = float("inf")
dist = [-INF]*n

# 未探索ノードの距離を0とする
for n in range(n):
    if dist[n] != -INF:
        continue
    else:
        stack = [n]
        dist[n] = 0
        
    # stackが空になるまで探索を繰り返す
    while len(stack):
        cur = stack.pop()
        
        # ノードcurと隣り合う未探索ノードをstackに追加
        for cost, nex_node in graph[cur]:
            if dist[nex_node] != -INF:
                continue
            else:
                dist[nex_node] = dist[cur] + cost
                stack.append(nex_node)

flag = True
for i in range(n):
    if not flag:
        break
    for d,node in graph[i]:
        if dist[node]-dist[i] != d:
            print("No")
            flag = False

if flag:
    print("Yes")

Fixed submission:
# 1.入力
X = int(input())
A = int(input())
B = int(input())

# 2.制約チェック
if A<1 or A>1000:
    print("制約条件1<=A<=1000")
    raise ValueError
elif B<1 or B>1000:
    print("制約条件1<=B<=1000")
    raise ValueError
elif X<A+B or X>10000:
    print("制約条件A+B<=X<=10000")
    raise ValueError

# 3.Aを引く
residue = X-A

# 4.Bを引く
while(1):
    if residue-B >= 0:
        residue = residue-B
    else:
        break
    
    
# 5.結果の表示
print(residue)
Buggy python submission (verdict: Runtime Error):
# input
a, b = input().split()

# constraints
if type(a)!='int' or type(b)!='int':
    print('型がintではありません')
    raise TypeError

if a > 1000 or b > 10000 or a<0 or b<0:
    print('制約違反です')
    raise ValueError
    

# result
if (a*b)%2 == 0:
    print('Even')
else:
    print('odd')    

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

# result
if (a*b)%2 == 0:
    print('Even')
else:
    print('Odd')

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

# constraints
if a > 1000 or b > 10000 or a<0 or b<0:
    print('制約違反です')
    raise ValueError

# result
if (a*b)%2 == 0:
    print('Even')
else:
    print('odd')    

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

# result
if (a*b)%2 == 0:
    print('Even')
else:
    print('Odd')
Buggy python submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**6) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

k = ni()
a = list(li())

exist = True

# lower
for i, ai in enumerate(a[::-1]):
    if i == 0:
        if ai != 2:
            exist = False
            break
        else:
            upper = 3
            lower = 2
            
    else:
        exist = False
        for yi in range(lower, upper+1):
            if yi % ai == 0:
                lower = yi
                upper = lower+ai-1
                exist = True
                break
            
        if not exist:
            break
                
                
                
ans_lower = lower


# upper
for i, ai in enumerate(a[::-1]):
    if i == 0:
        if ai != 2:
            exist = False
            break
        else:
            upper = 3
            lower = 2
            
    else:
        exist = False
        for yi in range(upper, lower-1, -1):
            if yi % ai == 0:
                lower = yi
                upper = lower+ai-1
                exist = True
                break
            
        if not exist:
            break
                
    
ans_upper = upper

        
print(ans_lower, ans_upper) if exist else print(-1)
        
        

Fixed submission:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def judge(k:int, a:list):
    mi = ma = 2
    for ai in a[::-1]:
        # miをaiの倍数に切り上げる
        if mi%ai:
            mi += ai - mi%ai
            
        ma += (ai - 1) - (ma % ai)
        
        if ma < mi:
            return False, (-1,-1)
        
    return True, (mi,ma)

k = ni()
a = list(li())

tf, (mi,ma) = judge(k,a)
if tf:
    print(mi,ma)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,y = li()

yuki_max = y // 10000
ichi_max = y // 5000

ans_y = -1
ans_i = -1
ans_h = -1

for yukichi in range(yuki_max+1):
    for ichiyo in range(ichi_max+1):
        hideyo = (y - 10000*yukichi - 5000*ichiyo) // 1000
        if hideyo < 0:
            continue
        
        if yukichi + ichiyo + hideyo == n:
            ans_y = yukichi
            ans_i = ichiyo
            ans_h = hideyo
            break

print(ans_y, ans_i, ans_h)

Fixed submission:

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


def greedy(Y):
    res = Y
    yukichi = 0
    ichiyo = 0
    hideyo = 0
    while res >= 10000:
        res -= 10000
        yukichi += 1
        
    while res >= 5000:
        res -= 5000
        ichiyo += 1
        
    while res > 0:
        res -= 1000
        hideyo += 1
        
    return yukichi, ichiyo, hideyo
    

def confirm_N(N,Y,yukichi,ichiyo,hideyo):
    bill = yukichi+ichiyo+hideyo
    if N<bill:
        return [-1,-1,-1]
    elif N == bill:
        return [yukichi, ichiyo, hideyo]
    
    while yukichi >= 0:
        if bill == N:
            return [yukichi, ichiyo, hideyo]
        
        while ichiyo > 0:
            bill += 4
            hideyo += 5
            ichiyo -= 1
            if bill == N:
                return [yukichi, ichiyo, hideyo]
        
        yukichi -= 1
        ichiyo = (Y-yukichi*10000) // 5000
        hideyo = (Y-yukichi*10000-ichiyo*5000) // 1000
        
        bill = yukichi+ichiyo+hideyo
    
    return [-1,-1,-1]

#1.まず貪欲

yukichi, ichiyo, hideyo = greedy(Y)

bill = yukichi+ichiyo+hideyo

ans_lst = confirm_N(N, Y, yukichi, ichiyo, hideyo)

print(*ans_lst)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect_left
from math import ceil

file = open("ABC085D.txt","r")

N,H = map(int, file.readline().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, file.readline().split())
    A.append(a)
    B.append(b)
    
# 最も強いaを探す
a_max = max(A)

# それ以上のbを探す
b_strong = []
for b in B:
    if b >= a_max:
        b_strong.append(b)
        
# bをソートしてcum作る
b_strong.sort(reverse=True)
b_cum = list(accumulate(b_strong))
b_cum = [0] + b_cum
    
# もしHPがb_cum[-1]なら投げてるうちに倒せる
if H <= b_cum[-1]:
    ans = bisect_left(b_cum, H)
    
else:
    ans = len(b_cum) - 1
    ans += ceil((H - b_cum[-1]) / a_max)
    
print(ans)

Fixed submission:
from itertools import accumulate
from bisect import bisect_left
from math import ceil

N,H = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(tuple(map(int, input().split())))

# A昇順、B降順にソート
AB.sort(key=lambda x: (x[0], -x[1]))

# 最後の刀を装備する
equip = AB.pop()

# a_max < b なる刀を集める
b_list = []
for a,b in AB:
    if b > equip[0]:
        b_list.append(b)

# bを攻撃力の高い順に並べ替える
b_list.sort(reverse=True)
b_list_cum = list(accumulate(b_list))
b_list_cum = [0] + b_list_cum
 
ans = 0
# hpがb_list_cum[-1]以下なら、刀投げで終わる
if H <= b_list_cum[-1]:
    ans = bisect_left(b_list_cum,H)
    print(ans)

# 違えば、まずはb>=a_maxなる刀を全部投げ、equipでhp<=bになるまで攻撃し、
# 最後の1手で刀を投げる
else:
    ans = len(b_list_cum)-1
    res = H - b_list_cum[-1]
    a_attack = max(0, int(ceil((res-equip[1]) / equip[0])))
    
    # aで攻撃した分と、最後の1手の刀投げの分を足す
    ans += (a_attack + 1)
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()

graph = [[] for _ in range(n)]
for _ in range(m):
    l,r,d = li()
    l -= 1
    r -= 1
    graph[l].append((d,r))
    graph[r].append((-d,l))
    
searched = [False]*n
dist = [float("inf") for _ in range(n)]

exist = True
for i in range(n):
    if not searched[i]:
        dist[i] = 0
        searched[i] = True
        stack = [(0,i)]
        
        while stack:
            cost, cur = stack.pop()
            for nex_cost, nex_node in graph[cur]:
                if searched[nex_node]:
                    if cost + nex_cost != dist[nex_node]:
                        exist = False
                        
                else:
                    stack.append((cost+nex_cost, nex_node))
                    dist[nex_node] = cost + nex_cost
                    searched[nex_node] = True
                    
print("Yes") if exist else print("No")

Fixed submission:
S = input()
N = len(S)

ans = N//2 + bool(N%2)


# 奇数
if N%2 == 1:
    left = S[:N//2]
    left = left[::-1]
    right = S[N//2+1:]
    cent = S[N//2]
    
    i = 0
    while i < N//2:
        if left[i] == cent and right[i] == cent:
            ans += 1
            i += 1
        else:
            break
        
else:
    left = S[:N//2]
    left = left[::-1]
    right = S[N//2:]
    cent = S[N//2]
    
    i = 0
    while i < N//2:
        if left[i] == cent and right[i] == cent:
            ans += 1
            i += 1
        else:
            break
        
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


# 回文判定
def judge(s):
    news = ""
    for si in s:
        if si != 'x':
            news += si

    if news == news[::-1]:
        return True
    else:
        return False

# 操作の最小値
def min_insertion(s):
    news = ""
    for si in s:
        if si != 'x':
            news += si

    n = len(news)
    fir = [0] * ((n+1)//2)
    lat = [0] * ((n + 1) // 2)

    # 前半
    cursor = 0
    for si in s:
        if si == 'x':
            fir[cursor] += 1
        else:
            cursor += 1

        if cursor == (n+1)//2:
            break

    # 後半
    cursor = 0
    for si in s[::-1]:
        if si == 'x':
            lat[cursor] += 1
        else:
            cursor += 1

        if cursor == (n + 1) // 2:
            break

    ans = 0
    for firi, lati in zip(fir, lat):
        ans += abs(firi - lati)

    return ans


# 入力
s = ns()

# x以外の回文判定
is_kaibun = judge(s)

# 回文でないならおわり
# 回文ならば最小値出す
if is_kaibun:
    print(min_insertion(s))
else:
    print(-1)


Fixed submission:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

s = deque(lc())
lens = len(s)

ok = True
ans = 0

while len(s):
    if len(s) == 1:
        s.pop()
    
    elif s[0] == s[-1]:
        s.pop()
        s.popleft()
        
    else:
        if s[0] == "x":
            s.append("x")
            ans += 1
        elif s[-1] == "x":
            s.appendleft("x")
            ans += 1
        else:
            ok = False
            break
    
if ok:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
#import sys
#stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def dfs(graph:list, node:int, start:int) -> list:
    # 未探索のノードは距離INF
    INF = float("inf")
    dist = [INF]*node
    
    # 始点ノードの距離を0とし、dfsのためのstackを作成
    dist[start] = 0
    stack = [(0,start)]
    
    while stack:
        cost, cur_node = stack.pop()

        # 未探索のノードをstackに入れる
        for nex_cost, nex_node in graph[cur_node]:
            if dist[nex_node] != INF:
                continue
            else:
                dist[nex_node] = dist[cur_node] + nex_cost
                stack.append((dist[nex_node],nex_node))
                
    return dist

def isnibu(graph:list, dist:list) -> bool:
    for i,edges in enumerate(graph):
        for _, j in edges:
            if dist[i]%2 == dist[j]%2:
                return False
    
    return True
    
    

n,m = li()

adj_lst = [set() for _ in range(n)]

for _ in range(m):
    a,b = li_()
    
    adj_lst[a].add((1,b))
    adj_lst[b].add((1,a))
    
dist = dfs(adj_lst, n, 0)

nibu = isnibu(adj_lst, dist)

ans = 0
if isnibu(adj_lst, dist):
    ans = sum([dist[i]%2 == 1 for i in range(n)]) * sum([dist[i]%2 == 0 for i in range(n)]) - m
    
else:
    ans = n*(n-1)//2 - m
    
print(ans)

Fixed submission:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def dfs(graph:list, node:int, start:int) -> list:
    # 未探索のノードは距離INF
    INF = float("inf")
    dist = [INF]*node
    
    # 始点ノードの距離を0とし、dfsのためのstackを作成
    dist[start] = 0
    stack = [(0,start)]
    
    while stack:
        cost, cur_node = stack.pop()

        # 未探索のノードをstackに入れる
        for nex_cost, nex_node in graph[cur_node]:
            if dist[nex_node] != INF:
                continue
            else:
                dist[nex_node] = dist[cur_node] + nex_cost
                stack.append((dist[nex_node],nex_node))
                
    return dist

def isnibu(graph:list, dist:list) -> bool:
    for i,edges in enumerate(graph):
        for _, j in edges:
            if dist[i]%2 == dist[j]%2:
                return False
    
    return True
    
    

n,m = li()

adj_lst = [set() for _ in range(n)]

for _ in range(m):
    a,b = li_()
    
    adj_lst[a].add((1,b))
    adj_lst[b].add((1,a))
    
dist = dfs(adj_lst, n, 0)

nibu = isnibu(adj_lst, dist)

ans = 0
if isnibu(adj_lst, dist):
    ans = sum([dist[i]%2 == 1 for i in range(n)]) * sum([dist[i]%2 == 0 for i in range(n)]) - m
    
else:
    ans = n*(n-1)//2 - m
    
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,f = map(int, input().split())

ab_list = set()

for i in range(0,f//100+1,a):
    for j in range(0, f//100-i+1, b):
        ab_list.add(100*(i+j))

ab_max = max(ab_list)

sug_max = int(ab_max*(e/100))

cd_list = set()

for i in range(0,sug_max+1, c):
    for j in range(0, sug_max-i+1, d):
        cd_list.add(i+j)


water = list(ab_list)
water.sort()

sugar = list(cd_list)
sugar.sort()

s = 0
ans = [0,0]
max_noudo = 0
for w in water[1:]:
    while (sugar[s+1] <= int(w*e/100)):
        if (s+1) >= len(sugar)-1:
            break
        s += 1
        
    noudo = sugar[s]/(w+sugar[s])
    if noudo > max_noudo:
        max_noudo = noudo
        ans = [w+sugar[s], sugar[s]]
        
print(*ans)

Fixed submission:
a,b,c,d,e,f = map(int, input().split())

ab_list = set()

for i in range(0,f//100+1,a):
    for j in range(0, f//100-i+1, b):
        ab_list.add(100*(i+j))

ab_max = max(ab_list)

sug_max = int(ab_max*(e/100))

cd_list = set()

for i in range(0,sug_max+1, c):
    for j in range(0, sug_max-i+1, d):
        cd_list.add(i+j)

water = list(ab_list)
water.sort()

sugar = list(cd_list)
sugar.sort()

max_noudo = -1
ans = [0,-1]
for w in water:
    for s in sugar:
        if w==0 and s==0:
            continue
        if 100*s <= e*w and w+s <= f:
            noudo = s/(w+s)
            if noudo > max_noudo:
                max_noudo = noudo
                ans = [w+s, s]
                
print(*ans)
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

file = open("ABC074D.txt", "r")

n = int(file.readline())
graph = np.array([[0 for _ in range(n)] for _ in range(n)], dtype=float)
for i in range(n):
    graph[i] = np.array(list(map(int, file.readline().split())))
    
# ワーシャルフロイドで最短距離出す
shortest = floyd_warshall(graph, directed=False)


if any([graph[i,j] != shortest[i,j] for i in range(n) for j in range(n)]):
    print(-1)
    
else:
    total = 0
    INF = float("inf")
    
    for i in range(n):
        graph[i,i] = INF
    
    for i in range(n):
        for j in range(i+1,n):
            via_k = np.min(graph[i] + graph[j])
            
            if via_k > graph[i,j]:
                total += graph[i,j]
                
    print(int(total))

Fixed submission:
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
import sys
sdin = sys.stdin.readline

n = int(sdin())
graph = np.array([[0 for _ in range(n)] for _ in range(n)], dtype=float)
for i in range(n):
    graph[i] = np.array(list(map(int, sdin().split())))
    
# ワーシャルフロイドで最短距離出す
shortest = floyd_warshall(graph, directed=False)


if any([graph[i,j] != shortest[i,j] for i in range(n) for j in range(n)]):
    print(-1)
    
else:
    total = 0
    INF = float("inf")
    
    for i in range(n):
        graph[i,i] = INF
    
    for i in range(n):
        for j in range(i+1,n):
            via_k = np.min(graph[i] + graph[j])
            
            if via_k > graph[i,j]:
                total += graph[i,j]
                
    print(int(total))