Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, p = map(int, input().split())
if n == 1:
    print(p)
else:
    ans = 1
    for i in range(1, 10**6+1):
        if pow(i, n) > p:
            break

        if p % pow(i, n) == 0:
            ans = i
    print(ans)


Fixed submission:
n, p = map(int, input().split())
if n == 1:
    print(p)
else:
    ans = 1
    for i in range(1, 10**6+1):
        if pow(i, n, 10**20) > p:
            break

        if p % pow(i, n, 10**20) == 0:
            ans = i
    print(ans)

Buggy python submission (verdict: Runtime Error):
n, p = map(int, input().split())
if n == 1:
    print(p)
else:
    ans = 1
    for i in range(1, 10**6+1):
        if pow(i, n) > p:
            break

        if P % pow(i, n) == 0:
            ans = i
    print(ans)


Fixed submission:
n, p = map(int, input().split())
if n == 1:
    print(p)
else:
    ans = 1
    for i in range(1, 10**6+1):
        if pow(i, n, 10**20) > p:
            break

        if p % pow(i, n, 10**20) == 0:
            ans = i
    print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = []
for i in range(N):

  a.append(int(input())
           
print(sum(a)-max(a)//2)
     

Fixed submission:
N = int(input())
a = []
for i in range(N):

  a.append(int(input()))
           
print(sum(a)-max(a)//2)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
tree = []
for i in range(N):
  tree.append(int(input()))
tree.sort()
mini = 1000000000
for i in range(N-K+1):
  mini = min(mini, tree[i+K-1]-[i])
print(mini)
  

Fixed submission:
N, K = map(int, input().split())
tree = []
for i in range(N):
  tree.append(int(input()))
tree.sort()
mini = 1000000000
for i in range(N-K+1):
  mini = min(mini, tree[i+K-1]-tree[i])
print(mini)
Buggy python submission (verdict: Runtime Error):
H, W, K = map(int, input().split())
dp = [[0 for i in range(W)] for j in range(H+1)]
mod = 10**9+7
dp[0][0] = 1

for k in range(H):
    for i in range(2**(W-1)):
        b = format(i, "0{}b".format(W-1))
        flag = 1
        for j in range(len(b)-1):
            if b[j+1] == "1" and b[j] == "1":
                flag = 0
                break
        if flag == 0:
            continue

        for j in range(len(b)):
            if flag == 0:
                flag = 1
                continue
            if b[j] == "1":
                dp[k+1][j+1] += dp[k][j]
                dp[k+1][j] += dp[k][j+1]
                dp[k+1][j+1] %= mod
                dp[k+1][j] %= mod
                flag = 0
            else:
                dp[k+1][j] += dp[k][j]
                dp[k+1][j] %= mod
                if j == len(b)-1:
                    dp[k+1][j+1] += dp[k][j+1]
                    dp[k+1][j+1] %= mod
                  
print(dp[H][K-1])


Fixed submission:
H, W, K = map(int, input().split())
dp = [[0 for i in range(W)] for j in range(H+1)]
mod = 10**9+7
dp[0][0] = 1

if W == 1:
    print(1)
else:
    for k in range(H):
        for i in range(2**(W-1)):
            b = format(i, "0{}b".format(W-1))
            flag = 1
            for j in range(len(b)-1):
                if b[j+1] == "1" and b[j] == "1":
                    flag = 0
                    break
            if flag == 0:
                continue

            for j in range(len(b)):
                if flag == 0:
                    flag = 1
                    continue
                if b[j] == "1":
                    dp[k+1][j+1] += dp[k][j]
                    dp[k+1][j] += dp[k][j+1]
                    dp[k+1][j+1] %= mod
                    dp[k+1][j] %= mod
                    flag = 0
                else:
                    dp[k+1][j] += dp[k][j]
                    dp[k+1][j] %= mod
            if b[-1] == "0":
                dp[k+1][-1] += dp[k][-1]
                dp[k+1][-1] %= mod
    print(dp[H][K-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for i in range(N)]

a.sort()
i = 0
j = N-1
if N <= 2:
    print(abs(a[0] - a[1]))
else:
    ans = a[j] - a[0] + a[j] - a[1]
    i = 0
    j = N-2
    while i < j:
        ans += a[j] - a[i]
        i += 1
        j -= 1
    else:
        if i == j:
            if N // 2 % 2 == 1:
                ans += max(abs(a[j+2]-a[j]), abs(a[j+1]-a[j]))
            else:
                ans += max(abs(a[j]-a[j-1]), abs(a[j]-a[j-2]))
    i = 1
    j = N-1
    ans1 = a[j] - a[0] + a[j-1] - a[0]
    while i < j:
        ans1 += a[j] - a[i]
        i += 1
        j -= 1
    else:
        if i == j:
            if N // 2 % 2 == 0:
                ans1 += max(abs(a[j+2]-a[j]), abs(a[j+1]-a[j]))
            else:
                ans1 += max(abs(a[j]-a[j-1]), abs(a[j]-a[j-2]))
    print(max(ans, ans1))


Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

a.sort(reverse = True)


keisuu = [0]*n
for i in range(n-1):
    if i % 2 == 0:
        keisuu[i] += 1
        keisuu[i+1] -= 1
    else:
        keisuu[i] -= 1
        keisuu[i+1] += 1
ans = 0
keisuu.sort(reverse = True)
for i in range(n):
    ans += a[i] * keisuu[i]


keisuu = [0]*n
for i in range(n-1):
    if i % 2 == 1:
        keisuu[i] += 1
        keisuu[i+1] -= 1
    else:
        keisuu[i] -= 1
        keisuu[i+1] += 1
keisuu.sort(reverse = True)
ans1 = 0
for i in range(n):
    ans1 += a[i] * keisuu[i]

print(max(ans, ans1))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
x = []
y = []
h = []
for i in range(N):
    x_i, y_i, h_i = map(int, input().split())
    x.append(x_i)
    y.append(y_i)
    h.append(h_i)

#i:情報番号 j:求めるx座標 k:求めるy座標 l:求める高さ
for j in range(101):
    for k in range(101):
        for l in range(h[0] - 200, h[0] + 200):
            flag = 1
            for i in range(N):
                h_i_test = max(l - abs(x[i] - j) - abs(y[i] - k), 0)
                if h_i_test != h[i]:
                    flag = 0
            if flag == 1:
                print(str(j)+ " " + str(k) + " " + str(l))


Fixed submission:
N = int(input())
x = []
y = []
h = []
for i in range(N):
    x_i, y_i, h_i = map(int, input().split())
    x.append(x_i)
    y.append(y_i)
    h.append(h_i)

#i:情報番号 j:求めるx座標 k:求めるy座標 l:求める高さ
for j in range(101):
    for k in range(101):
        for l in range(h[0], h[0] + 200):
            flag = 1
            for i in range(N):
                h_i_test = max(l - abs(x[i] - j) - abs(y[i] - k), 0)
                if h_i_test != h[i]:
                    flag = 0
                    break
            if flag == 1:
                print(str(j)+ " " + str(k) + " " + str(l))
                break
        if flag == 1:
            break
    if flag == 1:
        break
Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))
a.sort(reversed = True)
print(int(a[0])*10+a[1]+a[2])


Fixed submission:
a = list(map(int, input().split()))
a.sort(reverse = True)
print(int(a[0])*10+a[1]+a[2])

Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))
a.sort(reversed = True)
print(a[0]*10+a[1]+a[2])


Fixed submission:
a = list(map(int, input().split()))
a.sort(reverse = True)
print(int(a[0])*10+a[1]+a[2])
Buggy python submission (verdict: Runtime Error):
N = int(input())
used = [input()]
flag = 1
for i in range(N-1):
  now = input()
  if now not in used and used[-1][-1] == now[0]:
    used.append(now)
  else:
    flag = 0
   	break
if flag == 1:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
used = [input()]
flag = 1
for i in range(N-1):
  now = input()
  if now not in used and used[-1][-1] == now[0]:
    used.append(now)
  else:
      flag = 0

if flag == 1:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M, Q = map(int, input().split())
ans = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
    l, r = map(int, input().split())
    ans[l][r] += 1

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

for _ in range(Q):
    l, r = map(int, input().split())
    res = 0
    for i in range(l, r+1):
        res += ans[i][r]
    print(res)


Fixed submission:
import sys
input = sys.stdin.readline

N, M, Q = map(int, input().split())
ans = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
    l, r = map(int, input().split())
    ans[l][r] += 1

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

for _ in range(Q):
    l, r = map(int, input().split())
    res = 0
    for i in range(l, r+1):
        res += ans[i][r]
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

dp = [[0 for j in range(4)] for i in range(len(s)+1)]
dp[0][0] = 1
mod = 10**9+7
for i in range(len(s)):
    for j in range(4):
        dp[i+1][j] = dp[i][j]
        dp[i+1][j] %= mod
    if s[i] == "A":
        dp[i+1][1] += dp[i][0]
    elif s[i] == "B":
        dp[i+1][2] += dp[i][1]
    elif s[i] == "C":
        dp[i+1][3] += dp[i][2]
    else:
        dp[i+1][0] += dp[i][0] * 2
        dp[i+1][1] += dp[i][1] * 2 + dp[i][0]
        dp[i+1][2] += dp[i][2] * 2 + dp[i][1]
        dp[i+1][3] += dp[i][3] * 2 + dp[i][2]

print(dp[-1][3]%mod)


Fixed submission:
s = input()

dp = [[0 for j in range(4)] for i in range(len(s)+1)]
dp[0][0] = 1
mod = 10**9+7
for i in range(len(s)):
    for j in range(4):
        dp[i+1][j] = dp[i][j]
        dp[i+1][j] %= mod
        dp[i][j] %= mod
    if s[i] == "A":
        dp[i+1][1] += dp[i][0]
    elif s[i] == "B":
        dp[i+1][2] += dp[i][1]
    elif s[i] == "C":
        dp[i+1][3] += dp[i][2]
    else:
        dp[i+1][0] += dp[i][0] * 2
        dp[i+1][1] += dp[i][1] * 2 + dp[i][0]
        dp[i+1][2] += dp[i][2] * 2 + dp[i][1]
        dp[i+1][3] += dp[i][3] * 2 + dp[i][2]

print(dp[-1][3]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()

dp = [[0 for j in range(4)] for i in range(len(s)+1)]
dp[0][0] = 1
mod = 10**9+7
for i in range(len(s)):
    for j in range(4):
        dp[i+1][j] = dp[i][j]
        dp[i+1][j] %= mod
    if s[i] == "A":
        dp[i+1][1] += dp[i][0]
    elif s[i] == "B":
        dp[i+1][2] += dp[i][1]
    elif s[i] == "C":
        dp[i+1][3] += dp[i][2]
    else:
        dp[i+1][0] += dp[i][0] * 2
        dp[i+1][1] += dp[i][1] * 2 + dp[i][0]
        dp[i+1][2] += dp[i][2] * 2 + dp[i][1]
        dp[i+1][3] += dp[i][3] * 2 + dp[i][2]

print(dp[-1][3]%mod)


Fixed submission:
s = input()

dp = [[0 for j in range(4)] for i in range(len(s)+1)]
dp[0][0] = 1
mod = 10**9+7
for i in range(len(s)):
    for j in range(4):
        dp[i+1][j] = dp[i][j]
        dp[i+1][j] %= mod
        dp[i][j] %= mod
    if s[i] == "A":
        dp[i+1][1] += dp[i][0]
    elif s[i] == "B":
        dp[i+1][2] += dp[i][1]
    elif s[i] == "C":
        dp[i+1][3] += dp[i][2]
    else:
        dp[i+1][0] += dp[i][0] * 2
        dp[i+1][1] += dp[i][1] * 2 + dp[i][0]
        dp[i+1][2] += dp[i][2] * 2 + dp[i][1]
        dp[i+1][3] += dp[i][3] * 2 + dp[i][2]

print(dp[-1][3]%mod)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
now = 0
ans = 0
for i in range(N):
  if a[i] == now:
    count += 1
  else:
    ans += count//2
    count = 1
    now = a[i]

ans += count//2
print(ans)

Fixed submission:

N = int(input())
a = list(map(int, input().split()))
count = 0
now = 0
ans = 0
for i in range(N):
  if a[i] == now:
    count += 1
  else:
    ans += count//2
    count = 1
    now = a[i]

ans += count//2
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
now = ''
ans = 0
for i in range(N):
  if a[i] == now:
    count += 1
  else:
    ans += count//2
    count = 1
    now = a[i]

ans += count//2
print(ans)

Fixed submission:

N = int(input())
a = list(map(int, input().split()))
count = 0
now = 0
ans = 0
for i in range(N):
  if a[i] == now:
    count += 1
  else:
    ans += count//2
    count = 1
    now = a[i]

ans += count//2
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
w = int(input())
ans = ''
count = 0
while count <= len(s):
  ans += s[count]
  count += w
print(ans)

Fixed submission:
s = input()
w = int(input())
ans = ''
count = 0
while count <= len(s)-1:
  ans += s[count]
  count += w
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
p = list(map(int, input().split()))
par = [i for i in range(N+1)]
rank = [0] * (N+1)
def find(x):
    if par[x] == x:
        return x
    else:
        #親を検索
        par[x] = find(par[x])
        return par[x]

def same_checker(x, y):
    return find(x) == find(y)

def union(x, y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

for i in range(M):
    x, y = map(int, input().split())
    union(x, y)
    print(par)
S = {}
for i in range(N):
    S[p[i]] = par[i+1]
ans = 0
for i in range(N):
    if same_checker(S[p[i]], S[i+1]):
        ans += 1

print(ans)

Fixed submission:
N, M = map(int, input().split())
p = list(map(int, input().split()))
par = [i for i in range(N+1)]
rank = [0] * (N+1)
def find(x):
    if par[x] == x:
        return x
    else:
        #親を検索
        par[x] = find(par[x])
        return par[x]

def same_checker(x, y):
    return find(x) == find(y)

def union(x, y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

for i in range(M):
    x, y = map(int, input().split())
    union(x, y)
S = {}
for i in range(N):
    S[p[i]] = par[i+1]
ans = 0
for i in range(N):
    if same_checker(S[p[i]], S[i+1]):
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()

index = bisect.bisect_right(a, a[-1]/2)

if abs(a[-1]/2 - a[index]) > abs(a[-1]/2 - a[index+1]) and n > 2:
    index += 1
print(a[-1], a[index])


Fixed submission:
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()

maxi = a[-1]
mini = 1000000001
for i in range(n-1):
    if abs(maxi/2 - a[i]) < mini:
        minindex = i
        mini = abs(maxi/2 - a[i])
print(maxi, a[minindex])

Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

index = bisect.bisect_right(a, a[-1]//2)

if cmb(a[-1], a[index]) < cmb(a[-1], a[index+1]):
    index += 1
print(a[-1], a[index])


Fixed submission:
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()

maxi = a[-1]
mini = 1000000001
for i in range(n-1):
    if abs(maxi/2 - a[i]) < mini:
        minindex = i
        mini = abs(maxi/2 - a[i])
print(maxi, a[minindex])
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
ans = []
for i in range(50):
    ans.append(["."] * 100)
for i in range(50):
    ans.append(["#"] * 100)

i = 0
b -= 1
while b > 0:
    for j in range(0, 100, 2):
        ans[i][j] = "#"
        b -= 1
        if b == 0:
            break
    i += 2

i = 60
a -= 1
while a > 0:
    for j in range(0, 100, 2):
        ans[i][j] = "."
        a -= 1
        if a == 0:
            break
    i += 2
print(100, 100)
for i in range(100):
    print("".join(ans[i]))


Fixed submission:
a, b = map(int, input().split())
ans = []
for i in range(50):
    ans.append(["."] * 100)
for i in range(50):
    ans.append(["#"] * 100)

i = 0
b -= 1
while b > 0:
    for j in range(0, 100, 2):
        ans[i][j] = "#"
        b -= 1
        if b == 0:
            break
    i += 2

i = 60
a -= 1
while a > 0:
    for j in range(0, 100, 2):
        ans[i][j] = "."
        a -= 1
        if a == 0:
            break
    i += 2
print(100, 100)
for i in range(100):
    print("".join(ans[i]))
Buggy python submission (verdict: Runtime Error):
c = []
for i in range(3):
  c.append(list(map(int, input()split())))
diff = c[1][2] - c[2][2]
c[1][1] -= diff
c[1][0] -= diff

diff = c[0][2] - c[2][2]
c[0][1] -= diff
c[0][0] -= diff

if c[1][1] == c[2][1] and c[0][1] == c[2][1] and c[1][0] == c[2][0] and c[1][0] == c[0][0]:
  print('Yes')
else:
  print('No')
  


Fixed submission:
c = []
for i in range(3):
  c.append(list(map(int, input().split())))
diff = c[1][2] - c[2][2]
c[1][1] -= diff
c[1][0] -= diff

diff = c[0][2] - c[2][2]
c[0][1] -= diff
c[0][0] -= diff

if c[1][1] == c[2][1] and c[0][1] == c[2][1] and c[1][0] == c[2][0] and c[1][0] == c[0][0]:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
c = []
for i in range(3):
  c.append(list(map(int, input()split())))
diff = c[1][2] - c[2][2]
c[1][1] -= diff
c[1][3] -= diff

diff = c[3][2] - c[2][2]
c[3][1] -= diff
c[3][3] -= diff

if c[1][1] == c[2][1] and c[3][1] == c[2][1] and c[1][3] == c[2][3] and c[1][3] == c[3][3]:
  print('Yes')
else:
  print('No')
  


Fixed submission:
c = []
for i in range(3):
  c.append(list(map(int, input().split())))
diff = c[1][2] - c[2][2]
c[1][1] -= diff
c[1][0] -= diff

diff = c[0][2] - c[2][2]
c[0][1] -= diff
c[0][0] -= diff

if c[1][1] == c[2][1] and c[0][1] == c[2][1] and c[1][0] == c[2][0] and c[1][0] == c[0][0]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
grid = []
for i in range(H):
    grid.append(input())

visit = [[False for j in range(W)] for i in range(H)]


queue = [[0,0]]
count = 0
while len(queue) > 0:
    count += 1
    next = []
    for now in queue:
        visit[now[0]][now[1]] = True
        for i, j in [[0,-1], [1,0], [0,1], [-1,0]]:
            if 0 <= now[0]+i <= H-1 and 0 <= now[1]+j <= W-1:
                if not visit[now[0]+i][now[1]+j]:
                    if grid[now[0]+i][now[1]+j] == ".":
                        next.append([now[0]+i, now[1]+j])
    if visit[-1][-1]:
        break
    queue = list(set(next[:]))


black = count
for i in range(H):
    black += grid[i].count("#")

if visit[-1][-1]:
    print(H*W-black)
else:
    print(-1)


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

visit = [[False for j in range(W)] for i in range(H)]


queue = [[0,0]]
count = 0
while len(queue) > 0:
    count += 1
    next = []
    for now in queue:
        visit[now[0]][now[1]] = True
        for i, j in [[0,-1], [1,0], [0,1], [-1,0]]:
            if 0 <= now[0]+i <= H-1 and 0 <= now[1]+j <= W-1:
                if [now[0]+i,now[1]+j] not in next and not visit[now[0]+i][now[1]+j] and grid[now[0]+i][now[1]+j] == ".":
                    next.append([now[0]+i, now[1]+j])

    if visit[-1][-1]:
        break
    queue = next[:]


black = count
for i in range(H):
    black += grid[i].count("#")

if visit[-1][-1]:
    print(H*W-black)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

def judge(a, b):
    product = a * b
    if product % 2 == 0:
        return Even
    elif product % 2 == 1:
        return Odd
    break

print(judge(a, b))


Fixed submission:
a, b = map(int, input().split())

def judge(a, b):
    product = a * b
    if product % 2 == 0:
        return "Even"
    elif product % 2 == 1:
        return "Odd"

print(judge(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
a = list(map(int, input().split()))

l = -1
r = 10**18
while r - l > 1:
    m = l + (r-l)//2
    n = m
    for i in range(k):
        n = n//a[i] * a[i]
    if n >= 2:
        r = m
    else:
        l = m

ansl = r
l = -1
r = 10**18
while r - l > 1:
    m = l + (r-l)//2
    n = m
    for i in range(k):
        n = n//a[i] * a[i]
    if n <= 2:
        l = m
    else:
        r = m

ansr = l

if ansl <= ansr:
    print(ansl, ansr)
else:
    print(-1)


Fixed submission:
k = int(input())
a = list(map(int, input().split()))

l = -1
r = 10**18
while r - l > 1:
    m = l + (r-l)//2
    n = m
    for i in range(k):
        n = n//a[i] * a[i]
    if n >= 2:
        r = m
    else:
        l = m

ansl = r
l = -1
r = 10**18
while r - l > 1:
    m = l + (r-l)//2
    n = m
    for i in range(k):
        n = n//a[i] * a[i]
    if n <= 2:
        l = m
    else:
        r = m

ansr = l

if ansl <= ansr:
    print(ansl, ansr)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter
N, H = map(int, input().split())
ab = []
for i in range(N):
    n, m = map(int, input().split())
    ab.append([n, m])

max_count = 0
ab = sorted(ab, key = lambda x:(-x[1], x[0]))
a_max = max(a)
for i in range(N):
    if a[i] == a_max:
        max_count += 1
print(ab)
ans = 0
for i in range(N):
    if H <= 0:
        break
    if H <= ab[0][1] or H <= a_max:
        ans += 1
        break
    if a_max < ab[0][1]:
        if ab[0][0] == a_max:
            if max_count > 1:
                max_count -= 1
                H -= ab.pop(0)[1]
                ans += 1
            else:
                H -= ab[0][1]
                ans += 1
                if H <= 0:
                    break
                else:
                    ans += 1 + (H-1) // ab[0][0]
                    break
        else:
            H -= ab.pop(0)[1]
            ans += 1
    else:
        ans += 1 + (H-1) // a_max
print(ans)


Fixed submission:
from operator import itemgetter
N, H = map(int, input().split())
b = []
a = []
for i in range(N):
    n, m = map(int, input().split())
    b.append(m)
    a.append(n)
a_max = max(a)
ans = 0
b.sort(reverse = True)
for i in range(N):
    if H <= b[i] or H <= a_max:
        ans += 1
        break
    if b[i] >= a_max:
        H -= b[i]
        ans += 1
        if i == N-1:
            ans += 1 + ((H-1) // a_max)

    else:
        ans += 1 + ((H-1) // a_max)
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
Q = int(input())
numberlist = [0 for i in range(100001)]
prime = [2]

for i in range(3, 100001, 2):
    flag = 1
    for j in prime:
        if i % j == 0:
            flag = 0
            break
    if flag == 1:
        prime.append(i)

for i in prime:
    if (i+1)//2 in prime:
        numberlist[i] += 1
for i in range(100000):
    numberlist[i+1] += numberlist[i]


for i in range(Q):
    l, r = map(int, input().split())
    print(numberlist[r]-numberlist[l-1])


Fixed submission:
Q = int(input())
numberlist = [0 for i in range(100001)]
prime = [2]

for i in range(3, 100001, 2):
    flag = 1
    for j in prime:
        if i % j == 0:
            flag = 0
            break
    if flag == 1:
        prime.append(i)

for i in prime:
    if (i+1)//2 in prime:
        numberlist[i] += 1
for i in range(100000):
    numberlist[i+1] += numberlist[i]


for i in range(Q):
    l, r = map(int, input().split())
    print(numberlist[r]-numberlist[l-1])