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

Fixed submission:
from collections import defaultdict

def foo():
	H, W = map(int, input().split())
	s = ""
	for _ in range(H):
		s += input()

	counter = defaultdict(int)
	for c in s:
		counter[c] += 1

	x1, x2 = H // 2, H % 2
	y1, y2 = W // 2, W % 2

	n = x1 * y1
	k = 0
	for c in counter:
		if k == n:
			break
		while k != n and counter[c] >= 4:
			k += 1
			counter[c] -= 4

	if k != n:
		print("No")
		return

	if x2 == 1:
		n = y1
		k = 0
		for c in counter:
			if k == n:
				break
			while k != n and counter[c] >= 2:
				k += 1
				counter[c] -= 2
		if k != n:
			print("No")
			return

	if y2 == 1:
		n = x1
		k = 0
		for c in counter:
			if k == n:
				break
			while k != n and counter[c] >= 2:
				k += 1
				counter[c] -= 2
		if k != n:
			print("No")
			return
			
	print("Yes")

foo()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

def foo():
	H, W = map(int, input().split())
	s = ""
	for _ in range(H):
		s += input()

	counter = defaultdict(int)
	for c in s:
		counter[c] += 1

	x1, x2 = H // 2, H % 2
	y1, y2 = W // 2, W % 2

	n = x1 * y1
	k = 0
	for c in counter:
		if k == n:
			break
		while k != n and counter[c] >= 4:
			k += 1
			counter[c] -= 4

	if k != n:
		print("No")
		return

	if x2 == 1:
		n = y1
		k = 0
		for c in counter:
			if k == n:
				break
			while k != n and counter[c] >= 2:
				k += 1
				counter[c] -= 2
		if k != n:
			print("No")
			return

	if y2 == 1:
		n = x1
		k = 0
		for c in counter:
			if k == n:
				break
			while k != n and counter[c] >= 2:
				k += 1
				counter[c] -= 2
		if k != n:
			print("No")
			return

	if sum(counter.values() )	
	print("Yes")

foo()
Problem p03992 (python)

Fixed submission:
s = list(input())
s = s[:4] + [' '] + s[4:]
print(''.join(s))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
 
count = 0
 
for i, target in enumerate(a):
	if a[target - 1] == i + 1:
		count += 1
 
print(count // 2)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
 
count = 0
 
for i, target in enumerate(a):
	if a[target - 1] == i + 1:
		count += 1
 
print(count // 2)

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

count = 0

for i, target in enumerate(a):
	if a[target - 1] == i + 1:
		count += 1

print(count // 2)
Problem p03591 (python)

Fixed submission:
if str.lower(input())[:4] == "yaki":
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = str(input())
print str.lower(s)[:4] == "yaki"

Buggy submission (verdict: Runtime Error):
s = str(input())
print str.lower(s)[:4] == "yaki"

Buggy submission (verdict: Runtime Error):
s = str(raw_input())
print(str.lower(s)[:4] == "yaki")
Problem p03591 (python)

Fixed submission:
s = input()
if len(s)>=4 and s[:4] == 'YAKI':
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import fileinput
s = fileinput.input().strip()
if len(s)>=4 and s[:4] == 'YAKI':
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import fileinput
s = fileinput.input().strip()
print(len(s)>=4 and s[:3] == 'YAKI')
Problem p03592 (python)

Fixed submission:
N,M,K = map(int,input().strip().split())
def judge(N,M,K):
    if K > N * M or K < 0:
        return False
    for n in range(0, N + 1):
        for m in range(0, M + 1):
            if n * M + m * N - 2*m * n == K:
                return True
    return False
if judge(N, M, K):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N,M,K = map(int,input().strip().split())
def judge(N,M,K):
    if K > N * M or K < 0:
        return False
    for n in range(0, N + 1):
        for m in range(0, M + 1):
            if n * M + m * N - m * n == K or:
                return True
    return False
if judge(N, M, K):
    print("Yes")
else:
    print("No")
Problem p04029 (python)

Fixed submission:
from sys import stdin, stdout

n = int(stdin.read().strip())

result = str(int(n * (n + 1) / 2))

stdout.write(result)

Buggy submission (verdict: Runtime Error):
import sys

n = int(sys.stdin().strip())

result = str(int(n * (n + 1) / 2))

sys.stdout()
Problem p03583 (python)

Fixed submission:
n = int(input())
ans = None
for i in range(1, 3501, 1):
	for j in range(1, 3501, 1):
		dominator = 4 * i * j - n * (i + j)
		if dominator > 0:
			numerator = i * j * n
			if numerator % dominator == 0:
				ans = (i, j, int(numerator / dominator))
				break
	if ans is not None:
		break
print(" ".join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
import math

def is_prime(q):
    if q == 2:
        return (True, 0)
    if q < 2:
        return (False, 1)
    if q&1 == 0:
        return (False, 2)

    i = 3
    end = int(math.sqrt(q))
    while i <= end:
        if q%i is 0:
            return (False, i)
        i += 2
    return (True, 0)

def split22(n, k):
	if n % k != 0:
		return None
	ml = int(n / k)
	ret = is_prime(ml)
	if ret[0] is True:
		return None
	return (int(n/2), int(ret[1]), int(ml/ret[1]))

def split13(n):
	# n = (3 - m) * l
	if n&1 == 0:
		l = n / 2
		if math.gcd(l, 2) == n:
			return (n, l, 2)
	# l^2 - 3l + n = 0
	tmp = 3**2 - 4 * n
	if tmp < 0:
		return None
	_x = math.sqrt(tmp)
	if _x - int(_x) == _x:
		x = (-1) * _x - b
		if x > 0:
			x = _x - b
		return (n, x, 3-x)
	return None

n = int(input())
ans = None

ans = split13(n)
k = 1
while ans is None:
	if n&1 == 0:
		ans = split22(n, k)
	n *= 2
	k *= 2

print(" ".join(map(str, ans)))
Problem p03583 (python)

Fixed submission:
# coding: utf-8
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    return (N,)


def solve(N):
    ans = []
    for h in range(1, 3501):
        flag = False
        for n in range(1, 3501):
            if 4 * h * n - N * h - N * n == 0:
                continue
            div, mod = divmod(N * h * n, 4 * h * n - N * h - N * n)
            if mod == 0 and div > 0:
                ans = [h, n, div]
                flag = True
                break
        if flag:
            break
    ans = " ".join(map(str, ans))
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    return (N,)


def solve(N):
    ans = []
    for h in range(1, 3501):
        flag = False
        for n in range(1, 3501):
            w = (N * h * n) / (4 * h * n - N * h - N * n)
            if w > 0 and int(w) == w:
                ans = [h, n, w]
                flag = True
                break
        if flag:
            break
    ans = " ".join(map(str, map(int, ans)))
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()
Problem p03639 (python)

Fixed submission:
# coding: utf-8
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    a = ILI()
    return N, a


def solve(N, a):
    n_odd = 0
    n_div_2 = 0
    n_div_4 = 0
    for _a in a:
        if _a % 2 == 1:
            n_odd += 1
        else:
            if _a % 4 == 0:
                n_div_4 += 1
            else:
                n_div_2 += 1

    ans = ""
    if n_div_2 == 0:
        if n_div_4 >= n_odd - 1:
            ans = "Yes"
        else:
            ans = "No"
    else:
        if n_div_4 >= n_odd:
            ans = "Yes"
        else:
            ans = "No"

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
6
2 7 1 8 2 8
Problem p03675 (python)

Fixed submission:
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    n = II()
    a = list(map(str, input().split()))
    return n, a


def solve(n, a):
    b = collections.deque([])
    if n % 2 == 0:
        for i, ele in enumerate(a):
            if i % 2 == 0:
                b.append(ele)
            else:
                b.appendleft(ele)
    else:
        for i, ele in enumerate(a):
            if i % 2 == 0:
                b.appendleft(ele)
            else:
                b.append(ele)

    ans = " ".join(list(b))
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
a = list(map(int, input().split()))
b = collections.deque(list)
if n % 2 == 0:
    for i, ele in enumerate(a):
        if i % 2 == 0:
            b.append(ele)
        else:
            b.appendleft(ele)
else:
    for i, ele in enumerate(a):
        if i % 2 == 0:
            b.appendleft(ele)
        else:
            b.append(ele)

print(" ".join(b))
Problem p03715 (python)

Fixed submission:
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    H, W = ILI()
    return (H, W)

def solve(H, W):
    ans = INF
    
    if H % 3 == 0 or W % 3 == 0:
        return 0
    else:
        ans = min(ans, H, W)

    if W % 2 == 0:
        for h in range(1, H):
            num_1 = h * W
            num_2 = (H - h) * W // 2
            ans = min(ans, abs(num_1 - num_2))
    else:
        for h in range(1, H):
            num_1 = h * W
            num_2 = (H - h) * (W // 2)
            num_3 = (H - h) * (W // 2 + 1)
            nums = sorted([num_1, num_2, num_3])
            ans = min(ans, (nums[2] - nums[0]))

    if H % 2 == 0:
        for w in range(1, W):
            num_1 = w * H
            num_2 = (W - w) * H // 2
            ans = min(ans, abs(num_1 - num_2))
    else:
        for w in range(1, W):
            num_1 = w * H
            num_2 = (W - w) * (H // 2)
            num_3 = (W - w) * (H // 2 + 1)
            nums = sorted([num_1, num_2, num_3])
            ans = min(ans, (nums[2] - nums[0]))
    
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    a = ILI()
    return (N, a)


def solve(N, a):
    a_lef = a[0: N]
    a_rig = [-i for i in a[2 * N: 3 * N]]
    heapq.heapify(a_lef)
    heapq.heapify(a_rig)
    sum_lef = sum(a_lef)
    sum_rig = sum(a_rig)
    l_sum_lef = [sum_lef]
    l_sum_rig = [sum_rig]
    
    for i in range(1, N + 1):
        heapq.heappush(a_lef, a[N - 1 + i])
        lef_pop = heapq.heappop(a_lef)
        sum_lef += a[N - 1 + i] - lef_pop
        l_sum_lef.append(sum_lef)
        
        heapq.heappush(a_rig, -a[2 * N - i])
        rig_pop = heapq.heappop(a_rig)
        sum_rig += -a[2 * N - i] - rig_pop
        l_sum_rig.append(sum_rig)

    ans = -INF

    for i in range(N + 1):
        num_dif = l_sum_lef[i] + l_sum_rig[N - i]
        ans = max(ans, num_dif)

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()
Problem p03734 (python)

Fixed submission:
# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def solve(N, W, w_v):
    memo = collections.defaultdict(int)
    memo[0] = 0
    for w, v in w_v:
        for w_memo, v_memo in sorted(list(memo.items()), key=lambda x: -x[0]):
            if w + w_memo > W:
                continue
            if memo[w + w_memo] < v_memo + v:
                memo[w + w_memo] = v_memo + v

    return max(memo.values())


def main():
    N, W = ILI()
    w_v = IAI(N)
    print(solve(N, W, w_v))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def solve(N, W, w, v):
    dp = [[0] * (W + 1) for __ in range(N + 1)]

    for i in range(N - 1, -1, -1):
        for j in range(W + 1):
            if j < w[i]:
                dp[i][j] = dp[i + 1][j]
            else:
                dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i])
    
    ans = dp[0][W]
    return ans


def main():
    N, W = ILI()
    w, v = [], []
    for __ in range(N):
        x, y = ILI()
        w.append(x)
        v.append(y)
    print(solve(N, W, w, v))


if __name__ == "__main__":
    main()
Problem p03587 (python)

Fixed submission:
N = raw_input()
print(N.count('1'))

Buggy submission (verdict: Runtime Error):
N = input()
N = float(N)
result = 4/N
 
def output2():
    for i in range(3500):
        for j in range(3500):
            h = float(i+1)
            n = float(j+1)
            
            sum_ = 1/h + 1/n
            
            sum2 = result - sum_
            
            if(sum2 <= 0):
                continue
            
            w =  1/sum2
            
            if(w == int(w)):
                return('{} {} {}'.format(int(h),int(n),int(w)))
 
print(output2())
Problem p03605 (python)

Fixed submission:
N = raw_input()
N = int(N)

num10 = N/10
num1 = N - num10*10

if num10 == 9 or num1 == 9:
	print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
N = raw_input()
N = int(N)

a = {}
for i in range(N):
	s_input = raw_input()
	if s_input in a:
		del a[s_input]
	else:
		a[s_input] = s_input

print(len(a))

Buggy submission (verdict: Runtime Error):
N = raw_input()
N = int(N)

a = {}
for i in range(N):
	s_input = raw_input()
	s_input = int(s_input)
	if s_input in a:
		del a[s_input]
	else:
		a[s_input] += 1

print(len(a))

Buggy submission (verdict: Runtime Error):
N = raw_input()
N = int(N)

a = []
for i in range(N):
	s_input = input()
	s_input = int(s_input)
	if s_input in a:
		a.remove(s_input)
	else:
		a.append(s_input)

print(len(a))

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

a = []
for i in range(N):
	s_input = raw_input()
	s_input = int(s_input)
	if s_input in a:
		a.remove(s_input)
	else:
		a.append(s_input)

print(len(a))

Buggy submission (verdict: Runtime Error):
N = raw_input()
N = int(N)

a = []
for i in range(N):
	s_input = raw_input()
	s_input = long(s_input)
	if s_input in a:
		a.remove(s_input)
	else:
		a.append(s_input)

print(len(a))

Buggy submission (verdict: Runtime Error):
N = raw_input()
N = int(N)

a = []
for i in range(N):
	s_input = raw_input()
	s_input = int(s_input)
	if s_input in a:
		a.remove(s_input)
	else:
		a.append(s_input)
	a.sort()

print(len(a))
Problem p03607 (python)

Fixed submission:
n=int(raw_input())
li={}
while n !=0:
    a = raw_input()
    if a in li:
        del li[a]
    else:
        li[a]=a
    n-=1
print(len(li))

Buggy submission (verdict: Runtime Error):
N = raw_input()
N = int(N)

a = {}
for i in range(N):
	s_input = raw_input()
	s_input = int(s_input)
	if s_input in a:
		del a[s_input]
	else:
		a[s_input] += 1

print(len(a))

Buggy submission (verdict: Runtime Error):
N = raw_input()
N = int(N)

a = []
for i in range(N):
	s_input = raw_input()
	s_input = int(s_input)
	if s_input in a:
		a.remove(s_input)
	else:
		a.append(s_input)
    a.sort()

print(len(a))
Problem p03635 (python)

Fixed submission:
s = raw_input()
s = s.split(' ')
s = [int(x) for x in s]
n, m = s

print((n-1)*(m-1))

Buggy submission (verdict: Runtime Error):
N = raw_input()
N = int(N)
s = raw_input()
s = s.split(' ')
s = [float(x) for x in s]

n_list = [0 for i in range(3)]
for i in s:
	for t in range(3):
		i = i/2
		if (i - int(i) != 0):
			n_list[t] += 1
			break
		if(t == 2):
			n_list[t] += 1

if(n_list[0] <= n_list[2]):
	print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
N = raw_input()
N = int(N)
s = raw_input()
s = s.split(' ')
s = [float(x) for x in s]

n_list = []
for i in s:
	for t in range(3):
		i = i/2
		if (i - int(i) != 0):
			n_list.append(t)
			break
		if(t == 2):
			n_list.append(t)

if(n_list.count(0) <= n_list.count(2)):
	print('Yes')
else:
	print('No')
Problem p03591 (python)

Fixed submission:
s=input()
try:
    if s[0]=="Y" and s[1]=="A" and s[2]=="K" and s[3]=="I":
      print("Yes")
    else:
        print("No")
except:
    print("No")

Buggy submission (verdict: Runtime Error):
s=input()
if s[0]=="Y" and s[1]=="A" and s[2]=="K" and s[3]=="I":
    print("Yes")
else:
    print("No")
Problem p03605 (python)

Fixed submission:
a=int(input())
print("Yes") if a//10==9 or a%10==9 else print("No")

Buggy submission (verdict: Runtime Error):
n,m,r=map(int,input().split())
r=list(map(int,input().split()))
cost=[[99999999 if i!=j else 0 for j in range(n)] for i in range(n)]
for _ in range(m):
    a,b,c=map(int,input().split())
    cost[a-1][b-1]=cost[b-1][a-1]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j])
c=[[cost[y-1][x-1] for x in r] for y in r]
print(max(map(max,c)))
Problem p03589 (python)

Fixed submission:
import sys
N=int(input())
for h in range(1,3501):
    for n in range(h,3501):
        if 4*n*h-N*h-N*n >0:
            if (N*h*n)%(4*n*h-N*h-N*n)==0:
                w=int((N*h*n)/(4*n*h-N*h-N*n))
                print(h,n,w)
                sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
for i in range(1,3501):
    for j in range(i,3501):
        print(i,j)
        if 4*i*j-N*i-N*j > 0:
            if (N*i*j)%(4*i*j-N*i-N*j) == 0:
            print(i,j,int((N*i*j)/(4*i*j-N*i-N*j)))
            sys.exit()
Problem p03597 (python)

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

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

Fixed submission:
A, B, C, D, E, F = map(int, input().split())
 
x = set()
y = set()
 
for i in range(F // (100 * A) + 1):
    for j in range((F - 100 * A * i) // (100 * B) + 1):
        if i + j == 0:
            continue
        x.add(A * i * 100 + B * j * 100)
 
for i in range(F // C + 1):
    for j in range((F - C * i) // D + 1):
        y.add(C * i + D * j)
 
ret_w = 1
ret_s = -1
 
for w in x:
    for s in y:
        if w + s <= F and w * E / 100 >= s and s / (w + s) >= ret_s / ret_w:
            ret_s = s
            ret_w = w + s
 
print(ret_w, ret_s)

Buggy submission (verdict: Runtime Error):


A,B,C,D,E,F = list(map(int, input().split()))
#x is a list which represents for the volumn of water
x = set()

#y is a list which represents for the volumn of sugar
y = set()

for i in range(F//C+1):
    for j in range((F-C*i)//D+1):
        #if i + j == 0:
            continue
        y.add( i * C + j * D)

for i in range(F//(100 * A)+1):
    for j in range((F-100*A*i)//(100*B)+1):
        if i + j == 0:
            continue
        x.add(i * A * 100 + j * B * 100)
#print(x)
#print(y)
ans_sweetwater = 1
ans_sugar = -1
#ans_density = -1
#density = E/(100+E)
#print("density: ",density)
for m in x:
    for n in y:
        #tmp_density = n/(m+n)
        if m + n <= F and m*E/100 >= n and ans_sugar/ans_sweetwater <= n/(m+n):
            ans_sweetwater =  m + n
            ans_sugar = n
            #ans_density = tmp_density
print(ans_sweetwater,ans_sugar)

Buggy submission (verdict: Runtime Error):
import sys

A,B,C,D,E,F = list(map(int, input().split()))
#x is a list which represents for the volumn of water
x = list()

#y is a list which represents for the volumn of sugar
y = list()

for i in range(F//C+1):
    for j in range(F-C*i//D+1):
        if i == j == 0:
            continue
        tmp_y = i * C + j * D

        if tmp_y <= F:
            y.append(tmp_y)

for i in range(F//(100 * A)+1):
    for j in range(F-(100*A*i)//(100*B)+1):
        if i == j == 0:
            continue

        tmp_x = i * A * 100 + j * B * 100

        if tmp_x <= F:
            x.append(tmp_x)
#print(x)
#print(y)
ans_sweetwater = 0
ans_sugar = 0
ans_density = 0
density = E/(100+E)
#print("density: ",density)
for n in y:
    for m in x:
        tmp_density = n/(m+n)
        if m + n <= F and x/100*E >= y and ans_density <= tmp_density:
            ans_sweetwater =  m + n
            ans_sugar = n
            ans_density = tmp_density
print(ans_sweetwater,ans_sugar)
Problem p03589 (python)

Fixed submission:
n = int(input())

def solve(n):
	for x in range(1, 3501):
		nx = n * x
		for y in range(x, 3501):
			# 4/n = 1/x + 1/y + 1/z
			# 1/z = 4/n - 1/x - 1/y
			# z = 1/(4/n - 1/x - 1/y)
			# z = nxy/(4xy - ny - nx)
			nxy = nx * y
			den = 4*x*y - n*y -nx
			if (den > 0 and nxy % den == 0 and nxy//den > 0):
				print(x, y, nxy//den)
				return

solve(n)

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

def solve(n):
	for x in range(1, 3501):
		nx = n * x
		for y in range(x, 3501):
			# 4/n = 1/x + 1/y + 1/z
			# 1/z = 4/n - 1/x - 1/y
			# z = 1/(4/n - 1/x - 1/y)
			# z = nxy/(4xy - ny - nx)
			nxy = nx * y
			den = 4*x*y - n*y -nx
			if (nxy % den == 0 and nxy//den > 0):
				print(x, y, nxy//den)
				return

solve(n)
Problem p03590 (python)

Fixed submission:
def solve(K, ABs):
    if not ABs: return 0
    ansK = sum(b for a, b in ABs if (K | a) == K)
    pool = []
    for i in range(30, -1, -1):
        if (K & (1<<i)):
            pool.append(i)
    for p in pool:
        v = 1 << p
        KK = (K >> p) << p
        KKK = (K >> p)
        t = sum(b for a, b in ABs if (not(a & v) and (a | KK) >> p == KKK))
        if t > ansK: ansK = t
    return ansK
   

N, K = map(int, input().split())
ABs = []
for i in range(N):
    a, b = map(int, input().split())
    if a > K: continue
    ABs.append([a, b])

print(solve(K, ABs))

Buggy submission (verdict: Runtime Error):
def solve(K, ABs):
    if not ABs: return 0
    ansK = sum(b for a, b in ABs if (K | a) == K)
    pool = []
    for i in range(30, -1, -1):
        if (K & (1<<i)):
            pool.append(i)
    for p in pool:
        v = 1 << p
        KK = (K >> p) << p
        KKK = (K >> p)
        t = sum(b for a, b in ABs if (not(a & v) and (a | KK) >> p == KKK)
        if t > ansK: ansK = t
    return ansK
   

N, K = map(int, input().split())
ABs = []
for i in range(N):
    a, b = map(int, input().split())
    if a > K: continue
    ABs.append([a, b])

print(solve(K, ABs))

Buggy submission (verdict: Runtime Error):
def solve(K, ABs):
    if not ABs return 0
    ansK = sum(b for a, b in ABs if (K | a) == K)
    pool = []
    for i in range(30, -1, -1):
        if (K & (1<<i)):
            pool.append(i)
        else:
            if pool:
                break
    for p in pool:
        v = 1 << p
        t = sum(b for a, b in ABs if not(a & v))
        if t > ansK: ansK = t
    return ansK
   

N, K = map(int, input().split())
ABs = []
for i in range(N):
    a, b = map(int, input().split())
    if a > K: continue
    ABs.append([a, b])

print(solve(K, ABs))