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

Fixed submission:
R = int(input())
G = int(input())
ans = 2*G - R
print(ans)

Buggy submission (verdict: Runtime Error):
R, G = (int(x) for x in input().split())
ans = 2*G - R
print(ans)
Problem p03597 (python)

Fixed submission:
N = int(input())
A = int(input())
ans = N**2 - A
print(ans)

Buggy submission (verdict: Runtime Error):
N, A = (int(x) for x in input().split())
ans = N**2 - A
print(ans)
Problem p03599 (python)

Fixed submission:
A,B,C,D,E,F = (int(x) for x in input().split())

CCT = {}
for a in range(F//(100*A)+1):
    for b in range(F//(100*B)+1):
        water = (a*A+b*B)*100
        if water > F:
            continue
        max_suger = water*E//100
        for c in range(max_suger//C+1):
            for d in range(max_suger//D+1):
                suger = c*C+d*D
                total = water + suger
                if total > F or total == 0:
                    continue
                if max_suger < suger:
                    continue
                CCT[water,suger] = suger/total

ans = (A*100, 0)
max_cct = 0
for (water,suger),cct in CCT.items():
    if cct > max_cct:
        max_cct = cct
        ans = (water+suger, suger)
print(*ans)

Buggy submission (verdict: Runtime Error):
A,B,C,D,E,F = (int(x) for x in input().split())

CCT = {}
for a in range(F//(100*A)+1):
    for b in range(F//(100*B)+1):
        water = (a*A+b*B)*100
        max_suger = water*E//100
        for c in range(max_suger//C+1):
            for d in range(max_suger//D+1):
                suger = c*C+d*D
                if water + suger > F:
                    continue
                if max_suger < suger:
                    continue
                if water+suger == 0:
                    continue
                CCT[water,suger] = 100*suger/(water+suger)

max_cct = 0
for (water,suger),cct in CCT.items():
    if cct > max_cct:
        max_cct = cct
        ans = [water+suger, suger]
print(*ans)
Problem p03600 (python)

Fixed submission:
def main():
    inf=float("inf")
    n=int(input())
    alst=[list(map(int,input().split())) for _ in range(n)]
 
    for i in range(n):
        alst[i][i]=inf
 
    sm=0
    token=0
 
    for i in range(n):
        for j in range(i+1,n):
            for k in range(n):
                if alst[i][k]+alst[k][j]>alst[i][j]:
                    continue
                elif alst[i][k]+alst[k][j]==alst[i][j]:
                    break
                else:
                    token=1
                    break
            else :
                sm+=alst[i][j]
    
    if token : sm=-1
 
    print(sm)
 
main()

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [[(int(x),True) for x in input().split()] for _ in range(N)]

ans = 0
for k in range(N):
    for i in range(N):
        if i == k: continue
        for j in range(i+1,N):
            if j == k: continue
            Aikj = A[i][k][0] + A[k][j][0]
            if A[i][j][0] > Aikj:
                ans = -1
            if A[i][j][0] == Aikj:
                A[i][j][1] = False

if ans != -1:
    for i in range(N):
        for j in range(i+1,N):
            if A[i][j][1]:
                ans += A[i][j][0]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
A = [[(int(x),True) for x in input().split()] for _ in range(N)]

ans = 0
for k in range(N):
    for i in range(N):
        if i == k: continue
        for j in range(i+1,N):
            if j == k: continue
            Aikj = A[i][k][0] + A[k][j][0]
            if A[i][j][0] > Aikj:
                ans = -1
            if A[i][j][0] == Aikj:
                A[i][j][1] = False

if ans != -1:
    for i in range(N):
        for j in range(i+1,N):
            if A[i][j][1]:
                ans += A[i][j][0]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
A = [[(int(x),True) for x in input().split()] for _ in range(N)]

for k in range(N):
    for i in range(N):
        if i == k: continue
        for j in range(i+1,N):
            if j == k: continue
            Aikj = A[i][k][0] + A[k][j][0]
            if A[i][j][0] > Aikj:
                print(-1)
                sys.exit()
            if A[i][j][0] == Aikj:
                A[i][j][1] = False

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if A[i][j][1]:
            ans += A[i][j][0]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
A = [[(int(x),True) for x in input().split()] for _ in range(N)]

for k in range(N):
    for i in range(N):
        if i == k: continue
        for j in range(i+1,N):
            if j == k: continue
            Aikj = A[i][k][0] + A[k][j][0]
            if A[i][j][0] > Aikj:
                print(-1)
                sys.exit()
            if A[i][j][0] == Aikj:
                A[i][j][1] = False

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if A[i][j][1]:
            ans += A[i][j][0]
print(ans)
Problem p03645 (python)

Fixed submission:
N, M = map(int, input().split())
graph = [[] for _ in range(N)] 
for _ in range(M):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

def bfs(goal, graph, seen, next_v):
    for x in graph[next_v[0][0]]:
        if x == goal:
            return True
        if x in seen:
            continue
        next_v.append((x,next_v[0][1]+1))
        seen.add(x)
    return False


next_v = [(0,0)]
seen = {0}
#bfs
while True:
    if len(next_v) == 0 or next_v[0][1] == 2:
        ans = "IMPOSSIBLE"
        break
    if bfs(N-1, graph, seen, next_v):
        ans = "POSSIBLE"
        break
    next_v.pop(0)
print(ans)

Buggy submission (verdict: Runtime Error):
import typing
from typing import Deque, Set, Dict

class Island:
    def __init__(self, id: int) -> None:
        self.id: int = id
        self.connection: List['Island'] = []
        self.rank: int = 0
    
    def addConnection(self, other: 'Island') -> None:
        self.connection.append(other)
        other.connection.append(self)

    def setParent(self, other: 'Island') -> None:
        self.rank = other.rank +1

class Islands(Dict[int, Island]):
    def __init__(self, num: int):
        for id in range(1, num+1):
            self[id] = Island(id)

def bfs(root: Island, max_depth: int) -> None:
    root.setAsRoot()
    reserved: Deque[Island] = Deque([root])
    seen: Set[int] = {root.id}
    while len(reserved) != 0:
        current: Island = reserved.popleft()
        if current.rank > max_depth:
            break
        for connected in current.connection:
            if connected.id in seen:
                continue
            connected.setParent(current)
            seen.add(connected.id)
            reserved.append(connected)

def main() -> None:
    with open(0) as f:
        N, M = map(int, f.readline().split())
        ab = [map(int, line.split()) for line in f.readlines()]
    #諸島生成
    islands: Islands = Islands(N)
    #諸島間定期便生成
    for a, b in ab:
        islands[a].addConnection(islands[b])
    #bfs
    bfs(islands[1], 2)
    #出力
    print('POSSIBLE' if islands[N].rank in (1, 2) else 'IMPOSSIBLE')


if __name__ == '__main__':
    main()
Problem p03697 (python)

Fixed submission:
A, B = map(int, input().split())
print(A+B if A+B < 10 else 'error')

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A + b >= 10:
    print("error")
else:
    print(A+B)
Problem p03699 (python)

Fixed submission:
N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N

dp = [False] * (M+1)
dp[0] = True

for x in s:
    for i in range(M+1):
        if M-i < x: continue
        if dp[M-i-x]: dp[M-i] = True

for i in range(M+1):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
        break
else:
    print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N + 1

dp = [False * M]
dp[0] = True

for x in s:
    for i in range(M):
        if i < x: continue
        if dp[i-x]: dp[i] = True

for i in range(M):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
maxs = 0    
s = []
for i in range(N):
    cin = int(input())
    s.append(cin)
    maxs = max(maxs, cin)
M = maxs * N + 1

dp = [False * M]
dp[0] = True

for x in s:
    for i in range(M+1):
        if i < x: continue
        if dp[i-x]: dp[i] = True

for i in range(M+1):
    if (M-i)%10 != 0 and dp[M-i]:
        print(M-i)
else:
    print(0)
Problem p03700 (python)

Fixed submission:
with open(0) as f:
    N, A, B, *H = map(int, f.read().split())

diff = A - B #追加ダメージ
T = (max(H)+B-1)//B #答えはT以下

def clearable(t): #t回以内で敵を全滅できるか判定
    Higher = [h-B*t for h in H if h-B*t > 0]
    return True if sum([(h+diff-1)//diff for h in Higher]) <= t else False

def binary_search(a, b, judge): #b must be a or higher
    if a == b:
        return a, b
    
    c = a + (b - a)// 2
    return (a, c) if judge(c) else (c+1, b)

a, b = 0, T
while a != b:
    a, b = binary_search(a, b, clearable)
print(a)

Buggy submission (verdict: Runtime Error):
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    long N, A, B;
    cin >> N >> A >> B;
    vector<long> h;
    for (int i=0; i<N; i++){
        long input;
        cin >> input;
        h.push_back(input);
    }

    
    long ans = 0;
    vector<long> temp;
    while (h.size() != 0){
        bool first = true;
        make_heap(h.begin(),h.end());
        for (auto x : h){
            if (first) {x -= A; first = false;}
            else{ x -= B;}
            if (x > 0) temp.push_back(x);
        }
        h.clear();
        for (auto x : temp) h.push_back(x);
        temp.clear();
        ans++;
    }
    cout << ans << endl;
    return 0;
}
Problem p03720 (python)

Fixed submission:
N, M, *cnt = open(0).read().split()
from collections import Counter
cnt = Counter(cnt)
for i in range(1,int(N)+1):
    print(cnt[str(i)])

Buggy submission (verdict: Runtime Error):
N, M = open(0).readline().split()
from collections import Counter
cnt = Counter(open(0).read().split())
for i in range(1,int(N)+1):
    print(cnt[str(i)])

Buggy submission (verdict: Runtime Error):
N, M = open(0).readline().split()
from collections import Counter
cnt = Counter(open(0).read().split())
print('\n'.join(list(map(str,cnt.values()))))

Buggy submission (verdict: Runtime Error):
N, M = open(0).readline().split()
from collections import Counter
cnt = Counter(open(0).read().split())
print('\n'.join(map(str,cnt.values())))

Buggy submission (verdict: Runtime Error):
N, M = open(0).readline().split()
from collections import Counter
cnt = Counter([x for x in open(0).read().split()])
print('\n'.join(map(str,cnt.values())))

Buggy submission (verdict: Runtime Error):
N, M = open(0).readline().split()
from collections import Counter
cnt = Counter([int(x) for x in open(0).read().split()])
print('\n'.join(map(str,cnt.values())))
Problem p03739 (python)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

def odd_positive(List):
    sum_a = 0
    cost = 0
    i = 0
    for a in List:
        i += 1
        sum_a += a
        if i & 1 and sum_a <= 0:
            cost += - sum_a + 1
            sum_a = 1
        elif (not i & 1) and sum_a >= 0:
            cost += sum_a + 1
            sum_a = -1
    return cost


def odd_negative(List):
    sum_a = 0
    cost = 0
    i = 0
    for a in List:
        i += 1
        sum_a += a
        if i & 1 and sum_a >= 0:
            cost += sum_a + 1
            sum_a = -1
        elif (not i & 1) and sum_a <= 0:
            cost += - sum_a + 1
            sum_a = 1
    return cost
    
ans = min(odd_positive(a), odd_negative(a)) 
print(ans)

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

Cost = lambda a, Sum:0 if (Sum > 0) ^ (Sum + a > 0) else abs(Sum + a) + 1
Sum = lambda a, preSum:preSum+a if (preSum > 0) ^ (preSum + a > 0) else -preSum//abs(preSum)

pSum = Sum(A[0],0)
nSum = Sum(A[0],0)
pCost = 0
nCost = 0
for a in A[1:]:
    pCost += Cost(a, pSum)
    pSum = Sum(a, pSum)
    nCost += Cost(a, nSum)
    nSum = Sum(a, nSum)
print(min(pCost, nCost))

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

Cost = lambda a, Sum:0 if (Sum > 0) ^ (Sum + a > 0) else abs(Sum + a) + 1
Sum = lambda a, preSum:preSum+a if (Sum > 0) ^ (preSum + a > 0) else -preSum//abs(preSum)

pSum = Sum(A[0],0)
nSum = Sum(A[0],0)
pCost = 0
nCost = 0
for a in A[1:]:
    pCost += Cost(a, pSum)
    pSum = Sum(a, pSum)
    nCost += Cost(a, nSum)
    nSum = Sum(a, nSum)
print(min(pCost, nCost))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]

def odd_positive(List, n):
    sum_a = 0
    cost = 0
    for a in List:
        nextsum = sum_a + a
        if i & 1 and nextsum <= 0:
            cost = - nextsum + 1
            sum_a = 1
        elif (not i & 1) and nextsum >= 0:
            cost = nextsum + 1
            sum_a = -1
    return cost


def odd_negative(List, n):
    sum_a = 0
    cost = 0
    for a in List:
        nextsum = sum_a + a
        if i & 1 and nextsum >= 0:
            cost = nextsum + 1
            sum_a = -1
        elif (not i & 1) and nextsum <= 0:
            cost = - nextsum + 1
            sum_a = 1
    return cost
    
ans = min(odd_positive(a,n), odd_negative(a,n)) 
print(ans)
Problem p03759 (python)

Fixed submission:
a, b, c = map(int, input().split())
if b - a == c - b:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a, b = input().split()
print('H' if (a == 'H') ^ (b == 'D') else 'D')
Problem p03762 (python)

Fixed submission:
n, m = map(int, input().split())
x = [x for x in map(int, input().split())]
y = [y for y in map(int, input().split())]
sum_x = 0
sum_y = 0
ans = 0
for i in range(n):
    sum_x += (2*i - n + 1) * x[i] 
for j in range(m):
    sum_y += (2*j - m + 1) * y[j]
ans = sum_x * sum_y
print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = [x for x in map(int, input().split())]
y = [y for y in map(int, input().split())]
sum_x = 0
sum_y = 0
ans = 0
for i in range(n):
    sum_x += (2*i - n + 1) * x[i+1] 
for j in range(m):
    sum_y += (2*j - m + 1) * y[j+1]
ans = sum_x * sum_y
print(ans%1000000007)
Problem p03796 (python)

Fixed submission:
N = int(input())
power = 1
for i in range(N):
    power *= i + 1
    power %= 1000000007
print(power)

Buggy submission (verdict: Runtime Error):
N = int(input())
mod = int(10e9+7)
f = lambda n:1 if n==1 else n * f(n-1) % mod
print(f(N))
Problem p03798 (python)

Fixed submission:
N = int(input())
s = input()

init = ["SS", "SW", "WS", "WW"]
next_animal = { ("S","o","S"):"S",
                ("S","o","W"):"W",
                ("S","x","S"):"W",
                ("S","x","W"):"S",
                ("W","o","S"):"W",
                ("W","o","W"):"S",
                ("W","x","S"):"S",
                ("W","x","W"):"W"}
for X in init:
    SW = X
    for i in range(1,N):
        SW += next_animal[SW[i],s[i],SW[i-1]]
    ls = len(SW)
    if SW[0] == SW[ls-1] and next_animal[SW[0],s[0],SW[ls-2]] == SW[1]:
        print(SW[:ls-1])
        break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = input()

init = ["SS", "SW","WS","WW"]
next_animal = { ("S","o","S"):"S",
                ("S","o","W"):"W",
                ("S","x","S"):"W",
                ("S","x","W"):"S",
                ("W","o","S"):"W",
                ("W","o","W"):"S",
                ("W","x","S"):"S",
                ("W","x","W"):"W "}
for X in init:
    SW = X
    for i in range(1,N):
        SW += next_animal[SW[i],s[i],SW[i-1]]
    if SW[0] == SW[len(SW)-1]:
        print(SW[:len(SW)-1])
        break
else:
    print(-1)
Problem p03846 (python)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

cnt = {}
if N & 1:
    bit = 1
else:
    bit = 0

for a in A:
    if a & bit:
        ans = 0
        break
    if a in cnt:
        cnt[a] += 1
    else:
        cnt[a] = 1

for key in cnt.keys():
    if key == 0 and cnt[key] != 1:
        ans = 0
        break
    if key != 0 and cnt[key] != 2:
        ans = 0
        break
else:
    ans = 2**(N//2) %1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
from collections import defaultdict as dd
Dict = dd(lambda:0)
for a in A:
    Dict[a] += 1
    
if N & 1: Dict[0] += 1
f = (lambda:(lambda x:0 if x&1 else 2) if N&1 else (lambda x:2 if x&1 else 0))()
Possible = {i:f(i) for i in range(N)}
for key,value in Dict.items:
    if value != Possible[key]:
        print(0)
        exit()
else:
    print(2**(N//2)%1000000007)
Problem p03852 (python)

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

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

Fixed submission:
H, W = map(int, input().split())
C = []
for i in range(H):
    C.append(input())
for i in range(H):
    print(C[i])
    print(C[i])

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
C = []
for i in range(H):
    C[i] = input()
for i in range(H):
    print(C[i])
    print(C[i])
Problem p03854 (python)

Fixed submission:
s = input()
while 1:
    if len(s) == 0:
        print("YES")
        break
    if s[len(s)-5:] == "dream":
        s = s[:len(s)-5]
        continue
    elif s[len(s)-7:] == "dreamer":
        s = s[:len(s)-7]
        continue
    elif s[len(s)-5:] == "erase":
        s = s[:len(s)-5]
        continue
    elif s[len(s)-6:] == "eraser":
        s = s[:len(s)-6]
        continue
    else:
        print("NO")
        break

Buggy submission (verdict: Runtime Error):
s = input()
while 1:
    if len(S) == 0:
        print("YES")
        break
    if s[len(s)-5:] == "dream":
        s = s[:len(s)-5]
        continue
    elif s[len(s)-7:] == "dreamer":
        s = s[:len(s)-7]
        continue
    elif s[len(s)-5:] == "erase":
        s = s[:len(s)-5]
        continue
    elif s[len(s)-6:] == "eraser":
        s = s[:len(s)-6]
        continue
    else:
        print("NO")
        break
Problem p03862 (python)

Fixed submission:
import math
N, x = map(int, input().split())
L = [int(x) for x in input().split()]
ans = 0
for i in range(1,N):
    if L[i-1] + L[i] > x:
        if L[i-1] > x:
            ans += L[i-1] - x
            ans += L[i]
            L[i] = 0
        else:
            ans += L[i] + L[i-1] - x
            L[i] = x - L[i-1]
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, x = map(int, input().split())
L = [int(x) for x in input().split()]
ans = 0
for i in L[1:]:
    if L[i-1] + L[i] > x:
        if L[i-1] > x:
            ans += L[i-1] - x
            ans += L[i]
            L[i] = 0
        else:
            ans += L[i] + L[i-1] - x
            L[i] = x - L[i-1]
print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())
n = 0
def pick(list, num):
    4yu
for i in range(N):
    x = int(input().split())
    if x != A:
        L.append(int(input().split())-A)
    else:
        n += 1
L.sort()
Problem p03943 (python)

Fixed submission:
L = [int(x) for x in input().split()]
L.sort()
if L[0] + L[1] == L[2]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
L = sorted(list(map(int, input().split())))
print('Yes' if sum(L[:2] == L[2]) else 'No')
Problem p03945 (python)

Fixed submission:
S = input()
X = S[0]
ans = 0
while 1:    
    for i in range(len(S)):
        if S[i] != X:
            ans += 1
            X =S[i]
            S = S[i:]
            break
    else:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
X = S[0]
ans = 0
while 1:    
    for i in range(S):
        if S[i] != X:
            ans += 1
            X =S[i]
            S = S[i:]
            break
    else:
        break
print(ans)
Problem p03965 (python)

Fixed submission:
s = input()
N = len(s)
D = {"g":0, "p":0}
for i in range(N):
    D[s[i]] += 1
my_p = N//2
score = my_p - D["p"]
print(score)

Buggy submission (verdict: Runtime Error):
s = input()
N = len(s)
D = {}
for i in range(N):
    if s[i] in D:
        D[s[i]] += 1
    else:
        D[s[i]] = 1
my_p = N//2
score = my_p - D["p"]
print(score)

Buggy submission (verdict: Runtime Error):
s = input()
N = len(s)
D = {}
for i in range(N):
    if s[i] in D:
        D[s[i]] += 1
    else:
        D[s[i]] = 1
my_g = (N+1)//2
my_p = N//2
score = my_p - D["p"]
print(score)
Problem p04000 (python)

Fixed submission:
H, W, N = map(int, input().split())
from collections import defaultdict as dd
Grid =  dd(lambda:0) #3*3正方形を左上のマスで区別。値は正方形内の黒塗りの個数
Draw = lambda x,y:[(x-i,y-j) for i in range(3) for j in range(3) if 0<=x-i<H-2 and 0<=y-j<W-2] #塗りつぶしたマスを含む正方形の座標のリストを返す関数
for _ in range(N):
    a, b = map(int, input().split())
    for x,y in Draw(a-1,b-1): #Gridの更新
        Grid[x,y] += 1
Ans = [(H-2)*(W-2)-len(Grid) if i == 0 else sum(v==i for v in Grid.values()) for i in range(10)]         
for ans in Ans:
    print(ans)

Buggy submission (verdict: Runtime Error):
H, W, N = map(int, input().split())
Grid = [[0]*(W-2) for _ in range(H-2)] #3*3正方形を左上のマスで区別。値は正方形内の黒塗りの個数
Ans = [(H-2)*(W-2) if i == 0 else 0 for i in range(10)] 
f = lambda x:int(x)-1
Draw = lambda x,y:[(x-i,y-j) for i in range(3) for j in range(3) if 0<=x-i<H-2 and 0<=y-j<W-2] #塗りつぶしたマスを含む正方形の座標のリストを返す関数
for _ in range(N):
    a, b = map(f, input().split())
    for x,y in Draw(a,b): #Ans及びGridの更新
        Ans[Grid[x][y]] += -1
        Ans[Grid[x][y]+1] += 1
        Grid[x][y] += 1
for ans in Ans:print(ans)
Problem p04014 (python)

Fixed submission:
n, s = int(input()), int(input())

f = lambda b,n:n if n < b else n%b + f(b,n//b)
import math
ans = math.inf
if n == s: ans = n+1
for b in range(2,math.ceil(math.sqrt(n))+1): #O(√n)の全探索
    if f(b,n) == s:
        ans = b; break
else:
    for p in range(1,math.ceil(math.sqrt(n))): #n=pb+q (b>√n, p+q=s)に基づいたO(√n)の全探索
        b = (n-s)/p+1
        if b > 1 and b == int(b) and f(b,n) == s:
           ans = min(ans,int(b))
if ans == math.inf: ans = -1
print(ans)

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

f = lambda b,n:n if n < b else n%b + f(b,n//b)
import math
ans = n+2
for b in range(2,math.ceil(math.sqrt(n))): #O(√n)の全探索
    if f(b,n) == s:
        ans = b; break
else:
    for p in range(math.ceil(math.sqrt(n))): #n=pb+q (b>√n, p+q=s)に基づいたO(√n)の全探索
        q = s-p
        if p > 0: b = (n-q)/p
        else: b = n+1
        if b == int(b) and f(b,n) == s:
           ans = min(ans,int(b))
if ans == n+2: ans = -1
print(ans)
Problem p04043 (python)

Fixed submission:
L = [int(x) for x in input().split()]
L.sort()

if L == [5,5,7]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
A = input()
B = input()
C = input()

L = [A, B, C]

for x in L:
    if len(x) == 7:
        L.remove(x)
        for y in L:
            if len(y) != 5:
                break
        else:
            print("YES")
            break
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
A = input()
B = input()
C = input()

L = [A, B, C]

for x in L:
    if len(x) == 7:
        L.remove(x)
        for y in L:
            if len(y) != 5:
                break
        else:
            print("YES")
            break
else:
    print("NO")
Problem p03068 (python)

Fixed submission:
# coding: utf-8
# Your# coding: utf-8
# Your code here!
N = int(input())
S = str(input())
K = int(input())
#rint(N,S,K)
 
WRITE = list(S)
CHARA = S[K-1]
#print(CHARA)
 
for i in range(N):
    if S[i] != CHARA:
        S = S[:i] + '*' + S[i+1:]
 
print(S)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N = int(input())
S = str(input())
K = int(input())
#rint(N,S,K)

WRITE = list(S)
CHARA = S[K]
#print(CHARA)

for i in range(N):
    if S[i] != CHARA:
        S = S[:i] + '*' + S[i+1:]

print(S)