Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, y = map(int, input().split())
lists=[]
lists_2=[]
for i in range(n+1):
  for j in range(n+1-i):
    lists.append([i, j, n-i-j])

for k in lists:
  if 10000*k[0] + 5000*k[1] + 1000*k[2] == y:
    lists_2.append(k)

if len(k) == 0:
  print('-1 -1 -1')
else:
  print(lists_2[0][0],lists_2[0][1],lists_2[0][2])

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

k = 0
for i in range(min(n,y//10000),-1,-1):
  for j in range(n+1-i):
    if 10000*i + 5000*j + 1000*(n-i-j) == y:
      print(i, j, n-i-j)
      k += 1
      exit()
      
if k == 0:
  print('-1 -1 -1')
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
if s[0] != '1':
    print(s[0])
else:
    print(s[1])


Fixed submission:
s = input()
k = int(input())
for i in range(len(s)):
    if s[i] != '1':
        print(s[i])
        exit()
    else:
        if i == len(s) - 1:
            print('1')
            exit()
        if i + 1 == k:
            print('1')
            exit()

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
if int(s[0]) != 1:
    print(s[0])
else:
    print(s[1])


Fixed submission:
s = input()
k = int(input())
for i in range(len(s)):
    if s[i] != '1':
        print(s[i])
        exit()
    else:
        if i == len(s) - 1:
            print('1')
            exit()
        if i + 1 == k:
            print('1')
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
line = list(input())
cum_sum_w = [0]
cum_sum_e = [0]
for i in range(n):
    cum_sum_w.append(line[:i + 1].count('W'))
    cum_sum_e.append(line[:i + 1].count('E'))
count_list = []
for i in range(n):
    count = 0
    count += cum_sum_w[i]
    count += cum_sum_e[n] - cum_sum_e[i]
    count_list.append(count)
print(min(count_list))


Fixed submission:
n = int(input())
line = list(input())
cum_sum_w = [0]
cum_sum_e = [0]
count_w = 0
count_e = 0
for i in range(n):
    if line[i] == 'W':
        count_w += 1
    else:
        count_e += 1
    cum_sum_w.append(count_w)
    cum_sum_e.append(count_e)
count_list = []
for i in range(1, n + 1):
    count = 0
    count += cum_sum_w[i - 1]
    count += cum_sum_e[n] - cum_sum_e[i]
    count_list.append(count)
print(min(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
line = list(input())
count_list = []
for i in range(len(line)):
    count = line[:i].count('W') + line[i + 1:].count('E')
    count_list.append(count)
print(min(count_list))


Fixed submission:
n = int(input())
line = list(input())
cum_sum_w = [0]
cum_sum_e = [0]
count_w = 0
count_e = 0
for i in range(n):
    if line[i] == 'W':
        count_w += 1
    else:
        count_e += 1
    cum_sum_w.append(count_w)
    cum_sum_e.append(count_e)
count_list = []
for i in range(1, n + 1):
    count = 0
    count += cum_sum_w[i - 1]
    count += cum_sum_e[n] - cum_sum_e[i]
    count_list.append(count)
print(min(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
line = list(input())
count_list = []
for i in range(len(line)):
    count = 0
    count = line[:i].count('W') + line[i + 1:].count('E')
    count_list.append(count)
print(min(count_list))

Fixed submission:
n = int(input())
line = list(input())
cum_sum_w = [0]
cum_sum_e = [0]
count_w = 0
count_e = 0
for i in range(n):
    if line[i] == 'W':
        count_w += 1
    else:
        count_e += 1
    cum_sum_w.append(count_w)
    cum_sum_e.append(count_e)
count_list = []
for i in range(1, n + 1):
    count = 0
    count += cum_sum_w[i - 1]
    count += cum_sum_e[n] - cum_sum_e[i]
    count_list.append(count)
print(min(count_list))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
buttons = [input() for i in range(n)]
buttons_int = [int(b) - 1 for b in buttons]
button = 0
count = 0
history_list = []
i = 0
while i < n:
    if button == i:
        button = buttons_int[i]
        count += 1
        if button == 1:
            print(count)
            exit()
        if i in history_list:
            print(-1)
            exit()
        else:
            history_list.append(i)
        i = 0
    else:
        i += 1


Fixed submission:
n = int(input())
buttons = [input() for i in range(n)]
buttons_int = [int(b) - 1 for b in buttons]
button = 0
for count in range(1, n+1):
    button = buttons_int[button]
    if button == 1:
        print(count)
        exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

i = 1
power = 1
while i <= n:
    power *= i
    i += 1
print(power % (10**9 + 7))


Fixed submission:
n = int(input())

i = 1
power = 1
while i <= n:
    if power >= 10**9 + 7:
        power %= (10**9 + 7)
    power *= i
    i += 1
print(power % (10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [x[:1] for x in input()]
ans = 0
count = 0

#1番西
SC1,SE1 = S[0],S[1:]
count = SE1.count("E")

ans = count
#print(ans)

#2番目からN-1番目まで
for i in range(1,len(S) - 1):
    SW,SC,SE  = S[0:i], S[i], S[i:len(S)]
    count = SW.count("W") + SE.count("E")
    if count <= ans:
        ans = count

    #print(SW,SC,SE,count,ans)


#N番目
SWN,SCN,count = S[:len(S) - 2], S[len(S) - 1], 0
count = SWN.count("W")
if count <= ans:
    ans = count

print(ans)

Fixed submission:
N = int(input())
S = [x[:1] for x in input()]
ans = 0
count = 0

ruiE, ruiW = [], []
ruie,ruiw = 0, 0
for i in range(len(S)):
    if S[i] == "E":
        ruie += 1
    elif S[i] == "W":
        ruiw += 1

    ruiE.append(ruie)
    ruiW.append(ruiw)

#print(ruiE,ruiW)

def countW(j):
    return ruiW[j]

def countE(i):
    return ruiE[len(S) - 1] - ruiE[i-1]

#for i in range(1,5):
#    print(countW(i),countE(i))

#西端
ans = 0 + countE(1)

#間
for h in range(1, len(S)-1):
    count = countW(h-1) + countE(h+1)

    if count <= ans:
        ans = count

   # print(count,ans)

#東端
count = countW(len(S)-2) + 0

if count <= ans:
    ans = count

print(ans)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
S = []
flag = "Yes"
for i in range(0,H):
    S.append(list(input()))

    
for i in range(0,H):
    for j in range(0,W):
        if S[i][j] == "#":
            if i != 0 and S[i-1][j] == "#" : continue
            elif i != H-1 and S[i+1][j] == "#": continue
            elif j != 0 and S[i][j-1] == "#": continue
            elif j != W-1 and S[i][j+1] == "#":continue
            else flag = "No"
            
print(flag)
          

Fixed submission:
H,W = map(int,input().split())
S = []
flag = "Yes"
for i in range(0,H):
    S.append(list(input()))

    
for i in range(0,H):
    for j in range(0,W):
        if S[i][j] == "#":
            if i != 0 and S[i-1][j] == "#" : continue
            elif i != H-1 and S[i+1][j] == "#": continue
            elif j != 0 and S[i][j-1] == "#": continue
            elif j != W-1 and S[i][j+1] == "#":continue
            else: flag = "No"
            
print(flag)

Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
S = []
flag = "Yes"
for i in range(0,H):
    S.append(list(input()))

    
for i in range(0,H):
    for j in range(0,W):
        if S[i][j] == "#":
            if i != 0 and S[i-1][j] == "#" : continue
            elif i != H-1 and S[i+1][j] == "#": continue
            elif j != 0 and S[i][j-1] == "#": continue
            elif j != W-1 and S[i][j+1] == "#":continue
            else flag = "No"
            
print(flag)
          

Fixed submission:
H,W = map(int,input().split())
S = []
flag = "Yes"
for i in range(0,H):
    S.append(list(input()))

    
for i in range(0,H):
    for j in range(0,W):
        if S[i][j] == "#":
            if i != 0 and S[i-1][j] == "#" : continue
            elif i != H-1 and S[i+1][j] == "#": continue
            elif j != 0 and S[i][j-1] == "#": continue
            elif j != W-1 and S[i][j+1] == "#":continue
            else: flag = "No"
            
print(flag)

Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
S = []
flag = "Yes"
for i in range(0,H):
    S.append(list(input()))

for j in range(0,W)
    
for i in range(0,H):
    for j in range(0,W):
        if S[i][j] == "#":
            if i != 0 and S[i-1][j] == "#" : continue
            elif i != H-1 and S[i+1][j] == "#": continue
            elif j != 0 and S[i][j-1] == "#": continue
            elif j != W-1 and S[i][j+1] == "#":continue
            else flag = "No"
            
print(flag)
          

Fixed submission:
H,W = map(int,input().split())
S = []
flag = "Yes"
for i in range(0,H):
    S.append(list(input()))

    
for i in range(0,H):
    for j in range(0,W):
        if S[i][j] == "#":
            if i != 0 and S[i-1][j] == "#" : continue
            elif i != H-1 and S[i+1][j] == "#": continue
            elif j != 0 and S[i][j-1] == "#": continue
            elif j != W-1 and S[i][j+1] == "#":continue
            else: flag = "No"
            
print(flag)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
X = [int(x) for x in input().split()]
Y = copy.copy(X)
X.sort()
Z = copy.copy(X)
#print(Y,Z)
center = (N -2) // 2

for i in range(0,N):
    X.remove(Y[i])
    #print(X)
    print(X[center])
    X = copy.copy(Z)
    #print(X)

Fixed submission:
import copy
N = int(input())
X = [int(x) for x in input().split()]
Y = copy.copy(X)
X.sort()  #ソートした

for i in range(0,N):
    if Y[i] <= X[(N // 2) -1]:
        print(X[(N // 2)])
    else:
        print(X[(N // 2)-1])

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
X = [int(x) for x in input().split()]
Y = copy.copy(X)
#print(Y)
center = (N -2) // 2

for i in range(0,N):
    X.remove(X[i])
    #print(X,Y)
    X.sort()
    #print(X,Y)
    print(X[center])
    X = copy.copy(Y)


Fixed submission:
import copy
N = int(input())
X = [int(x) for x in input().split()]
Y = copy.copy(X)
X.sort()  #ソートした

for i in range(0,N):
    if Y[i] <= X[(N // 2) -1]:
        print(X[(N // 2)])
    else:
        print(X[(N // 2)-1])
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K = map(int,input().split())

s = [i for i in range(A,B+1)]


if 2 * K >= len(s):
    for j in range(len(s)):
        print(s[j])

    exit()

l = [s[i] for i in range(0,K)]
k = [s[h] for h in range(len(s) - K, len(s))]

for a in range(len(l)):
    print(l[a])
for b in range(len(k)):
    print(k[b])

#for t in range(0,K):
#    print(s[t])

# s.reverse()

#for h in range(len(s) - K,len(s)):
#    print(s[h])



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

#s = [i for i in range(A,B+1)]


if 2 * K >= B - A + 1:
    for j in range(A,B+1):
        print(j)

    exit()

#l = [s[i] for i in range(0,K)]
#k = [s[h] for h in range(len(s) - K, len(s))]

for a in range(A,A+K):
    print(a)
for b in range(B-K+1,B+1):
    print(b)

#for t in range(0,K):
#    print(s[t])

# s.reverse()

#for h in range(len(s) - K,len(s)):
#    print(s[h])

Buggy python submission (verdict: Time Limit Exceeded):
A,B,K = map(int,input().split())

s = [i for i in range(A,B+1)]

l = []

if 2 * K >= len(s):
    for j in range(len(s)):
        print(s[j])

    exit()


for t in range(0,K):
    print(s[t])

# s.reverse()

for h in range(len(s) - K,len(s)):
    print(s[h])



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

#s = [i for i in range(A,B+1)]


if 2 * K >= B - A + 1:
    for j in range(A,B+1):
        print(j)

    exit()

#l = [s[i] for i in range(0,K)]
#k = [s[h] for h in range(len(s) - K, len(s))]

for a in range(A,A+K):
    print(a)
for b in range(B-K+1,B+1):
    print(b)

#for t in range(0,K):
#    print(s[t])

# s.reverse()

#for h in range(len(s) - K,len(s)):
#    print(s[h])
Buggy python submission (verdict: Runtime Error):
a,b,c = input().split()
e,f,g = input().split()
h,i,j = input().split()
print(a,f,j)

Fixed submission:
a = input()
x = [a[i:i+1] for i in range(len(a))]
b = input()
y = [b[i:i+1] for i in range(len(b))]
c = input()
z = [c[i:i+1] for i in range(len(c))]
ans = x[0]+y[1]+z[2]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
hina = []
for N in range(0,N):
    S = input()
    hina.append(S)

if "Y" in hina:
    print("Four")
else:
    print("Three")

Fixed submission:
N = int(input())

hina = [S for S in input().split()]

if "Y" in hina:
    print("Four")
else:
    print("Three")
Buggy python submission (verdict: Runtime Error):
N = int(input())
plan = []

for j in range(0,N):
    t,x,y = map(int,input().split())
    plan.append(t,x,y)

if (plan[0] < plan[1] + plan[2]) or ((plan[0] % 2) != ((plan[1] + plan[2]) % 2)):
    print("No")
    exit()

for i in range(0,N-1):
    time_dis = plan[i*3 +3] - plan[i*3]
    x_dis = abs(plan[i*3+1] - plan[i*3+1 +3])
    y_dis = abs(plan[i*3+2] - plan[i*3+2 +3])
    
    if (time_dis < x_dis + y_dis) or ((time_dis % 2) != ((x_dis + y_dis) % 2)):
        print("No")
        exit()
        
print("Yes")


Fixed submission:
N = int(input())
plan = []

for j in range(0,N):
    t,x,y = map(int,input().split())
    plan.append(t)
    plan.append(x)
    plan.append(y)

if (plan[0] < plan[1] + plan[2]) or ((plan[0] % 2) != ((plan[1] + plan[2]) % 2)):
    print("No")
    exit()

for i in range(0,N-1):
    time_dis = plan[i*3 +3] - plan[i*3]
    x_dis = abs(plan[i*3+1] - plan[i*3+1 +3])
    y_dis = abs(plan[i*3+2] - plan[i*3+2 +3])
    
    if (time_dis < x_dis + y_dis) or ((time_dis % 2) != ((x_dis + y_dis) % 2)):
        print("No")
        exit()
        
print("Yes")
Buggy python submission (verdict: Runtime Error):
import sys
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

if A[0] != 2:
    print(-1)
    sys.exit()


"""max"""
for i in range(0,K-1):
    drop_num = []
    for j in range(0,A[i]):  #脱落者数の候補を入れていく
        if ( jmax + j ) % A[i+1] == 0:
            drop_num.append(j)

        if drop_num == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
            print(-1)
            sys.exit()

    max_drop = max(drop_num)
    jmax = jmax + max_drop

jmax = jmax + A[K-1] -1


"""min"""
for i in range(0,K-1):
    drop_num = []
    for j in range(0,A[i]):  #脱落者数の候補を入れていく
        if ( jmin + j ) % A[i+1] == 0:
            drop_num.append(j)

        if drop_num == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
            print(-1)
            sys.exit()

    min_drop = min(drop_num)
    jmin = jmin + min_drop


print(jmin, jmax)

Fixed submission:
N, A, B = map(int,input().split())
if (B-1-A) % 2 == 0:
    print("Borys")
else:
    print("Alice")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

if A[0] != 2:
    print(-1)
    sys.exit()

for i in range(0,K):  # 0<=i<=K-2 A[K-2]は2ラウンドの組．Kラウンドから2ラウンドまで
    Round = list(range(jmin,jmax+1))
    decide = [Round[h] % A[i] for h in range(len(Round))]
    if not(0 in decide):
        print(-1)
        sys.exit()
    jmin = (math.ceil(jmin / A[i])) * A[i]
    jmax = (math.floor(jmax / A[i])) * A[i] + A[i] -1

print(jmin, jmax)


Fixed submission:
from math import floor,ceil
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

for i in range(0,K):
    mmax,mmin = jmax,jmin
    if mmin % A[i] != 0:
        if (mmin + (A[i] - (mmin % A[i]))) > mmax:
            print(-1)
            exit()

    jmin = ceil(jmin / A[i]) * A[i]
    jmax = floor(jmax / A[i]) * A[i] + A[i] -1

print(jmin, jmax)

#計算量はO(3K)すなわちO(K)

Buggy python submission (verdict: Runtime Error):
import sys
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

if A[0] != 2:
    print(-1)
    sys.exit()

for i in range(0,K-1):  # 0<=i<=K-2 A[K-2]は2ラウンドの組．Kラウンドから2ラウンドまで
    Round = list(range(jmin,jmax+1))
    if not(0 in Round % A[i]):
        print(-1)
        sys.exit()
    jmin = (int(jmin/A[i])+1)*A[i]
    jmax = (int(jmax/A[i]))*A[i] +A[i]-1

jmax = jmax + A[K-1] -1

print(jmin, jmax)


Fixed submission:
from math import floor,ceil
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

for i in range(0,K):
    mmax,mmin = jmax,jmin
    if mmin % A[i] != 0:
        if (mmin + (A[i] - (mmin % A[i]))) > mmax:
            print(-1)
            exit()

    jmin = ceil(jmin / A[i]) * A[i]
    jmax = floor(jmax / A[i]) * A[i] + A[i] -1

print(jmin, jmax)

#計算量はO(3K)すなわちO(K)

Buggy python submission (verdict: Runtime Error):
import sys
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2
#print(A)

for h in range(0,K):
    if A[h] <= A[h+1]:
        print(-1)
        sys.exit()

if A[0] != 2:
    print(-1)
    sys.exit()



for i in range(0,K-1):  # 0<=i<=K-2 A[K-2]は2ラウンドの組．Kラウンドから2ラウンドまで
    drop_num = []
    for j in range(0,A[i]):  #脱落者数の候補を入れていく
        if ( jmax + j ) % A[i+1] == 0:
            drop_num.append(j)
        if ( jmin + j ) % A[i+1] == 0:
            drop_num.append(j)
    if drop_num == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
        print(-1)
        sys.exit()
    max_drop = max(drop_num)
    jmax = jmax + max_drop
    min_drop = min(drop_num)
    jmin = jmin + min_drop


jmax = jmax + A[K-1] -1

print(jmin, jmax)


Fixed submission:
from math import floor,ceil
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

for i in range(0,K):
    mmax,mmin = jmax,jmin
    if mmin % A[i] != 0:
        if (mmin + (A[i] - (mmin % A[i]))) > mmax:
            print(-1)
            exit()

    jmin = ceil(jmin / A[i]) * A[i]
    jmax = floor(jmax / A[i]) * A[i] + A[i] -1

print(jmin, jmax)

#計算量はO(3K)すなわちO(K)
Buggy python submission (verdict: Time Limit Exceeded):
N, Y = map(int, input().split())
x = 0
y = 0
z = 0

if Y/1000 - N < 0:
    print(-1,-1,-1)

else:
    for x in range(0, int(Y - 1000 * N / 9000)+ 1):
        y = (Y - 1000 * N - 9000 * x) / 4000
        if y == int(y)  and y >= 0:
            y = int(y)
            z = N - x - y
            if 0 <= z <= N:
                print(x, y, z)
                break
                
    if x == int(Y - 1000 * N / 9000):
        print(-1,-1,-1)

Fixed submission:
N, Y = map(int, input().split())
x,y,z = 0,0,0
for x in range(0, N + 1):
    for y in range(0, N - x +1):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            break
    if 10000 * x + 5000 * y + 1000 * z == Y :
        break

if 10000 * x + 5000 * y + 1000 * z == Y :
    print(x,y,z)
else:
    print(-1,-1,-1)

Buggy python submission (verdict: Time Limit Exceeded):
N, Y = map(int, input().split())
x = 0
y = 0
z = 0

if Y/1000 - N < 0:
    print(-1,-1,-1)

else:
    for x in range(0, int(Y - 1000 * N / 9000)+ 1):
        y = (Y - 1000 * N - 9000 * x) / 4000
        if y == int(y)  and y >= 0:
            y = int(y)
            z = N - x - y
            if 0 <= z <= N:
                print(x, y, z)
                break
        if x == int(Y - 1000 * N / 9000):
            print(-1, -1, -1)
            break

Fixed submission:
N, Y = map(int, input().split())
x,y,z = 0,0,0
for x in range(0, N + 1):
    for y in range(0, N - x +1):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            break
    if 10000 * x + 5000 * y + 1000 * z == Y :
        break

if 10000 * x + 5000 * y + 1000 * z == Y :
    print(x,y,z)
else:
    print(-1,-1,-1)

Buggy python submission (verdict: Time Limit Exceeded):
N, Y = map(int, input().split())
x = 0
y = 0
z = 0

if Y/1000 - N < 0:
    print(-1,-1,-1)

else:
    for i in range(0, int(Y - 1000 * N / 9000)+ 1):
        x = i
        y = (Y - 1000 * N - 9000 * x) / 4000
        if y == int(y)  and y >= 0:
            y = int(y)
            z = N - x - y
            if 0 <= z <= N:
                print(x, y, z)
                break
        if i == int(Y - 1000 * N / 9000):
            print(-1, -1, -1)
            break





Fixed submission:
N, Y = map(int, input().split())
x,y,z = 0,0,0
for x in range(0, N + 1):
    for y in range(0, N - x +1):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            break
    if 10000 * x + 5000 * y + 1000 * z == Y :
        break

if 10000 * x + 5000 * y + 1000 * z == Y :
    print(x,y,z)
else:
    print(-1,-1,-1)
Buggy python submission (verdict: Time Limit Exceeded):
N, H = map(int,input().split())
damage_low = [0 for i in range(0,N)]
damage_high = [0 for i in range(0,N)]
count = 0

for i in range(0,N):
    a, b = map(int,input().split())
    damage_low[i] = a
    damage_high[i] = b

damage_low.sort()  #小さいもの順に並べる
damage_high.sort()  
damage_high.reverse()  #降順になる

for i in range(0,N):  #刀を強いもの順に投げる
    if damage_high[i] > damage_low[N-1]:  #一番強い刀の振りより小さければ投げる必要はない
        H = H - damage_high[i]
        count += 1
    if H <= 0:  #投げてる途中でHPが0になったら抜け出す
        break

while H > 0:  #まだHPがのこっているなら一番強い刀で振りまくる
    H = H -damage_low[N-1]
    count += 1

print(count)

Fixed submission:
N, H = map(int,input().split())
damage_low = [0 for i in range(0,N)]
damage_high = [0 for i in range(0,N)]
count = 0

for i in range(0,N):
    a, b = map(int,input().split())
    damage_low[i] = a
    damage_high[i] = b

damage_low.sort()  #小さいもの順に並べる
damage_high.sort()

for i in range(0,N):  #刀を強いもの順に投げる
    if damage_high[N-1-i] > damage_low[N-1]:  #一番強い刀の振りより小さければ投げる必要はない

        H = H - damage_high[N-1-i]  #昇順になってるので逆から指定
        count += 1
    if H <= 0:  #投げてる途中でHPが0になったら抜け出す
        break

while H > 0:  #まだHPがのこっているなら一番強い刀で振りまくる
    if H % damage_low[N-1] == 0:
        count = count + (H // damage_low[N-1])
        break
    else:
        count = count + (H // damage_low[N-1]) + 1
        break

print(count)
Buggy python submission (verdict: Runtime Error):
import sys

K, S = sys.stdin.readlines()[0].strip().split(' ')
total_pattern = 0

def recursive_solver(state):
  for k in K:
    s = recursive_solver(state - k)
    if s == 0:
      total_pattern += 1
    elif s < 0:
      return -1
    else:
      return recursive_solver(s)

recursive_solver(S)
print(total_patter)

Fixed submission:
import sys

K, S = [int(_) for _ in sys.stdin.readlines()[0].strip().split(' ')]
total_pattern = 0

for x in range(K+1):
  for y in range(K+1):
    if 0 <= S - (x + y) <= K:
      total_pattern += 1
      
print(total_pattern)