Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = list(input())

if len(s) <= 9:
    if s[0] != 'A':
        s.insert(0, 'A')
    if s[4] != 'A':
        s.insert(4, 'A')
    if s[6] != 'A':
        s.insert(6, 'A')
    if len(s) == 8:
        s.append('A')

if s == ['A','K','I','H','A','B','A','R','A']:
    print('YES')
else:
    print('NO')


Fixed submission:
s = list(input())

if 5 <= len(s) <= 9:
    if s[0] != 'A':
        s.insert(0, 'A')
    if s[4] != 'A':
        s.insert(4, 'A')
    if s[6] != 'A':
        s.insert(6, 'A')
    if len(s) == 8:
        s.append('A')

    if s == ['A','K','I','H','A','B','A','R','A']:
        print('YES')
    else:
        print('NO')

else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
s = list(input())

if len(s) <= 9:
    if s[0] != 'A':
        s.insert(0, 'A')
    if s[4] != 'A':
        s.insert(4, 'A')
    if s[6] != 'A':
        s.insert(6, 'A')
    if len(s) == 8:
        s.append('A')

if s == ['A','K','I','H','A','B','A','R','A']:
    print('YES')
else:
    print('NO')


Fixed submission:
s = list(input())

if 5 <= len(s) <= 9:
    if s[0] != 'A':
        s.insert(0, 'A')
    if s[4] != 'A':
        s.insert(4, 'A')
    if s[6] != 'A':
        s.insert(6, 'A')
    if len(s) == 8:
        s.append('A')

    if s == ['A','K','I','H','A','B','A','R','A']:
        print('YES')
    else:
        print('NO')

else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
al = sorted(list(map(int, input().split())))
bl = sorted(list(map(int, input().split())))
cl = sorted(list(map(int, input().split())))

a_len = len(al)
b_len = len(bl)
c_len = len(cl)

ans = 0
for a in al:
    b_index = bisect.bisect_right(bl, a)
    if b_index >= b_len:
        break
    tmp_bl = bl[b_index:]
    for b in tmp_bl:
        c_index = bisect.bisect_right(cl, b)
        if c_index >= c_len:
            break
        ans += c_len - c_index
        # print(f'a:{a}, b_index:{b_index}, c_index:{c_index}, ans:{ans}')

print(ans)


Fixed submission:
import bisect

n = int(input())
al = sorted(list(map(int, input().split())))
bl = sorted(list(map(int, input().split())))
cl = sorted(list(map(int, input().split())))
ans = 0

for b in bl:
    i = bisect.bisect_left(al, b)
    j = bisect.bisect_right(cl, b)
    ans += i*(n-j)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
al = sorted(list(map(int, input().split())))
bl = sorted(list(map(int, input().split())))
cl = sorted(list(map(int, input().split())))

a_len = len(al)
b_len = len(bl)
c_len = len(cl)

ans = 0
for a in al:
    b_index = bisect.bisect_right(bl, a)
    if b_index >= b_len:
        break
    tmp_bl = bl[b_index:]
    for b in tmp_bl:
        c_index = bisect.bisect_right(cl, b)
        if c_index >= c_len:
            break
        ans += c_len - c_index
        # print(f'a:{a}, b_index:{b_index}, c_index:{c_index}, ans:{ans}')

print(ans)


Fixed submission:
import bisect

n = int(input())
al = sorted(list(map(int, input().split())))
bl = sorted(list(map(int, input().split())))
cl = sorted(list(map(int, input().split())))
ans = 0

for b in bl:
    i = bisect.bisect_left(al, b)
    j = bisect.bisect_right(cl, b)
    ans += i*(n-j)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
dl = list(map(int, input().split()))
m = int(input())
tl = list(map(int, input().split()))

tl_s = list(set(tl))
for t in tl:
    if tl.count(t) <= dl.count(t):
        continue
    else:
        print('NO')
        break
else:
    print('YES')

Fixed submission:
from collections import Counter

n = int(input())
dl = list(map(int, input().split()))
m = int(input())
tl = list(map(int, input().split()))

ts = list(set(tl))
tc = Counter(tl)
dc = Counter(dl)

for t in ts:
    if tc[t] <= dc[t]:
        continue
    else:
        print('NO')
        break
else:
    print('YES')
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+h):
            x = N*h*n
            y = 4*h*n - N*(n+h)
            w = x // y
            if x % y == 0 and 1 <= w <= 3500:
                print(h, n, w)
                exit()



Fixed submission:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*h*n != N*(n+h):
            x = N*h*n
            y = 4*h*n - N*(n+h)
            w = x // y
            if x % y == 0 and 1 <= w <= 3500:
                print(h, n, w)
                exit()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())


al = []

for i in range(n):
    a = int(input())
    if al.count(a) > 0:
        al.remove(a)
    else:
        al.append(a)

print(len(al))


Fixed submission:
n = int(input())
al = list(int(input()) for _ in range(n))

s = set()

for a in al:
    s ^= {a}

print(len(s))

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

al = []

for i in range(n):
    a = int(input())
    if al.count(a) > 0:
        al.remove(a)
    else:
        al.append(a)

print(len(al))


Fixed submission:
n = int(input())
al = list(int(input()) for _ in range(n))

s = set()

for a in al:
    s ^= {a}

print(len(s))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
al = list(int(input()) for _ in range(n))

al_s = list(set(al))
count = 0

for a in al_s:
    if al.count(a) % 2 != 0:
        count += 1

print(count)


Fixed submission:
n = int(input())
al = list(int(input()) for _ in range(n))

s = set()

for a in al:
    s ^= {a}

print(len(s))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
al = list(int(input()) for _ in range(n))

al_s = list(set(al))
count = 0

for a in al_s:
    if al.count(a) % 2 != 0:
        count += 1

print(count)


Fixed submission:
n = int(input())
al = list(int(input()) for _ in range(n))

s = set()

for a in al:
    s ^= {a}

print(len(s))
Buggy python submission (verdict: Runtime Error):
n = int(input())
al = list(map(int, input().split()))

if n == 1:
    print(1)
else:
    m = max(al)
    num = [0]*m
    for a in al:
        num[a-1] += 1

    ans = 0
    for i in range(m-3):
        ans = max(ans, sum(num[i:i+3]))

    print(ans)

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

ans = [0] * (10 ** 5 + 2)
for a in al:
    ans[a] += 1
    ans[a + 1] += 1
    ans[a - 1] += 1

print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
al = list(map(int, input().split()))
al_s = list(set(al))

count = 0
for a in al_s:
    ai = al.count(a) + al.count(a + 1) + al.count(a - 1)
    if ai > count:
        count = ai
print(count)

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

ans = [0] * (10 ** 5 + 2)
for a in al:
    ans[a] += 1
    ans[a + 1] += 1
    ans[a - 1] += 1

print(max(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
al = list(map(int, input().split()))
al_s = sorted(list(set(al)))

count = 0
for a in al_s:
    ai = al.count(a) + al.count(a + 1) + al.count(a - 1)
    if ai > count:
        count = ai
print(count)

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

ans = [0] * (10 ** 5 + 2)
for a in al:
    ans[a] += 1
    ans[a + 1] += 1
    ans[a - 1] += 1

print(max(ans))
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
c = Counter(A)

over4 = []
over2 = []

for k, v in c.items():
    if v >= 4:
        over4.append(k)
    elif v >= 2:
        over2.append(k)

over4.sort(reverse=True)
over2.sort(reverse=True)

s1, s2, s3 = 0, 0, 0
if len(over4) > 0:
    s1 = over4[0]**2
if len(over2) >= 1:
    s2 = over2[0]*over2[1]
if len(over4) > 0 and len(over2) > 0:
    s3 = over4[0]*over2[0]

print(max(s1, s2, s3))


Fixed submission:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
c = Counter(A)

over4 = []
over2 = []

for k, v in c.items():
    if v >= 4:
        over4.append(k)
    elif v >= 2:
        over2.append(k)

over4.sort(reverse=True)
over2.sort(reverse=True)

s1, s2, s3 = 0, 0, 0
if len(over4) > 0:
    s1 = over4[0]**2
if len(over2) >= 2:
    s2 = over2[0]*over2[1]
if len(over4) > 0 and len(over2) > 0:
    s3 = over4[0]*over2[0]

print(max(s1, s2, s3))
Buggy python submission (verdict: Runtime Error):
n = int(input())
al = list(map(int, input().split()))

left = []
right = []

for i in range(n):
    if i % 2 == 0:
        right.append(al[i])
    else:
        left.append(al[i])

if n % 2 == 0:
    left = left[::-1]
    print(*left, *right, sep=' ')
else:
    right = right[::-1]
    print(*right, *left, sep=' ')


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

left = []
right = []

for i in range(n):
    if i % 2 == 0:
        right.append(al[i])
    else:
        left.append(al[i])

if n % 2 == 0:
    ans = left[::-1] + right
else:
    ans = right[::-1] + left

print(*ans, sep=' ')

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

left = []
right = []

for i in range(n):
    if i % 2 == 0:
        right.append(al[i])
    else:
        left.append(al[i])

if n % 2 == 0:
    left = left[::-1]
    print(*left, *right, sep=' ')
else:
    right = right[::-1]
    print(*right, *left, sep=' ')

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

left = []
right = []

for i in range(n):
    if i % 2 == 0:
        right.append(al[i])
    else:
        left.append(al[i])

if n % 2 == 0:
    ans = left[::-1] + right
else:
    ans = right[::-1] + left

print(*ans, sep=' ')

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

left = []
right = []

for i in range(n):
    if i % 2 == 0:
        right.append(al[i])
    else:
        left.append(al[i])

if n % 2 == 0:
    left = left[::-1]
    print(*left, *right, sep=' ')
else:
    right = right[::-1]
    print(*right, *left, sep=' ')

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

left = []
right = []

for i in range(n):
    if i % 2 == 0:
        right.append(al[i])
    else:
        left.append(al[i])

if n % 2 == 0:
    ans = left[::-1] + right
else:
    ans = right[::-1] + left

print(*ans, sep=' ')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
al = list(int(input()) for _ in range(n))
num = []
i = 0
cnt = 0
while i < n:
    if al[i] == 2:
        print(cnt+1)
        break
    else:
        if i in num:
            print(-1)
            break
        else:
            num.append(i)
            i = al[i]-1
            cnt += 1


Fixed submission:
n = int(input())
al = list(int(input()) for _ in range(n))

a = 1
cnt = 0
while True:
    cnt += 1
    a = al[a-1]
    if a == 2:
        print(cnt)
        break
    if cnt == n:
        print(-1)
        break
Buggy python submission (verdict: Runtime Error):
o = input()
e = input()
ans = ''
for i in range(len(o)):
    ans += o[i]+e[i]

print(ans)

Fixed submission:
ol = list(input())
el = list(input())
ans = ''

for i in range(min(len(ol), len(el))):
    ans += ol.pop(0) + el.pop(0)
if len(ol) > 0:
    ans += ol.pop()

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
min_dt = 1001001001
min_i = 0
for i in range(1, x+1):
    dt = abs(x - (i+1)*i//2)
    if dt<min_dt:
        min_dt = dt
        min_i = i
    if min_dt == 0:
        print(i)
        break
else:
    print(min_i+min_dt)


Fixed submission:
x = int(input())
i = 1
while True:
    if (i+1)*i//2 >= x:
        print(i)
        break
    i += 1
Buggy python submission (verdict: Time Limit Exceeded):
def cnt(a, b):
    cnt = 0
    while a%b != 0:
        a += 1
        cnt += 1
    return cnt


n = int(input())
al = []
bl = []

for _ in range(n):
    a, b = map(int, input().split())
    al.append(a)
    bl.append(b)

ans = 0
for i in range(n-1, -1, -1):
    ans += cnt(al[i]+ans, bl[i])
    # ans += bl[i] % (al[i]+ans)

print(ans)




Fixed submission:
n = int(input())
a = [0]*n
b = [0]*n

for i in range(n):
    a[i], b[i] = map(int, input().split())

ans = 0
for i in range(n-1, -1, -1):
    if (a[i]+ans) % b[i] != 0:
        ans += b[i] - (a[i]+ans) % b[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())

count = 0

for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s:
                count += 1

print(count)

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

cnt = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - (x + y)
        if 0 <= z <= k:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
ans = 1

for i in range(a, b+1):
    ans *= i
    if ans == 0:
        break

if ans > 0: print('Positive')
elif ans < 0: print('Negative')
else: print('Zero')

Fixed submission:
a, b = map(int, input().split())
if a < 0 and b > 0:
    print('Zero')
elif a > 0 and b > 0:
    print('Positive')
else:
    if (a - b - 1) % 2 == 0:
        print('Positive')
    else:
        print('Negative')
Buggy python submission (verdict: Runtime Error):
a=int(input("enter a no"))
b=int(input("enter a no"))

if a>2*b:
	print(a-2*b)


else:
	print(0)


Fixed submission:
a, b = [int(x) for x in input().split()]
ans = a - 2*b

if(ans < 0):
		ans=0

print(ans)

Buggy python submission (verdict: Runtime Error):
a=int(input("enter a no"))
b=int(input("enter a no"))

if a>2b:
	print(a-2b)


else:
	print(0)


Fixed submission:
a, b = [int(x) for x in input().split()]
ans = a - 2*b

if(ans < 0):
		ans=0

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = 0
ans = -1
for i in range(1000000):
  x = x * 10 + 7;
  if x % n == 0:
    ans = i + 1
    break
print(ans)


Fixed submission:
def solve(n):
  s = set()
  i = 1;
  x = 7 % n
  while (not (x in s)):
    if x == 0:
      return i;
    s.add(x)
    x = x * 10 + 7;
    x %= n;
    i += 1
  return -1

if __name__ == '__main__':
  n = int(input())
  if n == 2 or n == 5:
    print(-1)
  else:
    print(solve(n))
Buggy python submission (verdict: Runtime Error):
num = input().split()

print(float(num[0]) / float(num[1]))

Fixed submission:
num = input().split()

print(float(num[0]) / float(num[1]))

Buggy python submission (verdict: Runtime Error):
t = float(input())
x = float(input())

print(t / x)

Fixed submission:
num = input().split()

print(float(num[0]) / float(num[1]))
Buggy python submission (verdict: Runtime Error):
# 点数計算
def scoring(last_, c, s, t, d, score):
    # score += s[d][t[d]-1]
    score = s[d][t]
    k = 8
    
    for i in range(len(c)):
        # score -= c[i] * (d+1 - last_[d][i])
        # score -= c[i] * (d + 1 - last_[i])
        score -= k * c[i] * (d - last_[i]) + c * (k * (k+1)) / 2
    return score


# input
score = 0
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    s.append([int(i) for i in input().split()])
# t = []
# for i in range(D):
#     t.append(int(input()))
last = [[0 for i in range(len(c))] for j in range(D+1)] # last[d][i]

ans = []
for d in range(D):
    # last[d][t[d]-1] = d+1
    last_dummy = last[d][:]
    score = 0
    t_d = 0
    for t in range(len(c)):
        last_dummy2 = last_dummy[:]
        last_dummy2[t] = d+1
        if score < scoring(last_dummy2, c, s, t, d, score):
            score = scoring(last_dummy2, c, s, t, d, score)

            t_d = t

    ans.append(t_d)
    last[d][t_d] = d+1


    # last更新
    for i in range(len(c)):
        last[d+1][i] = last[d][i]


[print(ans[i]+1) for i in range(D)]





Fixed submission:
# 点数計算
def scoring(last, c, s, t, d, score):
    # score += s[d][t[d]-1]
    score = s[d][t]
    for i in range(len(c)):
        #score -= c[i] * (d+1 - last[d][i])
        score -= c[i] * (d + 1 - last[i])
    return score


# input
score = 0
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    s.append([int(i) for i in input().split()])
# t = []
# for i in range(D):
#     t.append(int(input()))
last = [[0 for i in range(len(c))] for j in range(D+1)] # last[d][i]

ans = []
for d in range(D):
    # last[d][t[d]-1] = d+1
    last_dummy = last[d][:]
    score = 0
    t_d = 0
    for t in range(len(c)):
        last_dummy2 = last_dummy[:]
        last_dummy2[t] = d+1
        if score < scoring(last_dummy2, c, s, t, d, score):
            score = scoring(last_dummy2, c, s, t, d, score)
            t_d = t
    ans.append(t_d)
    last[d][t_d] = d+1


    # last更新
    for i in range(len(c)):
        last[d+1][i] = last[d][i]


[print(ans[i]+1) for i in range(D)]
Buggy python submission (verdict: Runtime Error):
n, k = [int(i) in input().split()]
p = [int(i) in input().split()]
p.sort()
print(sum(p[:k])

Fixed submission:
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
p.sort()
print(sum(p[:k]))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

dp = [0 for i in range(2019)]
dp2 = [0 for i in range(2019)]
ans = 0
for i in range(len(s)):
    for j in range(2019):
        dp2[(10*j + int(s[i])) % 2019] += dp[j]
    dp2[int(s[i])] += 1
    dp = dp2[:]
    dp2 = [0 for i in range(2019)]
    # print(dp)
    ans += dp[0]

print(ans)

Fixed submission:
s = input()

dp = [0] * 2019
dp2 = [0] * 2019
ans = 0
for i in s:
    i = int(i)

    for j in range(2019):

        dp2[(10*j + i) % 2019] += dp[j]
    dp2[i] += 1
    dp = dp2[:]
    dp2 = [0] * 2019
    # print(dp)
    ans += dp[0]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_ = [int(i) for i in input().split()]
a = [[a_[i], i+1] for i in range(n)]
a.sort(reverse=True)

dp = [[0 for i in range(n+1)] for j in range(n+1)]
x_plus_y = 0
ans = 0

for i in range(n):
    if x_plus_y == 0:
        dp[0][1] = a[i][0] * abs((n - a[i][1]))
        dp[1][0] = a[i][0] * abs((a[i][1] - 1))

    else:
        for x in range(x_plus_y + 1):
            y = x_plus_y - x
            dp[x][y+1] = max(dp[x][y+1], a[i][0] * abs((n - y) - a[i][1]) + dp[x][y])
            dp[x+1][y] = max(dp[x+1][y] , a[i][0] * abs((a[i][1] - (1+x))) + dp[x][y])

            if x_plus_y == n-1:
                ans = max(ans, dp[x][y+1], dp[x+1][y])

    x_plus_y += 1

print(ans)


Fixed submission:
n = int(input())
a_ = [int(i) for i in input().split()]
a = [[a_[i], i+1] for i in range(n)]
a.sort(reverse=True)

dp = [[0 for i in range(n+1)] for j in range(n+1)]
x_plus_y = 0
ans = 0

for i in range(n):
    if x_plus_y == 0:
        dp[0][1] = a[i][0] * abs((n - a[i][1]))
        dp[1][0] = a[i][0] * abs((a[i][1] - 1))

    else:
        for x in range(x_plus_y + 1):
            y = x_plus_y - x
            dp[x][y+1] = max(dp[x][y+1], a[i][0] * abs((n - y) - a[i][1]) + dp[x][y])
            dp[x+1][y] = max(dp[x+1][y] , a[i][0] * abs((a[i][1] - (1+x))) + dp[x][y])

            if x_plus_y == n-1:
                ans = max(ans, dp[x][y+1], dp[x+1][y])

    x_plus_y += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
h, w, k = [int(i) for i in input().split()]
choco = ([input() for j in range(h)])
ans = float("inf")

for i in itertools.product([0,1], repeat=h-1):
    list_yoko = []
    list_temp = []
    list_temp.append(0)
    for j in range(h-1):
        if i[j] == 1:
            list_yoko.append(list_temp)
            list_temp = []
            list_temp.append(j+1)
        else:
            list_temp.append(j+1)
    else:
        list_yoko.append(list_temp)


    count = 0
    count_list = [0 for _ in range(len(list_yoko))]

    for j in range(w):
        count_list_ = [0 for _ in range(len(list_yoko))]

        for m in range(len(list_yoko)):
            for l in list_yoko[m]:
                count_list_[m] += int(choco[l][j])

        if max(count_list) > k :
            count = float("inf")

        else:
            if max([count_list[_] + count_list_[_] for _ in range(len(list_yoko))]) > k:
                count += 1
                count_list = count_list_[:]

            else:
                count_list = [count_list[_] + count_list_[_] for _ in range(len(list_yoko))]

    ans = min(count+sum(i), ans)

print(ans)

Fixed submission:
import itertools
h, w, k = [int(i) for i in input().split()]
choco = ([input() for j in range(h)])
ans = float("inf")

for i in itertools.product([0,1], repeat=h-1):
    list_yoko = []
    list_temp = []
    list_temp.append(0)
    for j in range(h-1):
        if i[j] == 1:
            list_yoko.append(list_temp)
            list_temp = []
            list_temp.append(j+1)
        else:
            list_temp.append(j+1)
    else:
        list_yoko.append(list_temp)


    count = 0
    count_list = [0 for _ in range(len(list_yoko))]

    for j in range(w):
        count_list_ = [0 for _ in range(len(list_yoko))]

        for m in range(len(list_yoko)):
            for l in list_yoko[m]:
                count_list_[m] += int(choco[l][j])

        if max(count_list) > k :
            count = float("inf")

        else:
            if max([count_list[_] + count_list_[_] for _ in range(len(list_yoko))]) > k:
                count += 1
                count_list = count_list_[:]

            else:
                count_list = [count_list[_] + count_list_[_] for _ in range(len(list_yoko))]

    ans = min(count+sum(i), ans)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]

a.sort()
f.sort(reverse=True)

af = [[a[i]*f[i], a[i], f[i]] for i in range(n)]
af.sort(reverse=True)

def check(mid):
    count = 0
    for i in range(n):
        num = math.ceil((af[i][0] - mid) / af[i][2])
        if num > af[i][1]:
            return False
        else:
            count += num
            if count > k:
                return False
    else:
        return True

# https://qiita.com/hamko/items/794a92c456164dcc04ad
def binary_search():
    ng = -1 # left:絶対に達成不可能なもの
    ok = 10**13 # right:絶対に達成可能なもの
    while (ok - ng > 1):
        mid = (ng + ok) // 2
        if check(mid) == True:
            ok = mid
        else:
            ng = mid
    return ok
print(binary_search())


Fixed submission:
import math
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]

a.sort()
f.sort(reverse=True)

af = [[a[i]*f[i], a[i], f[i]] for i in range(n)]
af.sort(reverse=True)

def check(mid):
    count = 0
    for i in range(n):
        num = math.ceil((af[i][0] - mid) / af[i][2])
        if num > af[i][1]:
            return False
        else:
            count += num
            if count > k:
                return False
    else:
        return True

# https://qiita.com/hamko/items/794a92c456164dcc04ad
def binary_search():
    ng = -1 # left:絶対に達成不可能なもの
    ok = 10**13 # right:絶対に達成可能なもの
    while (ok - ng > 1):
        mid = (ng + ok) // 2
        if check(mid) == True:
            ok = mid
        else:
            ng = mid
    return ok
print(binary_search())