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

Fixed submission:
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    else:
        dfs(i + 1, f + "+" + abcd[i + 1], sum + int(abcd[i + 1]))
        dfs(i + 1, f + "-" + abcd[i + 1], sum - int(abcd[i + 1]))
abcd = input()
dfs(0, abcd[0], int(abcd[0]))

Buggy submission (verdict: Runtime Error):
def dfs(i, s, sum):
    if i == 3:
        if sum == 7:
            print(s + "=7")
            exit()
    dfs(i + 1, s + "+" + abcd[i + 1], sum + int(abcd[i + 1]))
    dfs(i + 1, s + "-" + abcd[i + 1], sum - int(abcd[i + 1]))
abcd = input()
dfs(0, abcd[0], int(abcd[0]))
Problem p03593 (python)

Fixed submission:
h,w=map(int,input().split())
a,l=[list(input())for i in range(h)],[0]*26
for i in a:
 for j in i:l[ord(j)-97]+=1
o,t,f=(h//2)*(w//2),(h//2)*(w%2)+(w//2)*(h%2),(h%2)*(w%2)
for i in l:
 while o and i>3:o-=1;i-=4
 while t and i>1:t-=1;i-=2
 f-=i
print("Yes"if o==t==f==0else"No")

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
a,l=[list(input())for i in range(h)],[0]*26
for i in a:
 for j in i:l[ord(j)-97]+=1
o,t,f=(h//2)*(w//2),(h//2)*(w%2)+(w//2)*(h%2),(h%2)*(w%2)
for i in l:
 while o and i>3:o-=1;i-=4
 while t and i>1:t-=1i-=2
 f-=i
print("Yes"if o==t==f==0else"No")
Problem p03624 (python)

Fixed submission:
alphabet = [chr(ord('a') + i) for i in range(26)]
s = list(input())
s = sorted(list(set(s)))
if len(s) == 26:
    print("None")
    exit()
for i in range(len(s)):
    if i == len(s) - 1:
        if s[i] == alphabet[i]:
            print(alphabet[i+1])
        else:
            print(alphabet[i])
        exit()
    if s[i] == alphabet[i]:
        pass
    else:
        print(alphabet[i])
        exit()

Buggy submission (verdict: Runtime Error):
alphabet = [chr(ord('a') + i) for i in range(26)]
s = list(input())
s = list(set(s))
s.sort()
for i in range(len(s)):
    if i == len(s) - 1:
        print(alphabet[i + 1])
        exit()
    elif s[i] == alphabet[i]:
        pass
    else:
        print(alphabet[i])
        exit()
print("None")
Problem p03826 (python)

Fixed submission:
input1 = list(map(int,input().split()))
A = input1[0]
B = input1[1]
C = input1[2]
D = input1[3]
if A * B >= C * D:
  print(A * B)
else:
  print(C * D)

Buggy submission (verdict: Runtime Error):
input1 = list(map(int,input().split()))
A = input1[0]
B = input1[1]
C = input1[2]
D = input1[3]
if A * B >= C * D
  print(A * B)
else:
  print(C * D)
Problem p03852 (python)

Fixed submission:
c = input()
if c == "a" or c == "e" or c == "i" or c == "o" or c == "u":
  print("vowel")
else:
  print("consonant")

Buggy submission (verdict: Runtime Error):
c = input()
if c == a or c == e or c == i or c == o or c == u:
  print("vowel")
else:
  print("consonant")
Problem p03957 (python)

Fixed submission:
s = list(input())
c = False
for i in range(len(s)):
    if s[i] == "C":
        c = True
    elif c and s[i] == "F":
        print("Yes")
        exit()
print("No")

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range(len(s)):
    if s[i] == "C":
        c = True
    elif c and s[i] == "F":
        print("Yes")
        exit()
print("No")
Problem p03999 (python)

Fixed submission:
def dfs(i, f):
    if i == len(s) - 1:
        return sum(list(map(int, f.split("+")))) 
    return dfs(i + 1, f + s[i + 1]) + \
           dfs(i + 1, f + "+" + s[i + 1])
 
s = input()
print(dfs(0, s[0]))

Buggy submission (verdict: Runtime Error):
def dfs(i, f):
    if i == len(s) - 1:
        return sum(list(map(int, f.split("+")))) 
    return dfs(i + 1, f + s[i + 1]) + \ 
    dfs(i + 1, f + "+" + s[i + 1])

s = input()
print(dfs(0, s[0]))

Buggy submission (verdict: Runtime Error):
def dfs(i, f):
    if i == len(s) - 1:
        return sum(list(map(int, f.split("+")))) 
    return dfs(i + 1, f + s[i + 1]) + \ dfs(i + 1, f + "+" + s[i + 1])

s = input()
print(dfs(0, s[0]))
Problem p04044 (python)

Fixed submission:
n, l = map(int, input().split())
S = [input() for i in range(n)]
sorted_list = sorted(S)
print(*sorted_list, sep="")

Buggy submission (verdict: Runtime Error):
n, l = map(int, input().split())
S = [int(input()) for i in range(n)]
sorted_list = sorted(S)
print(*sorted_list, sep="")
Problem p03433 (python)

Fixed submission:
x=int(input())
y=int(input())
if x%500<=y:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
x=input()
y=input()
if x%500<=y:
  print("Yes")
else:
  print("No")
Problem p03563 (python)

Fixed submission:
a=int(input())
b=int(input())
print(b*2-a)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
print(b*2-a)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print(b*2-a)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(b*2-a)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(int(b*2-a))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(b*2-a)
Problem p02574 (python)

Fixed submission:
from math import gcd

N = int(input())
A = list(map(int, input().split()))
MAX = 10**6 + 1

def prime_factor_sieve(n):
    """
    エラトステネスの篩で、
    2 ~ Nの各数に対して、その整数のもつ最小の素因数
    (その整数を篩落とした最小の素因数)を記録して返す
    O(nloglog(n))
    """
    res = [i for i in range(n+1)]
    for i in range(2, int(n**0.5)+1):
        if res[i] < i:
            continue
        for j in range(i*i, n+1, i):
            if res[j] == j:
                res[j] = i
    return res

def factorization(n, min_factor, used_factor, cnt):
    """
    エラトステネスの篩で手に入れた、各整数の最小素因数のリスト
    からO(log(n))で素因数分解する
    """
    
    while n > 1:
        if used_factor[min_factor[n]] == 0:
            used_factor[min_factor[n]] = cnt
        elif used_factor[min_factor[n]] != cnt:
            return False
        n //= min_factor[n]
        # 割った後の素因数についてもO(1)で参照できる
    return True


# 素因数が重複しているかを調べる
min_factor = prime_factor_sieve(MAX)
res = set()
is_ok = 1
used_factor = [0]*(MAX+1)
cnt = 1
for a in A:
    if a == 1:
        continue
    is_ok = factorization(a, min_factor, used_factor, cnt)
    cnt += 1
    if not is_ok:
        break

if is_ok:
    print("pairwise coprime")
else:
    g = A[0]
    for i in range(1, N):
        g = gcd(g, A[i])
    if g == 1:
        print("setwise coprime")
    else:
        print("not coprime")

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

N = int(input())
A = list(map(int, input().split()))
MAX = 10**6


def prime_factor_sieve(n):
    """
    エラトステネスの篩で、
    2 ~ Nの各数に対して、その整数のもつ最小の素因数
    (その整数を篩落とした最小の素因数)を記録して返す
    O(nloglog(n))
    """
    res = [i for i in range(n+1)]
    for i in range(2, int(n**0.5)+1):
        if res[i] < i:
            continue
        for j in range(i*i, n+1, i):
            if res[j] == j:
                res[j] = i
    return res

def factorization(n, min_factor):
    """
    エラトステネスの篩で手に入れた、各整数の最小素因数のリスト
    からO(log(n))で素因数分解する
    """
    res = set()
    while n > 1:
        res.add(min_factor[n])
        n //= min_factor[n]
        # 割った後の素因数についてもO(1)で参照できる
    return res

# 素因数が重複しているかを調べる
min_factor = prime_factor_sieve(MAX)
res = set()
is_ok = 1
A = [a for a in A if a != 1]
for a in A:
    tmp = factorization(a, min_factor)
    if res & tmp:
        is_ok = 0
        break
    res = factorization(a, min_factor)
if is_ok:
    print("pairwise coprime")
else:
    g = A[0]
    for i in range(1, N):
        g = gcd(g, A[i])
    if g == 1:
        print("setwise coprime")
    else:
        print("not coprime")
Problem p02579 (python)

Fixed submission:
import heapq
INF = 1e7
H,W=map(int, input().split())
sx, sy = map(int, input().split())
dh, dw = map(int, input().split())
sx -= 1
sy -= 1
S = [input() for _ in range(H)]
D = [[INF]*(W) for _ in range(H)] #始点からの距離(重み)
D[sx][sy] = 0
PQ = [(0, (sx, sy))]
heapq.heapify(PQ)
while PQ: # PQに候補がある限り
    _, (ux, uy) = heapq.heappop(PQ) # 最小コストなノードu
    for dx in range(-2, 3):
        for dy in range(-2, 3):
            xx, yy = ux+dx, uy+dy
            if 0 <= xx < H and 0 <= yy < W and S[xx][yy]==".":
                is_not_neighbor = int(abs(dx) + abs(dy) != 1)
                # neighborでなければコストが1増える
                if D[ux][uy] + is_not_neighbor < D[xx][yy]:
                    D[xx][yy] = D[ux][uy] + is_not_neighbor
                    heapq.heappush(PQ, (D[xx][yy], (xx, yy)))
if D[dh-1][dw-1] >= INF:
    print(-1)
else:
    print(D[dh-1][dw-1])

Buggy submission (verdict: Runtime Error):
from heapq import heapify, heappop, heappush
INF = 1e7

H,W=map(int, input().split())
sx, sy = map(int, input().split())
dh, dw = map(int, input().split())

S = [input() for _ in range(H)]

D = [[INF]*(W) for _ in range(H)] #始点からの距離(重み)
D[sx][sy] = 0
PQ = [(0, sx, sy)]
heapify(PQ)
while PQ: # PQに候補がある限り
    _, ux, uy = heappop(PQ) # 最小コストなノードu
    for dx in range(-2, 3):
        for dy in range(-2, 3):
            xx, yy = ux+dx, uy+dy
            if 0 <= xx < H and 0 <= yy < W and S[xx][yy]==".":
                is_not_neighbor = int(abs(dx) + abs(dy) != 1)
                # neighborでなければコストが1増える
                if D[ux][uy] + is_not_neighbor < D[xx][yy]:
                    D[xx][yy] = D[ux][uy] + is_not_neighbor
                    heappush(PQ, (D[xx][yy], xx, yy))
if D[dh-1][dw-1] >= INF:
    print(-1)
else:
    print(D[dh-1][dw-1])
Problem p02585 (python)

Fixed submission:
INF = float("inf")

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = -INF
for s in range(N):
    ### STEP1
    cum = []
    i = P[s] - 1 #s-> i
    cum.append(C[i])
    while i != s:
        i = P[i] - 1
        cum.append(cum[-1] + C[i])
    

    # STEP2
    if K <= len(cum):
        #1週未満しかできない
        score = max(cum[:K])
    
    elif cum[-1] <= 0:
        #一周以上できるが、ループしたら損する場合
        score = max(cum)
    else:
        # K//Length - 1回だけループし、最後は最適に止まる
        score1 = cum[-1] * (K//len(cum) - 1)
        score1 += max(cum)

        #ループをK//length回だけループする場合
        score2 = cum[-1]*(K//len(cum))
        resi = K % len(cum) #残り進める回数
        if resi != 0:
            #まだ進めるなら
            score2 += max(0, max(cum[:resi]))
        score = max(score1, score2)
    
    ans = max(ans, score)

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
P = [P[i] - 1 for i in range(N)]

loop_list = [] # ([indexes])
loop_score_list = []
loop_index_list = [0]*N
is_included_loop = [0] * N
num_loop = 0

for start in range(N):
    if is_included_loop[start]:
        continue
    now = start
    count = 1
    visited = [-1]*N # count
    visited[now] = 0
    while True:
        now = P[now]
        if visited[now] != -1:
            terminate_count = count
            start_count = visited[now]
            loop_start_idx = now
            break
        visited[now] = count
        count += 1
    
    num_loop += 1
    now = loop_start_idx
    loop_indexes = [now]
    visited = [-1]*N
    visited[now] = 0
    count = 1
    loop_score = 0
    while True:
        now = P[now]
        if visited[now] != -1:
            break
        loop_indexes.append(now)
        visited[now] = count
        loop_index_list[now] = num_loop
        loop_score += C[now]
        is_included_loop[now] = 1
    loop_list.append(loop_indexes)
    loop_score_list.append(loop_score)


scores = []
for start in range(N):
    tmp_score = 0
    rest = K
    now = start
    while not is_included_loop[now] and rest > 0:
        now = P[now]
        rest -= 1
        tmp_score += C[now]
        scores.append(tmp_score)
    
    if rest <= 0:
        scores.append(tmp_score)
        continue
    # loop
    number_of_loop = loop_index_list[now]
    one_cicle_score = loop_score_list[number_of_loop]
    if one_cicle_score < 0:
        continue
    if rest <= len(loop_list[number_of_loop]):
        while rest >= 0:
            now = P[now]
            rest -= 1
            tmp_score += C[now]
            scores.append(tmp_score)
        continue
    else:
        n_l = rest // len(loop_list[number_of_loop])
        tmp_score += n_l * one_cicle_score
        scores.append(tmp_score)
print(max(scores))
Problem p02586 (python)

Fixed submission:
R, C,K = map(int, input().split())
dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
# dp[r][c][j] :=r index c columns already j cnt
dp[0][0][0] = 0
D = [[0 for i in range(C+1)] for j in range(R+1)]
import random
for i in range(K):
    r, c, v = map(int,input().split())
    D[r][c] = v
 
for i in range(R+1):
    for j in range(C+1):
        if D[i][j] > 0:
            v = D[i][j]
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
            dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
            dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
 
        else:
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1]
 
ans = 0
for i in range(4):
    ans = max(ans, dp[i][-1][-1])
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
P = [P[i] - 1 for i in range(N)]

loop_list = [] # ([indexes])
loop_score_list = []
loop_index_list = [0]*N
is_included_loop = [0] * N
num_loop = 0

for start in range(N):
    if is_included_loop[start]:
        continue
    now = start
    count = 1
    visited = [-1]*N # count
    visited[now] = 0
    while True:
        now = P[now]
        if visited[now] != -1:
            terminate_count = count
            start_count = visited[now]
            loop_start_idx = now
            break
        visited[now] = count
        count += 1
    
    num_loop += 1
    now = loop_start_idx
    loop_indexes = [now]
    visited = [-1]*N
    visited[now] = 0
    count = 1
    loop_score = 0
    while True:
        now = P[now]
        if visited[now] != -1:
            break
        loop_indexes.append(now)
        visited[now] = count
        loop_index_list[now] = num_loop
        loop_score += C[now]
        is_included_loop[now] = 1
    loop_list.append(loop_indexes)
    loop_score_list.append(loop_score)


scores = []
for start in range(N):
    tmp_score = 0
    rest = K
    now = start
    while not is_included_loop[now] and rest > 0:
        now = P[now]
        rest -= 1
        tmp_score += C[now]
        scores.append(tmp_score)
    
    if rest <= 0:
        scores.append(tmp_score)
        continue
    # loop
    number_of_loop = loop_index_list[now] - 1
    one_cicle_score = loop_score_list[number_of_loop]
    if one_cicle_score < 0:
        continue
    if rest <= len(loop_list[number_of_loop]):
        while rest >= 0:
            now = P[now]
            rest -= 1
            tmp_score += C[now]
            scores.append(tmp_score)
        continue
    else:
        n_l = rest // len(loop_list[number_of_loop])
        tmp_score += n_l * one_cicle_score
        scores.append(tmp_score)
print(max(scores))
Problem p02665 (python)

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

ans = 0
if N == 0:
    if A[0] >= 2:
        ans = -1
    else:
        ans = 1

if N >= 1 and A[0] >= 1:
    ans = -1

if N >= 1:
    node_num = {N: A[N]}
    max_parent_num = {0: 1}
    for i in range(1, N+1):
        max_parent_num[i] = max_parent_num[i-1] * 2 - A[i]

    for i in range(N, 0, -1):
        if node_num[i] > A[i] + max_parent_num[i]:
            ans = -1
            break
        #i-1 no parent wo tukuru
        if node_num[i] <= max_parent_num[i-1]:
            i_1_parent_num = node_num[i]
        else:
            i_1_parent_num = max_parent_num[i-1]
        node_num[i-1] = i_1_parent_num + A[i-1]
        if i == 1:
            if node_num[i-1] != 1:
                ans = -1
                break

if ans == -1 or ans == 1:
    print(ans)
else:
    ans = sum(node_num.values())
    print(ans)

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

ans = 0
if A[0] >= 1:
    ans = -1
if N == 0:
    if A[0] == 0:
        ans = 1
    else:
        ans = -1
else:
    node_num = {N: A[N]}
    max_parent_num = {0: 1}
    for i in range(1, N+1):
        max_parent_num[i] = max_parent_num[i-1] * 2 - A[i]

    for i in range(N, 0, -1):
        if node_num[i] > min(2**i, A[i] + max_parent_num[i]):
            ans = -1
            break
        #i-1 no parent wo tukuru
        if node_num[i] <= max_parent_num[i-1]:
            i_1_parent_num = node_num[i]
        else:
            i_1_parent_num = max_parent_num[i-1]
        node_num[i-1] = i_1_parent_num + A[i-1]
    if node_num[0] > min(1, A[0] + max_parent_num[0]):
        ans = -1

if ans == -1 or ans == 1:
    print(ans)
else:
    ans = sum(node_num.values())
    print(ans)
Problem p02801 (python)

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 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])
Problem p02911 (python)

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 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")
Problem p02921 (python)

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

c=0
for i in range(3):
    if s[i]==t[i]:
        c+= 1
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())

ans = n*(n-1)//2
print(ans)
Problem p02924 (python)

Fixed submission:
n = int(input())

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

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(range(n))
print(sum(l))
Problem p02995 (python)

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 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)
Problem p03044 (python)

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 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)
Problem p03240 (python)

Fixed submission:
from itertools import product
xyh = []
xyh0 = []
N=int(input())
for _ in range(N):
    tmp1, tmp2, tmp3 = map(int, input().split())
    if tmp3 > 0:
        xyh.append((tmp1, tmp2, tmp3))
    else:
        xyh0.append((tmp1, tmp2, tmp3))
ans = None
for cx, cy in product(range(101), repeat=2):
    H = None
    H_lower = 1
    H_upper = 10**100
    is_ok = 1
    for x, y, h in xyh:
        if H is None:
            H = abs(x-cx)+abs(y-cy)+h
        else:
            if H != abs(x-cx)+abs(y-cy)+h:
                is_ok = 0
                break
    if not is_ok or H is None:
        continue
    for x, y, h in xyh0:
        H_upper = min(H_upper, abs(x-cx)+abs(y-cy))
    if H > H_upper or H < H_lower:
        continue
    ans = (cx, cy, H)
    break

print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import product
input = sys.stdin.readline
xyh = []
xyh0 = []
N=int(input())
for _ in range(N):
    tmp1, tmp2, tmp3 = map(int, input().split())
    if tmp3 > 0:
        xyh.append((tmp1, tmp2, tmp3))
    else:
        xyh0.append((tmp1, tmp2, tmp3))
ans = None
for cx, cy in product(range(101), repeat=2):
    H = None
    H_lower = 1
    is_ok = 1
    for x, y, h in xyh:
        if H is None:
            H = abs(x-cx)+abs(y-cy)+h
        else:
            if H != abs(x-cx)+abs(y-cy)+h:
                is_ok = 0
                break
    if not is_ok or H is None:
        continue
    for x, y, h in xyh0:
        H_lower = max(H_lower, abs(x-cx)+abs(y-cy))
    if H < H_lower:
        continue
    ans = (cx, cy, H)
    break
        
print(*ans)

Buggy submission (verdict: Runtime Error):
"""
ABC112C Diff:
"""
import sys
from itertools import product
input = sys.stdin.readline
xyh = []
xyh0 = []
N=int(input())
for _ in range(N):
    tmp1, tmp2, tmp3 = map(int, input().split())
    if tmp3 > 0:
        xyh.append((tmp1, tmp2, tmp3))
    else:
        xyh0.append((tmp1, tmp2, tmp3))
ans = None
for cx, cy in product(range(101), repeat=2):
    H = None
    H_lower = 1
    is_ok = 1
    for x, y, h in xyh:
        if H is None:
            H = abs(x-cx)+abs(y-cy)+h
        else:
            if H != abs(x-cx)+abs(y-cy)+h:
                is_ok = 0
                break
    if not is_ok:
        continue
    for x, y, h in xyh0:
        H_lower = max(H_lower, abs(x-cx)+abs(y-cy))
    if H < H_lower:
        continue
    ans = (cx, cy, H)
    break
        
print(*ans)
Problem p03262 (python)

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 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)
Problem p03502 (python)

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 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")

Buggy 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")
Problem p03544 (python)

Fixed submission:
N = int(input())
MAX = 86
L = [0]*(MAX+1)
L[0] = 2
L[1] = 1
for i in range(2, MAX+1):
    L[i] = L[i-1] + L[i-2]
print(L[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [0]*N
if N==1:
    print(2)
if N==2:
    print(1)
else:

    L[0]=2
    L[1]=1
    for i in range(2,N-1):
        L[i] = L[i-1]+L[i-2]
    print(L[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [0]*N
L[0]=2
L[1]=1
for i in range(2,N-1):
    L[i] = L[i-1]+L[i-2]
print(L[N-1])