Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
dp = ["" for i in range(51)]
dp[0] = "P"

def solve(n, dp):
    if n == 0:
        return dp[0]
    else:
        if dp[n] == "":
            k = solve(n - 1,dp)
            return 'B' + k + 'P' + k + 'B'
        else:
            return dp[n]
n, x = list(map(int, input().split()))
dp = solve(n,dp)
print(dp[-x:].count('P'))


Fixed submission:
n, x = list(map(int, input().split()))

a = [1]
p = [1]
for i in range(1,n):
    a.append(a[i - 1] * 2 + 3)
    p.append(2 * p[i - 1] + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])
print(f(n,x))

Buggy python submission (verdict: Time Limit Exceeded):
dp = ["" for i in range(51)]
dp[0] = "P"

def solve(n, dp):
    if n == 0:
        return dp[0]
    else:
        if dp[n] == "":
            return 'B' + solve(n - 1,dp) + 'P' + solve(n - 1,dp) + 'B'
        else:
            return dp[n]
n, x = list(map(int, input().split()))
dp = solve(n,dp)
print(dp[-x:].count('P'))


Fixed submission:
n, x = list(map(int, input().split()))

a = [1]
p = [1]
for i in range(1,n):
    a.append(a[i - 1] * 2 + 3)
    p.append(2 * p[i - 1] + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])
print(f(n,x))
Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
data = []
for i in range(m):
    data.append([i + 1] + list(map(int, input().split())))
data = sorted(data, key = lambda x: (x[1], x[2]))
print(data)
ans = [[0,0,0,0,0,0], [0,0,0,0,0,0] for i in range(m)]
print(ans)
for i in range(m):


Fixed submission:
n, m = list(map(int, input().split()))
data = []
for i in range(m):
    data.append([i + 1] + list(map(int, input().split())))
    #data[0::] = cityNumber,
    #data[:0:] = prefect,
    #data[::0] = year
data = sorted(data, key = lambda x: (x[1], x[2]))
#prefect => year
ans = [[0,0,0] for i in range(m)]
#ans[::0] = city Number
#ans[0::] = prefect
#ans[:0:] = ID

pre = data[0][1]
num = 0
for i in range(m):
    ans[i][0] = data[i][1] # prefect
    ans[i][2] = data[i][0] #cityNumber
    if pre == data[i][1]:
        num += 1
    else:
        num = 1
    ans[i][1] = num
    pre = data[i][1]
ans = sorted(ans, key = lambda x:x[2])
for i in range(m):
    print("{:0=6}{:0=6}".format(ans[i][0],ans[i][1]))
Buggy python submission (verdict: Runtime Error):
import fractions
n,m=map(int,input().split())
s=list(str(input()))
t=list(str(input()))

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

l=lcm(n, m)
ans=[0]*(l*2)

for i in range(n):
    index=l//n*i+1

    if ans[index]==0:
        ans[index]=s[i]
#print(ans)
for i in range(m):
    index=l//m*i+1
    if ans[index]==0:
        ans[index]=t[i]
    else:
        if t[i]!=ans[index]:
            print(-1)
            exit()
#print(ans)
print(l)


Fixed submission:
from fractions import gcd
n, m = map(int, input().split())
s = input()
t = input()
#一文字目が違うと無理
gcd_n_m = gcd(n,m)
if gcd_n_m == 1 and s[0] == t[0]:
    print(n*m)
else:
    step_s = n // gcd_n_m
    step_t = m // gcd_n_m
    index_s = 0
    index_t = 0
    while index_s < n and index_t < m:
        if s[index_s] != t[index_t]:
            print(-1)
            exit()
        index_s += step_s
        index_t += step_t
    print(n*m//gcd_n_m)

Buggy python submission (verdict: Runtime Error):
import fractions
n,m=map(int,input().split())
s=list(str(input()))
t=list(str(input()))

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

l=lcm(n, m)
ans=[0]*(l+2)

for i in range(n):
    index=l//n*i+1

    if ans[index]==0:
        ans[index]=s[i]
#print(ans)
for i in range(m):
    index=l//m*i+1
    if ans[index]==0:
        ans[index]=t[i]
    else:
        if t[i]!=ans[index]:
            print(-1)
            exit()
#print(ans)
print(l)


Fixed submission:
from fractions import gcd
n, m = map(int, input().split())
s = input()
t = input()
#一文字目が違うと無理
gcd_n_m = gcd(n,m)
if gcd_n_m == 1 and s[0] == t[0]:
    print(n*m)
else:
    step_s = n // gcd_n_m
    step_t = m // gcd_n_m
    index_s = 0
    index_t = 0
    while index_s < n and index_t < m:
        if s[index_s] != t[index_t]:
            print(-1)
            exit()
        index_s += step_s
        index_t += step_t
    print(n*m//gcd_n_m)
Buggy python submission (verdict: Runtime Error):
n, t = list(map(int, input().split()))
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
minCost = 1001
for i in range(n):
    if data[i][1] <= t && minCost > data[i][0]:
        minCost = data[i][0]

if minCost == 1001:
    print("TLE")
else:
    print(minCost)

Fixed submission:
n, t = list(map(int, input().split()))
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
minCost = 1001
for i in range(n):
    if data[i][1] <= t and minCost > data[i][0]:
        minCost = data[i][0]

if minCost == 1001:
    print("TLE")
else:
    print(minCost)

Buggy python submission (verdict: Runtime Error):
n, t = list(map(input().split()))
data = []
for i in range(n):
    data.append(list(map(input().split())))
minCost = 1001
for i in range(n):
    if data[i][1] <= t:
        minCost = data[i][0]

if minCost == 1001:
    printf("TLE")
else:
    printf(minCost)

Fixed submission:
n, t = list(map(int, input().split()))
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
minCost = 1001
for i in range(n):
    if data[i][1] <= t and minCost > data[i][0]:
        minCost = data[i][0]

if minCost == 1001:
    print("TLE")
else:
    print(minCost)
Buggy python submission (verdict: Runtime Error):
import math

n, m = list(map(int, input().split()))
k = 0
for i in range(1, int(math.sqrt(m) + 1)):
    if m % i == 0 and m/k >= n:
        k = i
print(k)

Fixed submission:
import math

n, m = list(map(int, input().split()))
reg = (m / n)
k = 1
for i in range(1, int(math.sqrt(m) + 1)):
    if m % i == 0:
        a = m/i
        b = i
        if reg >= b and k < b:
            k = b
        if reg >= a and k < a:
            k = a
print(int(k))

Buggy python submission (verdict: Runtime Error):
import math

n, m = list(map(int, input().split()))
k = 0
for i in range(1, int(math.sqrt(m) + 1):
    if m % i == 0:
        k = i
print(k)


Fixed submission:
import math

n, m = list(map(int, input().split()))
reg = (m / n)
k = 1
for i in range(1, int(math.sqrt(m) + 1)):
    if m % i == 0:
        a = m/i
        b = i
        if reg >= b and k < b:
            k = b
        if reg >= a and k < a:
            k = a
print(int(k))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
k = 0
for i in range(1, int((m/n) + 1)):
    if m % i == 0:
        k = i
print(k)

Fixed submission:
import math

n, m = list(map(int, input().split()))
reg = (m / n)
k = 1
for i in range(1, int(math.sqrt(m) + 1)):
    if m % i == 0:
        a = m/i
        b = i
        if reg >= b and k < b:
            k = b
        if reg >= a and k < a:
            k = a
print(int(k))
Buggy python submission (verdict: Runtime Error):
n = input()
for i in range(len(n)):
  if n[i] == '1':
    n[i] = '9'
  elif n[i] == '9':
    n[i] = '1'
print(n)


Fixed submission:
n = list(input())
for i in range(len(n)):
  if n[i] == '1':
    n[i] = '9'
  elif n[i] == '9':
    n[i] = '1'
print("".join(n))

Buggy python submission (verdict: Runtime Error):
n = input()
for i in range(len(n)):
  if n[i] == '1':
    n[i] = '9'
   elif n[i] == '9':
    n[i] = '1'
print(n)


Fixed submission:
n = list(input())
for i in range(len(n)):
  if n[i] == '1':
    n[i] = '9'
  elif n[i] == '9':
    n[i] = '1'
print("".join(n))

Buggy python submission (verdict: Runtime Error):
n = input
for i in range(len(n)):
  if n[i] == '1':
    n[i] = '9'
   elif n[i] == '9':
    n[i] = '1'
print(n)

Fixed submission:
n = list(input())
for i in range(len(n)):
  if n[i] == '1':
    n[i] = '9'
  elif n[i] == '9':
    n[i] = '1'
print("".join(n))
Buggy python submission (verdict: Runtime Error):
#奇数だったら左にずらす。
#左にずらせないのであれば、下にずらす
h, w = map(int, input().split())
grid = []
ans = []
for i in range(h):
    grid.append(list(map(int, input().split())))
for i in range(h):
    for j in range(w):
        if grid[i][j] % 2 != 0:
            if j == w - 1 and i != h - 1:
                ans.append([i+1,j+1,i+2,j+1])
                grid[i+1][j] += 1
            else:
                ans.append([i+1,j+1,i+1,j+2])
                grid[i][j+1] += 1
n = len(ans)
print(n)
for i in ans:
    print("{} {} {} {}".format(i[0], i[1],i[2],i[3]))


Fixed submission:
#奇数だったら左にずらす。
#左にずらせないのであれば、下にずらす
h, w = map(int, input().split())
grid = []
ans = []
for i in range(h):
    grid.append(list(map(int, input().split())))
for i in range(h):
    for j in range(w):
        if grid[i][j] % 2 != 0:
            if j == w - 1:
                if i != h - 1:
                    ans.append([i+1,j+1,i+2,j+1])
                    grid[i+1][j] += 1
            else:
                ans.append([i+1,j+1,i+1,j+2])
                grid[i][j+1] += 1
n = len(ans)
print(n)
for i in ans:
    print("{} {} {} {}".format(i[0], i[1],i[2],i[3]))
Buggy python submission (verdict: Runtime Error):
h, w = list(map(int, input().split()))
grid = []
for i in range(h):
    temp = list(input())
    if "#" in temp:
        grid.append(temp)
    else:
        h -= 1
i = 0
while i < len(grid[0]):
    for j in range(h):
        if grid[j][i] == "#":
            i += 1
            break
        if j == h - 1:
            for k in range(h):
                del grid[k][i]
for i in range(len(grid[0])):
    print("".join(grid[i]))

Fixed submission:
h, w = list(map(int, input().split()))
grid = []
for i in range(h):
    temp = list(input())
    if "#" in temp:
        grid.append(temp)
    else:
        h -= 1
i = 0
while i < len(grid[0]):
    for j in range(h):
        if grid[j][i] == "#":
            i += 1
            break
        if j == h - 1:
            for k in range(h):
                del grid[k][i]
for i in range(h):
    print("".join(grid[i]))

Buggy python submission (verdict: Runtime Error):
import numpy as np
h, w = list(map(int, input().split()))
grid = []
for i in range(h):
    temp = list(input())
    if "#" in temp:
        grid.append(temp)
    else:
        h -= 1
i = 0
while i < len(grid[0]):
    for j in range(h):
        if grid[j][i] == "#":
            i += 1
            break
        if j == h - 1:
            for k in range(h):
                del grid[k][i]
for i in range(len(grid[0])):
    print("".join(grid[i]))

Fixed submission:
h, w = list(map(int, input().split()))
grid = []
for i in range(h):
    temp = list(input())
    if "#" in temp:
        grid.append(temp)
    else:
        h -= 1
i = 0
while i < len(grid[0]):
    for j in range(h):
        if grid[j][i] == "#":
            i += 1
            break
        if j == h - 1:
            for k in range(h):
                del grid[k][i]
for i in range(h):
    print("".join(grid[i]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    a[i] = a[i] - (i + 1)
if n % 2 == 0:
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    print(total)
else:
    total2 = 0
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    ave = a[int((n + 1)/2)]
    for i in range(n):
        total2 += abs(a[i] - ave)
    if total2 >= total:
        print(total)
    else:
        print(total2)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    a[i] = a[i] - (i + 1)
if n == 1:
    print(0)
    exit()
a.sort()
if n % 2 == 0:
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    print(total)
else:
    total2 = 0
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    ave = a[int((n + 1)/2)]
    for i in range(n):
        total2 += abs(a[i] - ave)
    if total2 >= total:
        print(total)
    else:
        print(total2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    a[i] = a[i] - (i + 1)
if n % 2 == 0:
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    print(total)
else:
    total2 = 0
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    ave = a[int((n + 1)/2)]
    for i in range(n):
        total2 += abs(a[i] - ave)
    if total2 >= total:
        print(total2)
    else:
        print(total)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    a[i] = a[i] - (i + 1)
if n == 1:
    print(0)
    exit()
a.sort()
if n % 2 == 0:
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    print(total)
else:
    total2 = 0
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    ave = a[int((n + 1)/2)]
    for i in range(n):
        total2 += abs(a[i] - ave)
    if total2 >= total:
        print(total)
    else:
        print(total2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    a[i] = a[i] - (i + 1)
if n % 2 == 0:
    ave = a[int(n/2)]
else:
    ave = int((a[int(n/2)] + a[int((n + 1)/2)]) / 2)
for i in range(n):
    total += abs(a[i] - ave)
print(total)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    a[i] = a[i] - (i + 1)
if n == 1:
    print(0)
    exit()
a.sort()
if n % 2 == 0:
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    print(total)
else:
    total2 = 0
    ave = a[int(n/2)]
    for i in range(n):
        total += abs(a[i] - ave)
    ave = a[int((n + 1)/2)]
    for i in range(n):
        total2 += abs(a[i] - ave)
    if total2 >= total:
        print(total)
    else:
        print(total2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
bit_acc = [[0 for i in range(21)] for j in range(n+1)]
for i in range(1,n+1):
    k = format(a[i-1], '021b')
    for j in range(len(k)):
        if k[j] == "1":
            bit_acc[i][j] = bit_acc[i-1][j] + 1
        else:
            bit_acc[i][j] = bit_acc[i-1][j]
left = 0
ans = 0
while left <= n:
    last = n
    flag = False
    for right in range(left+1,n+1):
        for j in range(21):
            if bit_acc[right][j] - bit_acc[left][j] >= 2:
                last = right - 1
                flag = True
                break
        if flag:
            break
    #print("l {}, r {}".format(left, last))
    ans += last - left
    left += 1
print(ans)



Fixed submission:
n = int(input())
a = list(map(int, input().split()))
bit_acc = [[0 for i in range(21)] for j in range(n+1)]
for i in range(1,n+1):
    k = format(a[i-1], '021b')
    for j in range(len(k)):
        if k[j] == "1":
            bit_acc[i][j] = bit_acc[i-1][j] + 1
        else:
            bit_acc[i][j] = bit_acc[i-1][j]
right = 1
left = 0
ans = 0
while left <= n:
    flag = True
    for j in range(21):
        if bit_acc[right][j] - bit_acc[left][j] >= 2:
            #print("l {}, r {}".format(left, right))
            ans += right - 1 - left
            left += 1
            flag = False
            break
    if flag:
        if right < n:
            right += 1
        else:
            #print("l {}, r {}".format(left, right))
            ans += right - left
            left += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
h, w, d = list(map(int, input().split()))
grid = []
num = [[] for i in range(h*w+1)]
graph = [[0 for i in range(w+1)] for j in range(h+1)]
for i in range(h):
    grid.append(list(map(int, input().split())))
for i in range(h):
    for j in range(w):
        num[grid[i][j]]=[j+1, i+1]
k = math.ceil((h*w) / d)
#initialize
cost = [[0 for i in range(k)] for j in range(d)]
for i in range(d):
    cost[i][0] = 0
for i in range(d + 1,h*w+1):
    x, y = num[i]
    prex, prey = num[i - d]
    cost[i % d][i//d] = abs(prex - x) + abs(prey - y)
    cost[i % d][i//d] += cost[i % d][(i - d)// d]  
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(cost[r%d][r//d] - cost[l%d][l//d])


Fixed submission:
import math
h, w, d = list(map(int, input().split()))
grid = []
num = [[] for i in range(h*w+1)]
for i in range(h):
    grid.append(list(map(int, input().split())))
for i in range(h):
    for j in range(w):
        num[grid[i][j]]=[j+1, i+1]
k = math.ceil((h*w+1) / d)
#initialize
cost = [[0 for i in range(k)] for j in range(d)]
for i in range(d + 1,h*w+1):
    x, y = num[i]
    prex, prey = num[i - d]
    cost[i % d][i//d] = abs(prex - x) + abs(prey - y)
    cost[i % d][i//d] += cost[i % d][(i - d)// d]
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(cost[r%d][r//d] - cost[l%d][l//d])
Buggy python submission (verdict: Runtime Error):
n, c = map(int, input().split())
data = [[0 for i in range(c+1)] for j in range(10**5+1)]
for i in range(n):
    s, t, channel = map(int, input().split())
    data[s][channel] += 1
    data[t+1][channel] -= 1
for i in range(c+1):
    for j in range(1,10**5+1):
        data[j][i] += data[j-1][i]
ans = 0
for i in range(10**5+1):
    sum_channel = 0
    for j in range(c+1):
        if data[i][j] == 1:
            sum_channel += 1
    ans = max(ans, sum_channel)
print(ans) 


Fixed submission:
n, c = map(int, input().split())
data = [[0 for i in range(c+1)] for j in range(10**5+2)]
for i in range(n):
    s, t, channel = map(int, input().split())
    data[s][channel] += 1
    data[t+1][channel] -= 1
for i in range(c+1):
    for j in range(1,10**5+2):
        data[j][i] += data[j-1][i]
ans = 0
for i in range(10**5+2):
    sum_channel = 0
    for j in range(c+1):
        if data[i][j] == 1:
            sum_channel += 1
    ans = max(ans, sum_channel)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, c = map(int, input().split())
data = [0 for j in range(10**5+1)]
for i in range(n):
    s, t, channel = map(int, input().split())
    data[s] += 1
    data[t+1] -= 1
for i in range(10**5):
    data[i+1] += data[i]
print(max(data))

Fixed submission:
n, c = map(int, input().split())
data = [[0 for i in range(c+1)] for j in range(10**5+2)]
for i in range(n):
    s, t, channel = map(int, input().split())
    data[s][channel] += 1
    data[t+1][channel] -= 1
for i in range(c+1):
    for j in range(1,10**5+2):
        data[j][i] += data[j-1][i]
ans = 0
for i in range(10**5+2):
    sum_channel = 0
    for j in range(c+1):
        if data[i][j] == 1:
            sum_channel += 1
    ans = max(ans, sum_channel)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
def Lucas(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    else
        return Lucas(n - 1) + Lucas(n - 2)
print(Lucas(n))


Fixed submission:
n = int(input())
L = [0 for i in range(100)]
L[0] = 2
L[1] = 1
def Lucas(n):
    if L[n] != 0:
        return L[n]
    else:
        L[n - 1] = Lucas(n - 1)
        L[n - 2] = Lucas(n - 2)
        return L[n - 1] + L[n - 2]
print(Lucas(n))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
#初めから、どこに挿入されるのかを考えておく
A = {}
B = {}
C = {}
for i in range(n):
    B[c[i]] = min(bisect.bisect_left(b, c[i]), n)
    A[b[i]] = min(bisect.bisect_left(a, b[i]), n)
for i in range(n):
    Bindex = B[c[i]]
    for j in range(Bindex):
        Aindex = A[b[j]]
        ans +=  (Aindex)
print(ans)


Fixed submission:
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
#初めから、どこに挿入されるのかを考えておく
Bcount = [0 for i in range(n+1)]
for i in range(1,n+1):
    Bcount[i] = bisect.bisect_left(a, b[i-1]) + Bcount[i - 1]

for i in range(n):
    index = bisect.bisect_left(b,c[i])

    ans += Bcount[index]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(n):
    Bindex = min(bisect.bisect_left(b, c[i]), n)
    for j in range(Bindex):
        Aindex = min(bisect.bisect_left(a, b[j]), n)
        ans +=  (Aindex)
print(ans)


Fixed submission:
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
#初めから、どこに挿入されるのかを考えておく
Bcount = [0 for i in range(n+1)]
for i in range(1,n+1):
    Bcount[i] = bisect.bisect_left(a, b[i-1]) + Bcount[i - 1]

for i in range(n):
    index = bisect.bisect_left(b,c[i])

    ans += Bcount[index]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        if (4 * h * n - N * n - N * h) != 0 and (N * h * n) % (4 * h * n - N * n - N * h) == 0:
            if (N * h * n) // (4 * h * n - N * n - N * h) > 0:
                print("{} {} {}".format(h,n,(N * h * n) // (4 * h * n - N * n - N * h)))
                exit()

Fixed submission:
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        if (4 * h * n - N * n - N * h) != 0 and (N * h * n) % (4 * h * n - N * n - N * h) == 0:
            if (N * h * n) // (4 * h * n - N * n - N * h) > 0:
                print("{} {} {}".format(h,n,(N * h * n) // (4 * h * n - N * n - N * h)))
                exit()
Buggy python submission (verdict: Runtime Error):
import copy
import sys
input = sys.stdin.readline
n,k = map(int, input().split())
data = []
bit_k = format(k, 'b')
len_k = len(bit_k)
for i in range(n):
    a, b = map(int, input().split())
    if a <= k:
        tmp = format(a, 'b')
        tmp = tmp.zfill(len_k)
        data.append([tmp,b])
def check_value(bit):
    res = 0
    for i in range(len(data)):
        flag = True
        dd = data[i][0]
        for j in range(len_k):
            if bit[j] == '0' and dd[j] == '1':
                flag = False
                break
        if flag:
            #print("tmp:{} bit{}".format(tmp, bit))
            res += data[i][1]
    return res
ans = 0
tmp = []
for i in range(len_k):
    p = []
    if bit_k[i] == '1':
        p = tmp + ['0'] + ['1']*(len_k-1-i)
    else:
        continue
    p = "".join(p)
    ans = max(ans, check_value(p))
    tmp += bit_k[i]
print(ans)


Fixed submission:
import copy
import sys
input = sys.stdin.readline
n,k = map(int, input().split())
data = []
bit_k = format(k, 'b')
len_k = len(bit_k)
for i in range(n):
    a, b = map(int, input().split())
    if a <= k:
        tmp = format(a, 'b')
        tmp = tmp.zfill(len_k)
        data.append([tmp,b])
def check_value(bit):
    res = 0
    for i in range(len(data)):
        flag = True
        dd = data[i][0]
        for j in range(len_k):
            if bit[j] == '0' and dd[j] == '1':
                flag = False
                break
        if flag:
            #print("tmp:{} bit{}".format(tmp, bit))
            res += data[i][1]
    return res
ans = check_value(bit_k)
tmp = []
for i in range(len_k):
    p = []
    if bit_k[i] == '1':
        p = tmp + ['0'] + ['1']*(len_k-1-i)
    else:
        tmp += bit_k[i]
        continue
    p = "".join(p)
    ans = max(ans, check_value(p))
    tmp += bit_k[i]
print(ans)