Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
W = []
judge = True
a = ""
N = int(input())
for i in range(N):
    s = input()
    W.append(s)
    if i == 0:
        a = s[len(s)-1]
    else:
        if a != s[0] or s in W:
            judge = False
            break
        else:
            a = s[len(s)-1]
if judge:
    print("Yes"):
else:
    print("No")

Fixed submission:
W = []
judge = True
a = ""
N = int(input())
for i in range(N):
    s = input()
    if i == 0:
        a = s[len(s)-1]
    else:
        if a != s[0] or s in W:
            judge = False
            break
        else:
            a = s[len(s)-1]
    W.append(s)
if judge:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
x = [abs(X - int(i)) for i in input().split()]

def f(a, b):
    if b == 0:
        return a
    return f(b, a % b)

tmp = 1
for i in range(len(x)-1):
    x[i+1] = f(x[i], x[i+1])

print(x[len(x)])


Fixed submission:
N, X = map(int, input().split())
x = [abs(X - int(i)) for i in input().split()]

def f(a, b):
    if b == 0:
        return a
    return f(b, a % b)

tmp = 1
for i in range(len(x)-1):
    x[i+1] = f(x[i], x[i+1])

print(x[len(x)-1])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input())
x = list(map(int, input()))
ret = 10 ** 9
for i in range(N-k+1):
    init = abs(x[i])
    dist = abs(x[i]-x[i+k-1])
    l = init + dist
    init = abs(x[i+k-1])
    r = init + dist
    ret = min(l, r)
print(ret)

Fixed submission:
N, K = map(int, input().split())
x = list(map(int, input().split()))
ret = 10 ** 9
for i in range(N-K+1):
    init = abs(x[i])
    dist = abs(x[i]-x[i+K-1])
    l = init + dist
    init = abs(x[i+K-1])
    r = init + dist
    ret = min(ret, l, r)
print(ret)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
ret = "1"
for i in K:
    if len(S) <= K:
        break
    if S[i] != "1":
        ret = S[i]
        break
print(ret)


Fixed submission:
S = input()
K = int(input())
ret = "1"
for i in range(K):
    if len(S) < i-1:
        break
    if S[i] != "1":
        ret = S[i]
        break
print(ret)

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
ret = "1"
for i in K:
    if len(S) <= K:
        break
    if i != "1":
        ret = i
        break
print(ret)


Fixed submission:
S = input()
K = int(input())
ret = "1"
for i in range(K):
    if len(S) < i-1:
        break
    if S[i] != "1":
        ret = S[i]
        break
print(ret)

Buggy python submission (verdict: Runtime Error):
import re
S = input()
K = int(input())

next_t = S
now_t = ""

while next_t.ljust(K)[:K] != now_t.ljust(K)[:K]:
    now_t = next_t
    next_t = re.sub(r"[2]","22", next_t)
    next_t = re.sub(r"[3]","333", next_t)
    next_t = re.sub(r"[4]","4444", next_t)
    next_t = re.sub(r"[5]","55555", next_t)
    next_t = re.sub(r"[6]","666666", next_t)
    next_t = re.sub(r"[7]","7777777", next_t)
    next_t = re.sub(r"[8]","88888888", next_t)
    next_t = re.sub(r"[9]","999999999", next_t)

print(next_t[K])
    

Fixed submission:
S = input()
K = int(input())
ret = "1"
for i in range(K):
    if len(S) < i-1:
        break
    if S[i] != "1":
        ret = S[i]
        break
print(ret)
Buggy python submission (verdict: Runtime Error):
def add(pc, p, G, tmp):
    for i in range(len(pc)-1, -1, -1):
        for k in range(pc[i][0]):
            p += (i+1) * 100
            tmp += 1
            if p >= G:
                return tmp


D, G = map(int,input().split())
pc = [list(map(int,input().split())) for i in range(D)]
cnt = 10 ** 9
tmp = 0

for i in range(D):
    p = (i+1) * 100 * pc[i][0]
    p += pc[i][1]
    tmp = pc[i][0]
    if p < G:
        tmp += add(pc, p, G, tmp)
    cnt = min(cnt, tmp)
print(cnt)


Fixed submission:
D, G = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(D)]

def dfs(question_num, rquired_point):
    if question_num < 0:
        return 10 ** 9

    point = (question_num+1) * 100
    ans_num = min(rquired_point // point, pc[question_num][0])
    score = ans_num * point

    if ans_num == pc[question_num][0]:
        score += pc[question_num][1]

    if rquired_point > score:
        ans_num += dfs(question_num-1, rquired_point-score)
    
    return min(ans_num, dfs(question_num-1, rquired_point))

print(dfs(D-1, G))

Buggy python submission (verdict: Runtime Error):
def add(pc, p, G, tmp):
    b = False
    for i in range(len(pc)-1, -1, -1):
        for k in range(pc[i][0]):
            p += (i+1) * 100
            tmp += 1
            if p >= G:
                return tmp


D, G = map(int,input().split())
pc = [list(map(int,input().split())) for i in range(D)]
cnt = 0
tmp = 0

for i in range(D):
    p = (i+1) * 100 * pc[i][0]
    p += pc[i][1]
    tmp = pc[i][0]
    while p < G:
        tmp += add(pc, p, G, tmp)
    cnt = min(cnt, tmp)
print(cnt)


Fixed submission:
D, G = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(D)]

def dfs(question_num, rquired_point):
    if question_num < 0:
        return 10 ** 9

    point = (question_num+1) * 100
    ans_num = min(rquired_point // point, pc[question_num][0])
    score = ans_num * point

    if ans_num == pc[question_num][0]:
        score += pc[question_num][1]

    if rquired_point > score:
        ans_num += dfs(question_num-1, rquired_point-score)
    
    return min(ans_num, dfs(question_num-1, rquired_point))

print(dfs(D-1, G))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ret = 0
for l in range(N):
    for r in range(l, N):
        s = 0
        xor = 0
        for i in range(l, r+1):
            s += A[i]
            xor = xor ^ A[i]
        if s == xor:
            ret += 1

print(ret)

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

def ischeck(amount, target):
    for i in range(30):
        a = (amount >> i) & 1
        b = (target >> i) & 1
        if a & b:
            return False
    return True

ans = 0
tmp = A[0]
r = 0
for l in range(N):
    if r == l:
        tmp = A[l]
        r += 1
    while r < N and ischeck(tmp, A[r]):
        tmp += A[r]
        r += 1
    ans += (r - l)
    tmp -= A[l]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int, input().split()
S = input()
res = 10 ** 9
for i in range(len(S)):
    tmp = S[:i].count("W") + S[i+1:].count("E")
    res = tmp if tmp < res else res
print(res)


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

e = S.count("E")
w = 0
res = e
for i, s in enumerate(S):
    if s == "E":
        e -= 1
    tmp = e + w
    res = tmp if tmp < res else res
    if s == "W":
        w += 1
print(res)
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if d*2 >= a-c
    print("Yes")
else:
    print("No")

Fixed submission:
a, b, c, d = map(int, input().split())
diff = max(abs(a-b), abs(b-c))
if diff <= d or abs(a-c) <= d:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

sub = []
for i in range(1, len(s)+1):
    for k in range(len(s)-i+1):
        sub.append(s[k:k+i])

sub = list(set(sub))
sub.sort()
print(sub[K-1])


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

sub = []
for i in range(1, K+1):
    for k in range(len(s)-i+1):
        sub.append(s[k:k+i])

sub = list(set(sub))
sub.sort()
print(sub[K-1])

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

sub = []
for i in range(1, len(s)+1):
    for k in range(len(s)-i+1):
        sub.append(s[k:k+i])

sub = list(set(sub))
sub.sort()
print(sub[k+1])


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

sub = []
for i in range(1, K+1):
    for k in range(len(s)-i+1):
        sub.append(s[k:k+i])

sub = list(set(sub))
sub.sort()
print(sub[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
def primes(n):
    '''
    素数テーブルの作成
    '''
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    ret = []
    for i, p in enumerate(is_prime):
        if p:
            ret.append(i)
    return ret, is_prime
prime_list, is_prime = primes(55555 * 100)
prime_list.reverse()

from itertools import combinations

N = int(input())
A = []
for i in range(5):
    A.append(prime_list.pop())

while len(A) < N:
    n = prime_list.pop()
    if not any([is_prime[sum(comb)+n] for comb in combinations(A, 4)]):
        A.append(n)

print(*A, sep=" ")



Fixed submission:
N = int(input())

def get_primes(n):
    '''
    素数テーブルの作成
    '''
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i, b in enumerate(is_prime):
        if b:
            yield i

primes_and_mod1 = []
for i in get_primes(55999):
    if i % 5 == 1:
        primes_and_mod1.append(i)

print(*primes_and_mod1[:N], sep=" ")

Buggy python submission (verdict: Runtime Error):
def primes(n):
    '''
    素数テーブルの作成
    '''
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    ret = []
    for i, p in enumerate(is_prime):
        if p:
            ret.append(i)
    return ret, is_prime
prime_list, is_prime = primes(55555 * 10)
prime_list.reverse()

from itertools import combinations

N = int(input())
A = []
for i in range(5):
    A.append(prime_list.pop())

while len(A) < N:
    n = prime_list.pop()
    if not any([is_prime[sum(comb)+n] for comb in combinations(A, 4)]):
        A.append(n)

print(*A, sep=" ")



Fixed submission:
N = int(input())

def get_primes(n):
    '''
    素数テーブルの作成
    '''
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i, b in enumerate(is_prime):
        if b:
            yield i

primes_and_mod1 = []
for i in get_primes(55999):
    if i % 5 == 1:
        primes_and_mod1.append(i)

print(*primes_and_mod1[:N], sep=" ")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

suml = [0] * (N+1)
tmp = 0
for i in range(1, N+1):
    tmp += A[i-1]
    suml[i] = tmp

ret = 0
for i in range(N+1):
    for j in range(i+1, N+1):
        if suml[j] == suml[i]:
            ret += 1

print(ret)


Fixed submission:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]

suml = [0] * (N+1)
tmp = 0
for i in range(1, N+1):
    tmp += A[i-1]
    suml[i] = tmp

c = Counter(suml)
ret = 0
for i in c.values():
    if i > 1:
        ret += (i-1) * i // 2

print(ret)
Buggy python submission (verdict: Runtime Error):
s = input()
n = s.count("o")
print(100 × n + 700)

Fixed submission:
s = input()
n = s.count("o")
print(100 * n + 700)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
tmp = 0
r = 0
for a in A:
    if maxA == a:
        continue
    combA = cmb(maxA, a)
    if tmp < combA:
        tmp = combA
        r = a

print(maxA, r)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
halfA = maxA // 2
tmp = 10 ** 9
r = 0
for a in A:
    if a == maxA:
        continue
    half = abs(halfA - a)
    if tmp > half:
        tmp = half
        r = a

print(maxA, r)

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
tmp = 0
r = 0
for a in A:
    if maxA == a:
        continue
    combA = comb(maxA, a)
    if tmp < combA:
        tmp = combA
        r = a

print(maxA, r)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
halfA = maxA // 2
tmp = 10 ** 9
r = 0
for a in A:
    if a == maxA:
        continue
    half = abs(halfA - a)
    if tmp > half:
        tmp = half
        r = a

print(maxA, r)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

for i in range(N):
    num = 0
    pos = 0
    for ai, av in enumerate(A):
        if ai == i:
            continue
        num += abs(pos - av)
        pos = av
    num += abs(pos - 0)
    print(num)

Fixed submission:
N = int(input())
A = [0] * (N + 2)
for i, v in enumerate(input().split()):
    A[i+1] = int(v)
num = sum([abs(A[i] - A[i+1]) for i in range(N+1)])
for i in range(1,N+1):
    ret = num + abs(A[i-1] - A[i+1]) - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]))
    print(ret)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if a+b => c:
  print("Yes")
else:
  print("No")


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

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if a+b =< c:
  print("Yes")
else:
  print("No")

Fixed submission:
a,b,c = map(int, input().split())
if a + b < c:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
print(input()//3)

Fixed submission:
print(int(input())//3)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = []
for i in range(N):
    s = input()
    if s[0] in [ 'M','A','R','C','H' ]:
        S.append(s)

S = list(set(S))

N = len(S)
selected = [""] * 2
cnt = 0
for i in range(N):
    selected[0] = S[i][0]
    for k in range(i+1, N):
        if selected[0] == S[k][0]:
            continue
        selected[1] = S[k][0]
        for t in range(k+1, N):
            if selected[1] == S[t][0]:
                continue
            cnt += 1
print(cnt)

Fixed submission:
import numpy as np
import itertools
cnt = 0
N = int(input())
S = {'M':0,'A':0,'R':0,'C':0,'H':0}
march = ['M','A','R','C','H']
for i in range(N):
    s = input()[0]
    if s in march:
        S[s] += 1
seq = S.values()
for i in list(itertools.combinations(seq, 3)):
    i = np.array(i)
    cnt += np.prod(i)

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
# とりあえず先頭の性別を取得する
print(0)
begin = input()

l, r = 0, N
while r - l > 1:
    mid = (l+r)//2
    print(mid)
    sex = input()
    if sex != begin:
        r = mid
    else:
        l = mid

print(l)


Fixed submission:
N = int(input())
# とりあえず先頭の性別を取得する
print(0)
begin = input()

l, r = 0, N
while r - l > 1:
    mid = (l+r)//2
    print(mid)
    sex = input()
    if sex == "Vacant":
        l = mid
        break
    elif mid % 2 == 0:
        if sex != begin:
            r = mid
        else:
            l = mid
    else:
        if sex != begin:
            l = mid
        else:
            r = mid

print(l)
Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input())
A = list(map(int, input().split()))
def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt

l,r = 0, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) > 2:
        r = mid
    else:
        l = mid
maxcnt = l

l,r = 0, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) < 2:
        l = mid
    else:
        r = mid
mincnt = r


if check(mincnt, A) == check(maxcnt, A) == 2:
    print(mincnt, maxcnt)
else:
    print(-1)



Fixed submission:
import math
K = int(input())
A = list(map(int, input().split()))
mincnt = 2
for a in reversed(A):
    if a < mincnt:
        a = math.ceil(mincnt/a) * a
    mincnt = max(mincnt, a)

#print(mincnt)

maxcnt = 2
nowgropu = 1
for a in reversed(A):
    nowgropu = maxcnt // a
    maxcnt = a * (nowgropu + 1) - 1

#print(maxcnt)

def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt == 2

#print(check(mincnt, A))
if check(mincnt, A) and check(maxcnt, A):
    print(mincnt, maxcnt)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())

cnt = 0
strdit = {1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}
for i in input().split():
    strdit[int(i)] += 1

for i in strdit.keys():
    if strdit[i] != 0:
        cnt += abs(i-strdit[i])

print(cnt)



Fixed submission:
N = input()

cnt = 0
strdit = {}
for i in input().split():
    i = int(i)
    if i not in strdit.keys():
        strdit[i] = 0
    strdit[i] += 1

for i in strdit.keys():
    if i > strdit[i]:
        cnt += strdit[i]
    else:
        cnt += strdit[i] - i

print(cnt)
Buggy python submission (verdict: Runtime Error):
X, Y = map(int, input().split())

l ={ "A":1, "B":2, "C":3, "D":4, "E":5, "F":6 }
res = ""
if l[X] == l[Y]:
    res = "="
elif l[X] > l[Y]:
    res = ">"
else:
    res = "<"
print(res)

Fixed submission:
X, Y = input().split()

l ={ "A":1, "B":2, "C":3, "D":4, "E":5, "F":6 }
res = ""
if l[X] == l[Y]:
    res = "="
elif l[X] > l[Y]:
    res = ">"
else:
    res = "<"
print(res)
Buggy python submission (verdict: Runtime Error):
c1 = input()
c2 = input()
res = "YES" if c1[0] == c2[0] and c1[2] == c2[2] "NO"
print(res)

Fixed submission:
c1 = input()
c2 = input()
c1 = c1[2] + c1[1] + c1[0]
res = "YES" if c1 == c2 else "NO"
print(res)
Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)
L = list(S)

# 回文の判定
def judge(s):
    n = len(s)
    half = n//2
    for i in range(half):
        if s[i] != s[n-1-i]:
            return False
    return True

removeX = S.replace("x", "")
n_removex = len(removeX)
if N % 2 == 0:
    center = removeX[n_removex//2-1:n_removex//2+1]
else:
    center = removeX[n_removex//2:n_removex//2+1]
left, right = S.split(center)
left_idx = 0
right_idx = len(right) - 1
ret = 0
while left_idx < len(left) and right_idx > -1:
    if left[left_idx] != right[right_idx]:
        if left[left_idx] == "x":
            right_idx -= 1
            ret += 1
        elif right[right_idx] == "x":
            left_idx += 1
            ret += 1
    else:
        left_idx += 1
        right_idx -= 1

ret += len(left) - left_idx
ret += right_idx + 1
if judge(removeX):
    print(ret)
else:
    print(-1)



Fixed submission:
S = input()
N = len(S)
L = list(S)
left_idx = 0
right_idx = N - 1
ret = 0
while left_idx < right_idx:
    l = S[left_idx]
    r = S[right_idx]
    if l == r:
        left_idx += 1
        right_idx -= 1
    elif l == "x":
        ret += 1
        left_idx += 1
    elif r == "x":
        ret += 1
        right_idx -= 1
    else:
        ret = -1
        break

print(ret)

Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)
L = list(S)

# 回文の判定
def judge(s):
    n = len(s)
    half = n//2
    for i in range(half):
        if s[i] != s[n-1-i]:
            return False
    return True

removeX = S.replace("x", "")
n_removex = len(removeX)
if N % 2 == 0:
    center = removeX[n_removex//2-1:n_removex//2+1]
else:
    center = removeX[n_removex//2:n_removex//2+1]
left, right = S.split(center)
left_idx = 0
right_idx = len(right) - 1
ret = 0
while left_idx < len(left) and right_idx > -1:
    if left[left_idx] != right[right_idx]:
        if left[left_idx] == "x":
            right_idx -= 1
            ret += 1
        if right[right_idx] == "x":
            left_idx += 1
            ret += 1
    else:
        left_idx += 1
        right_idx -= 1

ret += len(left) - left_idx
ret += right_idx + 1
if judge(removeX):
    print(ret)
else:
    print(-1)


Fixed submission:
S = input()
N = len(S)
L = list(S)
left_idx = 0
right_idx = N - 1
ret = 0
while left_idx < right_idx:
    l = S[left_idx]
    r = S[right_idx]
    if l == r:
        left_idx += 1
        right_idx -= 1
    elif l == "x":
        ret += 1
        left_idx += 1
    elif r == "x":
        ret += 1
        right_idx -= 1
    else:
        ret = -1
        break

print(ret)
Buggy python submission (verdict: Runtime Error):
def calc(N, h, n):
    base = 4/N - 1/h - 1/n
    if base == 0:
        return False, 0
    ret = 1/base
    return ret == int(ret) and 0 <= ret <= 3500, int(ret)

N = int(input())

def f(N):
    for h in range(1, 3501):
        for n in range(1, 3501):
            judge, ret = calc(N,h,n)
            if judge:
                return h, n, ret

print(*f(N))


Fixed submission:
def calc(N, h, n):
    base = 4 * h * n - N * n - N * h
    if base <= 0:
        return False, -1
    ret = (N*h*n) / base
    return ret == int(ret) and 0 <= ret <= 3500, int(ret)

N = int(input())

def f(N):
    for h in range(1, 3501):
        for n in range(1, 3501):
            judge, ret = calc(N,h,n)
            if judge:
                return h, n, ret
    return -1, -1, -1

print(*f(N))

Buggy python submission (verdict: Runtime Error):
def calc(N, h, n):
    base = 4/N - 1/h - 1/n
    if base == 0:
        return False, 0
    ret = 1/base
    return ret == int(ret) and ret >= 0, int(ret)

N = int(input())

def f(N):
    for h in range(1, 3501):
        for n in range(1, 3501):
            judge, ret = calc(N,h,n)
            if judge:
                return h, n, ret

print(*f(N))


Fixed submission:
def calc(N, h, n):
    base = 4 * h * n - N * n - N * h
    if base <= 0:
        return False, -1
    ret = (N*h*n) / base
    return ret == int(ret) and 0 <= ret <= 3500, int(ret)

N = int(input())

def f(N):
    for h in range(1, 3501):
        for n in range(1, 3501):
            judge, ret = calc(N,h,n)
            if judge:
                return h, n, ret
    return -1, -1, -1

print(*f(N))

Buggy python submission (verdict: Runtime Error):
def calc(N, h, n):
    base = 4/N - 1/h - 1/n
    if base == 0:
        return False, 0
    ret = 1/base
    return ret == int(ret) and ret > 0, int(ret)

N = int(input())

def f(N):
    for h in range(1, 3501):
        for n in range(1, 3501):
            judge, ret = calc(N,h,n)
            if judge:
                return h, n, ret

print(*f(N))


Fixed submission:
def calc(N, h, n):
    base = 4 * h * n - N * n - N * h
    if base <= 0:
        return False, -1
    ret = (N*h*n) / base
    return ret == int(ret) and 0 <= ret <= 3500, int(ret)

N = int(input())

def f(N):
    for h in range(1, 3501):
        for n in range(1, 3501):
            judge, ret = calc(N,h,n)
            if judge:
                return h, n, ret
    return -1, -1, -1

print(*f(N))
Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D, E, F = map(int, input().split())

def calc(a, b):
    if a == 0 or b == 0: return 0
    return 100 * b / (a + b)
ans = 0
tmp = 0
for i in range(F//100+1):
    for j in range(F//100+1):
        water = i * 100 + j * 100
        if 1 > water or water > F: break
        for k in range(F//C+1):
            for l in range(F//D+1):
                suger = k * C + l * D
                if water + suger > F: break
                if water * E // 100 < suger: break
                t = calc(water, suger)
                if tmp < t:
                    tmp = t
                    ans = (water+suger, suger)

print(*ans)




Fixed submission:
import math
A, B, C, D, E, F = map(int, input().split())

def calc(a, b):
    if a == 0 or b == 0: return 0
    return 100 * b / (a + b)
ans = (0, 0)
tmp = 0
ret = set()
for i in range(3001):
    for j in range(3001):
        water = i * A * 100 + j * B * 100
        if 1 > water or water > F: break
        for k in range((F-water)//C+1):
            for l in range((F-water)//D+1):
                suger = k * C + l * D
                if water + suger > F: break
                if water * E // 100 < suger: break
                t = calc(water, suger)
                #ret.add((t, water+suger, suger))
                if tmp <= t:
                    tmp = t
                    ans = (water+suger, suger)

#ret = list(ret)
#ret.sort(reverse=True)
print(*ans)