Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import copy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():

    N = I()
    XY = LLIN(N)
    XY.sort()
    if N == 1:
        print(1)
        exit()
    
    count = defaultdict(int)
    for i, (x1, y1) in enumerate(XY):
        for j, (x2, y2) in enumerate(XY[i+1:]):
            dx, dy = x1 - x2, y1 - y2
            count[(dx, dy)] += 1
    print(N - max(count.values()))
    
    
                        
if __name__ == '__main__':
    main()

Fixed submission:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, K = MI()
    if K == 1:
        print(0)
    else:
        print(N-K)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    from collections import deque
    input = sys.stdin.readline
    N = int(input())
    color = [-1] * N
    color[0] = 0
    uvw = []
    edge = [[]for _ in range(N)]
    # append=uvw.append
    for i in range(N-1):
        ui, vi, wi = map(int, input().split())
        ui -= 1
        vi -= 1
        edge[ui].append((vi, wi))
        edge[vi].append((ui, wi))
    stack = [0]
    for i in range(N):
        tmp = deque()
        while stack:
            i = stack.pop()
            for e, w in edge[i]:
                if color[e] == -1:
                    stack.append(e)
                    if color[i] == 0:
                        if w % 2 == 0:
                            color[e] = 0
                        else:
                            color[e] = 1
                    else:
                        if w % 2 == 0:
                            color[e] = 1
                        else:
                            color[e] = 0
                # ここを追加--------------------------------------
                # 矛盾判定
                else:
                    if (color[i] == color[e]) != (w % 2 == 0):
                        print(-1)
                        exit()
                # ^^^^^^^^--------------------------------------
        # print(color)
        stack = tmp
    print(*color, sep="\n")


if __name__ == '__main__':
    main()


Fixed submission:
N, K = map(int, input().split())
S = list(input())
K -= 1
if S[K] == "A":
    S[K] = "a"
elif S[K] == "B":
    S[K] = "b"
elif S[K] == "C":
    S[K] = "c"


print("".join(S))
Buggy python submission (verdict: Runtime Error):
from math import log2, ceil
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    percent = (1 / 2)**(log2(ceil(K / i)))
    ans += percent
print(ans/N)


Fixed submission:
N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    percent = 1
    point = i
    while K > point:
        percent /= 2
        point *= 2
    ans += percent
print(ans/N)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
ans=0
for i in range(1,int(math.sqrt(N)+1)):
    if N//(N//i-1)!=N%((N//i-1)):
        continue
    else:
        #print(i,N//i-1,N//(N//i-1),N%((N//i-1)))
        ans+=N//i-1
print(ans)


Fixed submission:
import math
N = int(input())
ans=0
for i in range(1,int(math.sqrt(N)+1)):
    if i==N:
        continue
    if N//(N//i-1)!=N%((N//i-1)):
        continue
    else:
        #print(i,N//i-1,N//(N//i-1),N%((N//i-1)))
        ans+=N//i-1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def dp_table(*counts):  # dp[x][y]を作りたかったら dp_table(xのサイズ,yのサイズ)
    if counts:
        return [dp_table(*counts[1:]) for _ in range(counts[0])]
    else:
        return 0


def main():

    N = int(input())
    A = [int(input()) for _ in range(N)]
    mod = 998244353
    ans = pow(3, N, mod)
    sum_A = sum(A)
    dp = [[0] * (sum_A+1) for i in range(N)]
    # dp[i][j]: i番目までの中から辺をいくつか選んで、長さがjになるパターン数

    # init
    dp[0][A[0]] = 1
    dp[0][0] = 2  # 他の色のうちどちらに入れるかで2通り

    # init2
    dp2 = [[0] * (sum_A+1) for i in range(N)]  # ある二色でsum_Aを等分するパターンを数える
    dp2[0][A[0]] = 1
    dp2[0][0] = 1  # 今度は片方に集中したパターン

    # dp
    sum_now = A[0]
    for i in range(1, N):
        a = A[i]
        sum_now += a
        for length in range(sum_now+1):
            # A[i]を追加しないのなら他の２食のうちどちらに入れるかで2倍選択肢がある
            if length >= a:
                dp[i][length] = dp[i - 1][length - a] + \
                    (dp[i - 1][length] << 1)
            else:
                dp[i][length] = dp[i-1][length] << 1
            dp[i][length] %= mod

        for length in range(min(sum_now + 1, sum_A // 2 + 1)):
            if length >= a:
                dp2[i][length] = dp2[i - 1][length - a] + dp2[i - 1][length]
            else:
                dp2[i][length] = dp2[i-1][length]
            dp2[i][length] %= mod
    # print(sum(dp[N-1][sum_A//2]))
    # print(dp)
    ans -= 3*sum(dp[N-1][(sum_A+1)//2:])
    if sum_A % 2 == 0:
        ans += 3*dp2[N-1][sum_A//2]
    print(ans % mod)


if __name__ == '__main__':
    main()


Fixed submission:
def dp_table(*counts):  # dp[x][y]を作りたかったら dp_table(xのサイズ,yのサイズ)
    if counts:
        return [dp_table(*counts[1:]) for _ in range(counts[0])]
    else:
        return 0


def main():

    N = int(input())
    A = [int(input()) for _ in range(N)]
    mod = 998244353
    ans = pow(3, N, mod)
    sum_A = sum(A)
    dp = [[0] * (sum_A+1) for i in range(N)]
    # dp[i][j]: i番目までの中から辺をいくつか選んで、長さがjになるパターン数

    # init
    dp[0][A[0]] = 1
    dp[0][0] = 2  # 他の色のうちどちらに入れるかで2通り

    # init2
    dp2 = [[0] * (sum_A+1) for i in range(N)]  # ある二色でsum_Aを等分するパターンを数える
    dp2[0][A[0]] = 1
    dp2[0][0] = 1  # 今度は片方に集中したパターン

    # dp
    sum_now = A[0]
    for i in range(1, N):
        a = A[i]
        sum_now += a
        for length in range(sum_now+1):
            # A[i]を追加しないのなら他の２食のうちどちらに入れるかで2倍選択肢がある
            if length >= a:
                dp[i][length] = dp[i - 1][length - a] + \
                    (dp[i - 1][length] << 1)
            else:
                dp[i][length] = dp[i-1][length] << 1
            dp[i][length] %= mod

        for length in range(min(sum_now + 1, sum_A // 2 + 1)):
            if length >= a:
                dp2[i][length] = dp2[i - 1][length - a] + dp2[i - 1][length]
            else:
                dp2[i][length] = dp2[i-1][length]
            dp2[i][length] %= mod
    # print(sum(dp[N-1][sum_A//2]))
    # print(dp)
    ans -= 3*sum(dp[N-1][(sum_A+1)//2:])
    if sum_A % 2 == 0:
        ans += 3*dp2[N-1][sum_A//2]
    print(ans % mod)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
minians = []
for i in range(N-1):
    if S[i:i + 2] == "AC":
        minians.append(i)
# print(minians)
ans = [0]*Q
for i in range(Q):
    left, right = map(int, input().split())
    left -= 1
    right -= 1
    ans[i] = sum(left <= mini < right for mini in minians)
    """for j in range(len(minians)):
        if left <= minians[j] and minians[j] < right:
            ans[i] += 1
        elif minians[j] >= right:
            break"""
print('\n'.join(map(str, ans)))


Fixed submission:
import bisect
N, Q = map(int, input().split())
S = input()
minians = []
for i in range(N-1):
    if S[i:i + 2] == "AC":
        minians.append(i)
# print(minians)
ans = [0]*Q
for i in range(Q):
    left, right = map(int, input().split())
    left -= 1
    right -= 1
    """print("\n", bisect.bisect_left(minians, right),
          bisect.bisect_left(minians, left))"""
    ans[i] = bisect.bisect_left(minians, right) - \
        bisect.bisect_left(minians, left)

    #ans[i] = sum(left <= mini < right for mini in minians)
    """for j in range(len(minians)):
        if left <= minians[j] and minians[j] < right:
            ans[i] += 1
        elif minians[j] >= right:
            break"""
print('\n'.join(map(str, ans)))

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
minians = []
for i in range(N-1):
    if S[i:i + 2] == "AC":
        minians.append(i)
# print(minians)
ans = [0]*Q
for i in range(Q):
    left, right = map(int, input().split())
    left -= 1
    right -= 1
    for j in range(len(minians)):
        if left <= minians[j] and minians[j] < right:
            ans[i] += 1
        elif minians[j] >= right:
            break
print('\n'.join(map(str, ans)))


Fixed submission:
import bisect
N, Q = map(int, input().split())
S = input()
minians = []
for i in range(N-1):
    if S[i:i + 2] == "AC":
        minians.append(i)
# print(minians)
ans = [0]*Q
for i in range(Q):
    left, right = map(int, input().split())
    left -= 1
    right -= 1
    """print("\n", bisect.bisect_left(minians, right),
          bisect.bisect_left(minians, left))"""
    ans[i] = bisect.bisect_left(minians, right) - \
        bisect.bisect_left(minians, left)

    #ans[i] = sum(left <= mini < right for mini in minians)
    """for j in range(len(minians)):
        if left <= minians[j] and minians[j] < right:
            ans[i] += 1
        elif minians[j] >= right:
            break"""
print('\n'.join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())
ans = 0
for i in range(B - A + 1):
    ans = A + i ^ ans
print(int(ans))


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

# 0~B → b
# 0~A-1 → a
# A~B → c　とすると
# a^c = b
#c = a^b (両辺^a)
# 0から並べると、4個置きにXORの累積が0になる
B_ans = 0
for i in range(B % 4+1):
    B_ans = B_ans ^ (B - i)
    # print(bin(B-i))
A_ans = 0
for i in range((A - 1) % 4 + 1):
    # print(bin(A-i))
    A_ans = A_ans ^ (A-1 - i)
#print(A_ans, B_ans)
print(A_ans ^ B_ans)

Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())
ans = 0
for i in range(B - A + 1):
    ans = A + i ^ ans
print(int(ans))


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

# 0~B → b
# 0~A-1 → a
# A~B → c　とすると
# a^c = b
#c = a^b (両辺^a)
# 0から並べると、4個置きにXORの累積が0になる
B_ans = 0
for i in range(B % 4+1):
    B_ans = B_ans ^ (B - i)
    # print(bin(B-i))
A_ans = 0
for i in range((A - 1) % 4 + 1):
    # print(bin(A-i))
    A_ans = A_ans ^ (A-1 - i)
#print(A_ans, B_ans)
print(A_ans ^ B_ans)
Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
if math.gcd(A, B) == A:
    print(A + B)
else:
    print(B-A)


Fixed submission:
from fractions import gcd
A, B = map(int, input().split())
if gcd(A, B) == A:
    print(A + B)
else:
    print(B-A)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
N=int(input())
list=[int(i) for i in input().split()]
print(gcd(list))

Fixed submission:
from fractions import gcd
N = int(input())
list = [int(i) for i in input().split()]
gcd1 = list[0]
for i in list:
    gcd1 = gcd(i, gcd1)
print(gcd1)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

# print(math.log2(10**12))
sum = [0 for i in range(K)]

for x in range(K):
    y = [int(x / (2 ** i)) % 2 for i in range(40)]  # log2(10**12) < 40
    for n in range(N):
        for j in range(40):
            z = int(A[n] / (2 ** j)) % 2
            if (z > 0) ^ (y[j] > 0):
                sum[x] += 2 ** j
print(max(sum))


Fixed submission:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
max_bit = 40
dp = [[-1] * 2 for i in range(41)]  # dp[i][j] = 上からi bitまで、j smaller

dp[0][0] = 0
for d in range(max_bit):
    mask = 1 << (max_bit-d-1)

    # Aでもともとd bit目にbitが立っているものの個数
    num = len([1 for i in range(N) if A[i] & mask])
    #print([1 for i in range(N) if A[i] & mask])

    # Xのbit bit目を0,1にしたときのコスト
    cost0 = mask * num
    cost1 = mask * (N - num)
    # smaller -> smaller
    if dp[d][1] != -1:
        # 0でも1でもいい！
        dp[d + 1][1] = max(dp[d + 1][1], dp[d][1] + max(cost0, cost1))

    # exact -> smaller
    if dp[d][0] != -1:
        if K & mask:  # kのd桁目が1だったらXのd桁目は0にする
            dp[d + 1][1] = max(dp[d + 1][1], dp[d][0] + cost0)

    # exact -> exact
    if dp[d][0] != -1:
        if K & mask:
            dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + cost1)
        else:
            dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + cost0)

# print(dp)
print(max(dp[max_bit][0], dp[max_bit][1]))
Buggy python submission (verdict: Time Limit Exceeded):
N = list(input())
stack = []
count = 0
while N:
    stack.append(N.pop(0))
    i = 0
    while len(stack) >= 2:
        #print(stack, i)
        if stack[-2 - i] != stack[-1 - i]:
            count += 1
            tmp = stack[-2 - i]
            stack[-2 - i] = stack[-1 - i]
            stack[-1 - i] = tmp
            i += 1
            if i == len(stack)-1:
                break
        else:
            break
print(count)

Fixed submission:
N = list(input())
b_n = N.count("B")
point = 0
for i in range(len(N)):
    if N[i] == "B":
        point += i
future_point = (b_n * (len(N) - 1 - b_n + 1 + len(N) - 1)) // 2
print(future_point - point)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
x = X
nums = [1]
p_count = [1]
for i in range(N):
    nums.append(2 * nums[-1] + 3)
    p_count.append(2 * p_count[-1] + 1)


def solve_p(N, X):
    if X <= 1:
        return 0
    elif N == 0:
        return 1
    else:
        if X == (nums[N]) // 2:
            return (p_count[N]+1) // 2
        elif X < nums[N] // 2:
            return solve_p(N - 1, X - 1)
        else:
            return p_count[N-1]+1+solve_p(N-1, X-(nums[N]+1)//2)


print(solve_p(N, X))
"""
ans = 0
for i, n in enumerate(nums[:-1]):
    if X == n:
        ans += p_count[i]
        break
    elif X > n // 2:
        X -= p_count[i]//2
        ans += p_count[i] // 2
    elif X == n // 2:
        ans += (p_count[i] + 1) // 2
        break
# print(ans)

burger = ["P"]
for i in range(N):
    burger.append(("B"+burger[i]+"P"+burger[i]+"B"))
print(burger)  # [N + 1])

print(burger[N])

print(burger[N][:x].count("P"))
"""


Fixed submission:
D = int(input())
output = "Christmas"
while D < 25:
    output = output + " Eve"
    D += 1
print(output)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())

burger = ["P"]
for i in range(1, N+1):
    burger.append("B"+burger[i-1]+"P"+burger[i-1]+"B")
#print(burger[N])
print(burger[N][0:X].count("P"))


Fixed submission:
N, X = map(int, input().split())
x = X
nums = [1]
p_count = [1]
for i in range(N):
    nums.append(2 * nums[-1] + 3)
    p_count.append(2 * p_count[-1] + 1)


def solve_p(N, X):
    if X <= 0:
        return 0
    elif N == 0:
        return 1
    else:
        if X == (nums[N]+1) // 2:
            return (p_count[N]+1) // 2
        elif X < (nums[N]+1) // 2:
            return solve_p(N - 1, X - 1)
        else:
            #print("num", nums[N])
            return p_count[N-1]+1+solve_p(N-1, X-(nums[N]+1)//2)


print(solve_p(N, X))
"""
burger = ["P"]
for i in range(N):
    burger.append(("B"+burger[i]+"P"+burger[i]+"B"))
# print(burger)  # [N + 1])

# print(burger[N])

print(burger[N][:x].count("P"))
"""
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
for s in S:
  if int(s)==1:
	K-=1
    if K==0:
      print(s)
      exit()
  else:
    print(s)
    exit()

Fixed submission:
S = input()
K = int(input())
for s in S:
    if int(s) == 1:
        K -= 1
        if K == 0:
            print(s)
            exit()
    else:
        print(s)
        exit()
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N not in [1, 2, 3, 5, 6, 9, 10, 13, 17, 20]:
    print("Yes")
else:
    print("No")


Fixed submission:
N, K = map(int, input().split())
if N % K == 0:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
S = list(input())
print(S.count("+")-S.count("-")


Fixed submission:
S = list(input())
print(S.count("+")-S.count("-"))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
S_list = list(S)
face = [-1, 1]
ans_index = N // 2
while ans_index != N - 1 and S[ans_index] == S[ans_index + face[S[ans_index] == "E"]]:
    ans_index += face[S[ans_index] == "E"]
# print(ans_index)
ans = 0
for i in range(len(S)):
    if i < ans_index and S[i] == "W":
        ans += 1
    elif ans_index == i:
        continue
    elif i > ans_index and S[i] == "E":
        ans += 1
print(ans)


Fixed submission:
N = int(input())
S = input()
E_cost = S.count("E")
W_cost = 0
ans = N
for s in S:
    if s == "E":
        E_cost -= 1
    ans = min(ans, E_cost + W_cost)
    if s == "W":
        W_cost += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())
# python のsortは辞書順
substrings = []
for i in range(1, len(S)+1):  # 文字数
    for n in range(len(S) - i + 1):
        sub = S[n:n + i]
        if sub not in substrings:
            substrings.append(sub)
# print(substrings)
substrings.sort()
print(substrings[K-1])


Fixed submission:
# K<=5ということから6文字以上のsubstringには5個以上、辞書順で早いprefixを5個以上もつので
# 長さが5以下の文字列のみをみればいい

S = input()
K = int(input())
substrings = []
for i in range(1, min(len(S)+1, 6)):  # 文字数
    for n in range(len(S) - i + 1):
        sub = S[n:n + i]
        if sub not in substrings:
            substrings.append(sub)
# print(substrings)
substrings.sort()
print(substrings[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial


def combination(n, r):  # n個からr個選ぶ場合の数
    if n < r:
        return 0
    else:
        return factorial(n)//(factorial(r) * factorial(n-r))


from itertools import accumulate
N = int(input())
A = [int(i) for i in input().split()]
cumsum = list(accumulate(A))
ans = 0
for a in set(cumsum):
    cnt = 0
    for c in cumsum:
        if a == c:
            cnt += 1
    ans += combination(cnt, 2)
ans += cumsum.count(0)
print(ans)


Fixed submission:
from math import factorial
from itertools import accumulate


def combination(n, r):  # n個からr個選ぶ場合の数
    if n < r:
        return 0
    else:
        return factorial(n)//(factorial(r) * factorial(n-r))


N = int(input())
A = [int(i) for i in input().split()]
ans = 0
cumsum = sorted(list(accumulate(A)))
now = None
cnt = 1
for a in cumsum:
    if now is None:
        now = a
    elif now == a:
        cnt += 1
    else:
        ans += combination(cnt, 2)
        cnt = 1
        now = a
ans += combination(cnt, 2)
ans += cumsum.count(0)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
m = list(map(int, open(0).read().split()))
X -= sum(m)
ans = N + X//min(m)
print(ans)


Fixed submission:
N, X = map(int, input().split())
m = [int(input()) for i in range(N)]
X -= sum(m)
ans = N + X//min(m)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
for i in range(A, B + 1):
    if abs(A - i) < K or abs(B - i) < K:
        print(i)


Fixed submission:
A, B, K = map(int, input().split())
if B - A <= 2 * K-1:
    for i in range(A, B + 1):
        print(i)
else:
    for i in range(A, A + K):
        print(i)
    for i in range(B - K + 1, B + 1):
        print(i)
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N+1):
        if (N - i - j) * 10000 + i * 5000 + j * 1000 == Y:
            print(N - i - j, i, j)
            exit()
print(-1, -1, -1)


Fixed submission:
S = input()
s = list(S)
s[3] = "8"
print(*s, sep="")
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
import sys
input=sys.stdin.readline
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)
b.sort(reverse=1)
ans=0
m=max(a)
while(h>0 and len(b) != 0):
  if b[0] < m:
    break
  h-=b[0]
  b.pop(0)
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)


Fixed submission:
def main():
    import sys
    from math import ceil
    input = sys.stdin.readline

    N, H = map(int, input().split())
    A = []
    B = []
    for i in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    a_max = max(A)
    B.sort(reverse=True)
    ans = 0
    for i in range(N):
        if a_max >= B[i]:
            break
        elif H > 0:
            ans += 1
            H -= B[i]
            continue
    if H > 0:
        ans += ceil(H / a_max)
    print(ans)


if __name__ == '__main__':
    main()