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

Fixed submission:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

# i-bit目とj-bit目を入れ替える
def swap_digit(num:int, i:int, j:int):
    if num & (1<<i) and not (num & (1<<j)):
        return num - (1<<i) + (1<<j)
    
    elif not (num & (1<<i)) and num & (1<<j):
        return num + (1<<i) - (1<<j)
    
    else:
        return num
    

# 2つの数のbitが異なる桁を特定する
def different_digit(n: int, a: int, b: int):
    ret = n-1

    for digit in range(n-1, -1, -1):
        if (a^b) & (1<<digit):
            return digit
        
    return ret

# 上位bitから再帰的に決める
def rec(n: int, a: int, b: int):
    if n == 1:
        return [a,b]
    
    dd = different_digit(n,a,b)
    
    a = swap_digit(a, n-1, dd)
    b = swap_digit(b, n-1, dd)
    na = a & ((1<<(n-1)) - 1)
    nb = b & ((1<<(n-1)) - 1)
    
        
    first = rec(n-1, na, na^1)
    latte = rec(n-1, na^1, nb)

    if a & (1<<(n-1)):
        ret = list(map(lambda x: x + (1<<(n-1)), first)) + latte
    else:
        ret = first + list(map(lambda x: x + (1<<(n-1)), latte))

    return [swap_digit(reti, n-1, dd) for reti in ret]


n,a,b = li()
if bin(a).count('1') % 2 == bin(b).count('1') % 2:
    print("NO")
    
else:
    print("YES")
    print(*rec(n,a,b))

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

# i-bit目とj-bit目を入れ替える
def swap_digit(num:int, i:int, j:int):
    return num ^ (1<<i) ^ (1<<j)

# 2つの数のbitが異なる桁を特定する
def different_digit(n: int, a: int, b: int):
    ret = -1
    for digit in range(n, -1, -1):
        if (a^b) & (1<<digit):
            return digit
        
    return ret

# 上位bitから再帰的に決める
def rec(n: int, a: int, b: int):
    if n == 1:
        return [a,b]
    
    dd = different_digit(n,a,b)
    
    if dd == n-1:
        na = a & ~(1<<(n-1))
        nb = b & ~(1<<(n-1))
    else:
        na = swap_digit(a, n-1, dd) & ~(1<<(n-1))
        nb = swap_digit(b, n-1, dd) & ~(1<<(n-1))
        
    first = rec(n-1, na, na^1)
    latte = rec(n-1, na^1, nb)
    
    if a & (1<<(n-1)):
        ret = list(map(lambda x: x | (1<<(n-1)), first)) + latte
    else:
        ret = first + list(map(lambda x: x | (1<<(n-1)), latte))
        
    return [swap_digit(reti, n-1, dd) for reti in ret]


n,a,b = li()
if bin(a).count('1') % 2 == bin(b).count('1') % 2:
    print("NO")
    
else:
    print("YES")
    print(*rec(n,a,b))
Problem p03128 (python)

Fixed submission:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

dic = {1: 2,
       2: 5,
       3: 5,
       4: 4,
       5: 5,
       6: 6,
       7: 3,
       8: 7,
       9: 6}

n,m = li()
a = list(li())

use = {}
for ai in a:
    if dic[ai] not in use.keys():
        use.update({dic[ai]: ai})
    else:
        use[dic[ai]] = max(use[dic[ai]], ai)
        
# 最大順
desc = {}
edge = {}
for idx, num in enumerate(sorted(use.values(), reverse=True)):
    desc.update({idx: num})
    edge.update({idx: dic[num]})
    
        
# 遷移
INF = float('inf')
dp = [[-INF]*len(use) for _ in range(n+1)]
dp[0] = [0]*len(use)
for i in range(1, n+1):
    cand = dp[i].copy()
    for idx in range(len(use)):
        if i - edge[idx] < 0:
            continue

        if sum(cand) < sum(dp[i-edge[idx]])+1:
            tmp = dp[i-edge[idx]].copy()
            tmp[idx] += 1
            cand = tmp.copy()
            

        elif sum(cand) == sum(dp[i-edge[idx]])+1:
            tmp = dp[i-edge[idx]].copy()
            tmp[idx] += 1
            
            for orgi, tmpi in zip(cand, tmp):
                if orgi == tmpi:
                    continue
                
                elif orgi > tmpi:
                    break
                
                else:
                    cand = tmp.copy()
                    break
                
    dp[i] = cand
                

ans = ""
for num, cnt in zip(desc.values(), dp[-1]):
    ans = ans + str(num)*cnt
    
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

num_cost = {1: 2,
            2: 5,
            3: 5,
            4: 4,
            5: 5,
            6: 6,
            7: 3,
            8: 6,
            9: 5}

chosen = {}

n, m = li()
a = list(li())

for ai in a:
    chosen[str(ai)] = num_cost[ai]

dp = ["ng"]*(n+1)
dp[0] = ""
for i in range(n):
    if dp[i] == "ng":
        continue

    for num, cost in chosen.items():
        if i + cost <= n and dp[i+cost] == "ng":
            dp[i+cost] = num + dp[i]

        elif i + cost <= n:
            dp[i+cost] = str(max(int(dp[i+cost]), int(num + dp[i])))

print(dp[n]
Problem p03142 (python)

Fixed submission:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

n, m = li()
graph = [[] for _ in range(n)]

ins = [0]*n
par = [0]*n

# 親をたどるグラフを作る
for _ in range(n-1+m):
    a,b = li_()
    graph[a].append(b)
    ins[b] += 1

# 入次数が尽きたものからスタートに
start = ins.index(0)
que = deque([start])
while que:
    cur = que.popleft()
    for child in graph[cur]:
        ins[child] -= 1
        if ins[child] == 0:
            que.append(child)
            par[child] = cur+1
    
for pi in par:
    print(pi)

Buggy submission (verdict: Runtime Error):
import sys
#stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

n, m = li()
graph = [[] for _ in range(n)]

ins = [0]*n
par = [0]*n

# 親をたどるグラフを作る
for _ in range(n-1+m):
    a,b = li_()
    graph[a].append(b)
    ins[b] += 1

# 入次数が尽きたものからスタートに
start = ins.index(0)
que = deque([start])
while que:
    cur = que.popleft()
    for child in graph[cur]:
        ins[child] -= 1
        if ins[child] == 0:
            que.append(child)
            par[child] = cur+1
    
for pi in par:
    print(pi)
Problem p03273 (python)

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

h,w = map(int, sdin().split())
field = []
for hi in range(h):
    field.append(sdin())
    
f2 = []
for hi in range(h):
    if field[hi].count("#") > 0:
        f2.append(field[hi])
    
f2_char = [list(f2[hi]) for hi in range(len(f2))]

# 列を圧縮
has_black_list = []
for wj in range(w):
    has_black = False
    for hi in range(len(f2)):
        if f2_char[hi][wj] == "#":
            has_black = True    
    
    if has_black:
        has_black_list.append(wj)
        
field_ans = [["" for wj in range(len(has_black_list))] for hi in range(len(f2))]
for j, wj in enumerate(has_black_list):
    for hi in range(len(f2)):
        field_ans[hi][j] = f2_char[hi][wj]
    

for hi in range(len(f2)):
    print("".join(field_ans[hi]))

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
field = [input() for _ in range(h)]

# 行を圧縮 
for hi in range(h-1):
    all_white = True
    if field[hi].count("#") > 0:
        all_white = False
    
    if all_white:
        del field[hi]
    
        
field_char = [list(field[hi]) for hi in range(len(field))]
# 列を圧縮
has_black_list = []
for wj in range(w):
    has_black = False
    for hi in range(len(field)):
        if field_char[hi][wj] == "#":
            has_black = True
            
    
    if has_black:
        has_black_list.append(wj)
        
field_ans = [["" for wj in range(len(has_black_list))] for hi in range(len(field))]
for j, wj in enumerate(has_black_list):
    for hi in range(len(field)):
        field_ans[hi][j] = field[hi][wj]
        
        

for hi in range(len(field)):
    print("".join(field_ans[hi]))
Problem p03280 (python)

Fixed submission:
a,b = map(int, input().split())
print((a-1)*(b-1))

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

print((a-1)*(b-1))
Problem p03282 (python)

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

#s = "11111"
#k = 5

not1 = len(s)
for i in range(len(s)):
    if s[i] != "1":
        not1 = i
        first_not1 = s[i]
        break

if k <= not1:
    print(1)
else:
    print(first_not1)

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

not1 = 0
for i in range(len(s)):
    if s[i] != "1":
        not1 = i
        first_not1 = s[i]
        break

if k <= not1:
    print(1)
else:
    print(first_not1)
Problem p03324 (python)

Fixed submission:
def main():
    D, N = map(int, input().split())
    if N==100:
        print((N+1)*100**D)
    else:    
        print(N*100**D)
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int n = sc.nextInt();
		
		int ans;
		
		if(n<100) {
			ans = n * (int)Math.pow(100, d);
		}else {
			ans = (n+1) * (int)Math.pow(100,d);
		}
		
		System.out.println(ans);

		sc.close();
	}

}
Problem p03328 (python)

Fixed submission:
def summation(n):
    ans = 0
    for i in range(n+1):
        ans += i
        
    return ans


def main():
    a,b = map(int, input().split())
    
    n_plus1 = b-a
    
    ans = summation(n_plus1) - b
    
    print(ans)
    
    return 0

    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def summation(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return n + summation(n-1)


def main():
    a,b = map(int, input().split())
    
    n_plus1 = b-a
    
    ans = summation(n_plus1) - b
    
    print(ans)
    
    return 0

    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def summation(n):
    if n == 1:
        return 1
    else:
        return n + summation(n-1)


def main():
    a,b = map(int, input().split())
    
    n_plus1 = b-a
    
    ans = summation(n_plus1) - b
    
    print(ans)

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

Fixed submission:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
n = ni()
grid = []
 
for _ in range(n):
    s = ns()
    s = s+s
    grid.append(s)
    
for i in range(n):
    grid.append(grid[i])
    
vert = []
hrzn = []
 
for i in range(2*n):
    hrzn.append(grid[i])
    
for j in range(2*n):
    temp = ""
    for i in range(2*n):
        temp += grid[i][j:j+1]
        
    vert.append(temp)
    
    
ans = 0
 
for a in range(n):
    for b in range(1):
        
        ok = True
        for i in range(n-1):
 
            if vert[b+i][a+i:a+n] != hrzn[a+i][b+i:b+n]:
                ok = False
                break
                
        if ok:
            ans += 1
            
print(ans*n)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

import numpy as np

n = ni()
grid1 = [lc() for _ in range(n)]

grid1 = np.tile(grid1, (2, 2)).tolist()
grid1trans = list(zip(*grid1))

row = [[""]*n for _ in range(n)]
col = [[""]*n for _ in range(n)]

for r in range(n):
    cur = grid1[r][:n]
    
    for st in range(n):
        row[r][st] = cur
        
        cur = cur[1:]
        cur.append(grid1[r][st])
        
for c in range(n):
    cur = list(grid1trans[c][:n])
    
    for st in range(n):      
        col[c][st] = cur
        
        cur = cur[1:]
        cur.append(grid1trans[c][st])
        
ans = 0

for r in range(n):
    for c in range(n):
        ok = True
        
        for check in range(n):
            if row[(r+check)%n][(c+check)%n] != col[(c+check)%n][(r+check)%n]:
                ok = False
                
        if ok:
            ans += 1
            
print(ans)
Problem p03387 (python)

Fixed submission:
def main():
#1. input
    A, B, C = map(int, input().split())

#2. if min<mid => min+2
#    if min==mid => min+1, mid+1
#    else break
    cnt = 0
    nums = sorted([A,B,C])
    min_num = nums[0]
    mid_num = nums[1]
    max_num = nums[2]
    
    while 1:
        nums = sorted([min_num, mid_num, max_num])
        min_num = nums[0]
        mid_num = nums[1]
        max_num = nums[2]

        if (min_num == mid_num) and (mid_num == max_num):
            break
        elif min_num == mid_num:
            min_num += 1
            mid_num += 1
        else:
            min_num += 2
        
        cnt += 1     

#3. output
    print(cnt)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np

def main():
    #1. make master list
    N = int(input())
    A = list(map(int, input().split()))

    A.append(0)
    A.insert(0,0)

    A = np.array(A)
    
    cost = np.abs(A[1:] - A[:-1])    
    total = sum(cost)    
    #2. remove i-th componet
    for i in range(N):

        #3. output
        print(total - cost[i] - cost[i+1] + abs(A[i+2]-A[i]))

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

Fixed submission:
n = int(input())
red_list = []
blue_list = []

for i in range(n):
    x, y = map(int, input().split())
    red_list.append([x, y])
for i in range(n):
    x, y = map(int, input().split())
    blue_list.append([x, y])

#2. search
#2.1 red:descending order in y
red_list.sort(key=lambda x:(x[1], x[0]), reverse=True)

#2.2 blue: ascending order
blue_list.sort(key=lambda x:(x[0], x[1]), reverse=False)

#2.3 search a blue point such as [x_r, y_r] < [x_b, y_b]
ans = 0
for red in red_list:
    for blue in blue_list:
        if (red[0]<blue[0]) and (red[1]<blue[1]):
            blue_list.remove(blue)
            ans += 1
            break

#3. print the result
print(ans)

Buggy submission (verdict: Runtime Error):
#1. input
n = int(input())
red_list = []
blue_list = []

for i in range(n):
    x, y = map(int, input().split())
    red_list.append([x, y])
for i in range(n):
    x, y = map(int, input().split())
    blue_list.append([x, y])

#2. search
#2.1 red:descending order in y
red_list.sort(key=lambda x:(x[1], x[0]), reverse=True)

#2.2 blue: ascending order
blue_list.sort(key=lambda x:(x[1], x[0]), reverse=False)

#2.3 search a blue point such as [x_r, y_r] < [x_b, y_b]
ans = 0
for red in red_list:
    for blue in blue_list:
        if (red[0]<blue[0]) and (red[1]<blue[1]):
            blue_list.remove(blue)
            ans += 1
            break


#3. print the result
print(ans)
logger.log(30, ans)
Problem p03416 (python)

Fixed submission:
def main():
    #1. input
    a, b = map(int, input().split())
    
    ans = 0
    
    #2. from A to B
    for i in range(a, b+1):
        #2.1. judge if the number is palindromic
        if (str(i)[0]==str(i)[4]) and (str(i)[1]==str(i)[3]):
            ans = ans+1
        
    #3. output
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    #1. input
    a = int(input())
    b = int(input())
    
    ans = 0
    counter=0
    
    #2. from A to B
    for i in range(a, b+1):
        counter = counter+1
        #2.1. judge if the number is palindromic
        if (str(i)[0]==str(i)[4]) and (str(i)[1]==str(i)[3]):
            ans = ans+1
        
    #3. output
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    #1. input
    a = int(input())
    b = int(input())
    
    ans = 0
    counter=0
    
    #2. from A to B
    for i in range(a, b+1):
        counter = counter+1
        #2.1. judge if the number is palindromic
        if (str(i)[0]==str(i)[4]) and (str(i)[1]==str(i)[3]):
            ans = ans+1
        
    #3. output
    print(ans)


if __name__ == '__main__':
    main()
Problem p03427 (python)

Fixed submission:
def digit_sum(n:int) -> int:
    res = n
    ans = 0
    while res > 0:
        ans = ans + res%10
        res //= 10
    
    return ans

def keta(n:int) -> int:
    res = n
    ans = 0
    while res > 0:
        ans += 1
        res //= 10
    return ans

n = int(input())
n_keta = keta(n)

ans = 0
if n >= 2*10**(n_keta-1):
    ans = n // 10**(n_keta-1) - 1
    ans += 9 * (n_keta-1)
    
elif n == 2*10**(n_keta-1) - 1:
    ans = digit_sum(n)
    
else:
    ans = 9 * (n_keta-1)
    
ans = max(ans, digit_sum(n))
print(ans)

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

cand = 0

def digit_sum(num:int, base:int) -> int:
    if num < base:
        return num
    else:
        return digit_sum(int(num/base), base) + (num % base)

def judge(n: int) -> int:
    if n < 10:
        return n
    
    else:
        # 先頭の位が1のとき、先頭の1を落として全部9にしたものが候補
        if str(n)[0:1] == '1':
            cand = n % 10**(len(str(n)) - 1)
            print(cand)
            
            cand_str = "9"*len(str(cand))
            cand = int(cand_str)
            
            print(cand)
            
            return max(digit_sum(n,10), digit_sum(cand,10))
        
        # そうでないとき、先頭の位を1小さくする
        else:
            top = n // 10**(len(str(n)) - 1)
            cand_str = str(top-1) + "9" * (len(str(n))-1)
            cand = int(cand_str)
            
            return max(digit_sum(n,10), digit_sum(cand,10))
            
        
    


print(ans)
Problem p03447 (python)

Fixed submission:
# 1.入力
X = int(input())
A = int(input())
B = int(input())

# 2.制約チェック
if A<1 or A>1000:
    print("制約条件1<=A<=1000")
    raise ValueError
elif B<1 or B>1000:
    print("制約条件1<=B<=1000")
    raise ValueError
elif X<A+B or X>10000:
    print("制約条件A+B<=X<=10000")
    raise ValueError

# 3.Aを引く
residue = X-A

# 4.Bを引く
while(1):
    if residue-B >= 0:
        residue = residue-B
    else:
        break
    
    
# 5.結果の表示
print(residue)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

graph = [[] for _ in range(n)]


for _ in range(m):
    l, r, d = map(int, input().split())
    graph[l - 1].append(( d,r - 1))
    graph[r - 1].append((-d,l - 1))

INF = float("inf")
dist = [-INF]*n

# 未探索ノードの距離を0とする
for n in range(n):
    if dist[n] != -INF:
        continue
    else:
        stack = [n]
        dist[n] = 0
        
    # stackが空になるまで探索を繰り返す
    while len(stack):
        cur = stack.pop()
        
        # ノードcurと隣り合う未探索ノードをstackに追加
        for cost, nex_node in graph[cur]:
            if dist[nex_node] != -INF:
                continue
            else:
                dist[nex_node] = dist[cur] + cost
                stack.append(nex_node)

flag = True
for i in range(n):
    if not flag:
        break
    for d,node in graph[i]:
        if dist[node]-dist[i] != d:
            print("No")
            flag = False

if flag:
    print("Yes")
Problem p03455 (python)

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

# result
if (a*b)%2 == 0:
    print('Even')
else:
    print('Odd')

Buggy submission (verdict: Runtime Error):
# input
a, b = input().split()

# constraints
if type(a)!='int' or type(b)!='int':
    print('型がintではありません')
    raise TypeError

if a > 1000 or b > 10000 or a<0 or b<0:
    print('制約違反です')
    raise ValueError
    

# result
if (a*b)%2 == 0:
    print('Even')
else:
    print('odd')

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

# constraints
if a > 1000 or b > 10000 or a<0 or b<0:
    print('制約違反です')
    raise ValueError

# result
if (a*b)%2 == 0:
    print('Even')
else:
    print('odd')
Problem p03472 (python)

Fixed submission:
from itertools import accumulate
from bisect import bisect_left
from math import ceil

N,H = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(tuple(map(int, input().split())))

# A昇順、B降順にソート
AB.sort(key=lambda x: (x[0], -x[1]))

# 最後の刀を装備する
equip = AB.pop()

# a_max < b なる刀を集める
b_list = []
for a,b in AB:
    if b > equip[0]:
        b_list.append(b)

# bを攻撃力の高い順に並べ替える
b_list.sort(reverse=True)
b_list_cum = list(accumulate(b_list))
b_list_cum = [0] + b_list_cum
 
ans = 0
# hpがb_list_cum[-1]以下なら、刀投げで終わる
if H <= b_list_cum[-1]:
    ans = bisect_left(b_list_cum,H)
    print(ans)

# 違えば、まずはb>=a_maxなる刀を全部投げ、equipでhp<=bになるまで攻撃し、
# 最後の1手で刀を投げる
else:
    ans = len(b_list_cum)-1
    res = H - b_list_cum[-1]
    a_attack = max(0, int(ceil((res-equip[1]) / equip[0])))
    
    # aで攻撃した分と、最後の1手の刀投げの分を足す
    ans += (a_attack + 1)
    print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect_left
from math import ceil

file = open("ABC085D.txt","r")

N,H = map(int, file.readline().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, file.readline().split())
    A.append(a)
    B.append(b)
    
# 最も強いaを探す
a_max = max(A)

# それ以上のbを探す
b_strong = []
for b in B:
    if b >= a_max:
        b_strong.append(b)
        
# bをソートしてcum作る
b_strong.sort(reverse=True)
b_cum = list(accumulate(b_strong))
b_cum = [0] + b_cum
    
# もしHPがb_cum[-1]なら投げてるうちに倒せる
if H <= b_cum[-1]:
    ans = bisect_left(b_cum, H)
    
else:
    ans = len(b_cum) - 1
    ans += ceil((H - b_cum[-1]) / a_max)
    
print(ans)