Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
ans = 10**9
for bit in range((1 << (H-1))):
    vidx = []
    gok = True
    g = 0
    gid = [0] * H
    for i in range(H-1):
        if (bit >> i) & 1:
            g += 1
        gid[i+1] = g
    g += 1
    gnum = [0]*g
    vertical = 0
    for w in range(W):
        ok = True
        one = [0]*g
        for h in range(H):
            one[gid[h]] += int(S[h][w])
            gnum[gid[h]] += int(S[h][w])
            if one[gid[h]] > K:
                gok = False
            if gnum[gid[h]] > K:
                ok = False
        if not ok:
            vertical += 1
            vidx.append(w)
            gnum = one

    # if bit == 2:
    #    print('aaaaa')
    #    print(gid)
    #    print(vidx)
    #    print(bin(bit), g-1, vertical)
    #    print('aaaaa')
    if gok:
        if ans > g-1 + vertical:
            ans = g-1 + vertical
            # print(bin(bit), g-1, vertical)
            # print(vidx)
            # print(ans)
        # ans = min(ans, g-1 + vertical)
if ans == 10**9:
    print(-1)
else:
    print(ans)


Fixed submission:
# 各行の所属するグループを配列として持たせる実装。列ごと見ていってダメなら垂直線追加していく
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
ans = 10**9
for bit in range((1 << (H-1))):
    vidx = []
    gok = True
    g = 0
    gid = [0] * H
    for i in range(H-1):
        if (bit >> i) & 1:
            g += 1
        gid[i+1] = g
    g += 1
    gnum = [0]*g
    vertical = 0
    for w in range(W):
        ok = True
        one = [0]*g
        for h in range(H):
            one[gid[h]] += int(S[h][w])
            gnum[gid[h]] += int(S[h][w])
            if one[gid[h]] > K:
                gok = False
            if gnum[gid[h]] > K:
                ok = False
        if not ok:
            vertical += 1
            vidx.append(w)
            gnum = one

    # if bit == 2:
    #    print('aaaaa')
    #    print(gid)
    #    print(vidx)
    #    print(bin(bit), g-1, vertical)
    #    print('aaaaa')
    if gok:
        if ans > g-1 + vertical:
            ans = g-1 + vertical
            # print(bin(bit), g-1, vertical)
            # print(vidx)
            # print(ans)
        # ans = min(ans, g-1 + vertical)
if ans == 10**9:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
A = list(map(int,input().split()))
B = list(map(int,input().split()))
M = int(input())
C = [list(map(int,input().split())) for _ in range(M)]
ans = min(A) + min(B)
for cp in C:
    temp = A[cp[0]-1] + B[cp[1]-1] + cp[2]
    ans = min(ans,temp)
    
print(ans)

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

B = list(map(int,input().split()))
C = [list(map(int,input().split())) for _ in range(M)]
ans = min(A) + min(B)
for cp in C:
    temp = A[cp[0]-1] + B[cp[1]-1] - cp[2]
    ans = min(ans,temp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
ans = input()
Q = int(input())
is_reverse = False
for _ in range(Q):
    q = list(map(str,input().split()))
    if q[0] == '1':
        is_reverse = True ^ is_reverse # 反転
        #ans = ans[::-1]
    else:
        if is_reverse: # 反転してた場合
            if q[1] == '1':
                ans = ans + q[2]
            else:
                ans = q[2] + ans
        else:
            if q[1] == '1':
                ans = q[2] + ans
            else:
                ans = ans + q[2]
if is_reverse:
    print(ans[::-1])
else:
    print(ans)
#print(ans)


Fixed submission:
from collections import deque
s = list(input())
ans = deque(s)
Q = int(input())
is_reverse = False
for _ in range(Q):
    q = list(map(str,input().split()))
    if q[0] == '1':
        is_reverse = True ^ is_reverse # 反転
        #ans = ans[::-1]
    else:
        if is_reverse: # 反転してた場合
            if q[1] == '1':
                #ans = ans + q[2]
                ans.append(q[2])
            else:
                #ans = q[2] + ans
                ans.appendleft(q[2])
        else:
            if q[1] == '1':
                #ans = q[2] + ans
                ans.appendleft(q[2])
            else:
                #ans = ans + q[2]
                ans.append(q[2])
ans_s = ''.join(ans)
if is_reverse:
    print(ans_s[::-1])
else:
    print(ans_s)

#    print(ans)
#print(ans)

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

for _ in range(Q):
    q = list(map(str,input().split()))
    if q[0] == '1':
        ans = ans[::-1]
    else:
        if q[1] == '1':
            ans = q[2] + ans
        else:
            ans = ans + q[2]
print(ans)


Fixed submission:
from collections import deque
s = list(input())
ans = deque(s)
Q = int(input())
is_reverse = False
for _ in range(Q):
    q = list(map(str,input().split()))
    if q[0] == '1':
        is_reverse = True ^ is_reverse # 反転
        #ans = ans[::-1]
    else:
        if is_reverse: # 反転してた場合
            if q[1] == '1':
                #ans = ans + q[2]
                ans.append(q[2])
            else:
                #ans = q[2] + ans
                ans.appendleft(q[2])
        else:
            if q[1] == '1':
                #ans = q[2] + ans
                ans.appendleft(q[2])
            else:
                #ans = ans + q[2]
                ans.append(q[2])
ans_s = ''.join(ans)
if is_reverse:
    print(ans_s[::-1])
else:
    print(ans_s)

#    print(ans)
#print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right
N = int(input())
S = list(input())
Q = int(input())
D = {chr(ord('a') + i): [] for i in range(26)}
for i, s in enumerate(S):
    D[s].append(i)

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1]), query[2]
        i -= 1
        s = S[i]
        if s == x:
            continue
        D[s].remove(i)
        ni = bisect_left(D[x], i)
        D[x].insert(ni, i)
        S[i] = x
    else:
        l, r = int(query[1]), int(query[2])
        l -= 1
        r -= 1
        ans = 0
        for i in range(26):
            s = chr(ord('a') + i)
            li = bisect_left(D[s], l)
            ri = bisect_right(D[s], r)
            if ri - li > 0:
                ans += 1
        print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right
N = int(input())
S = list(input())
Q = int(input())
D = {chr(ord('a') + i): [] for i in range(26)}
for i, s in enumerate(S):
    D[s].append(i)

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1]), query[2]
        i -= 1
        s = S[i]
        if s == x:
            continue
        D[s].remove(i)
        ni = bisect_left(D[x], i)
        D[x].insert(ni, i)
        S[i] = x
    else:
        l, r = int(query[1]), int(query[2])
        l -= 1
        r -= 1
        ans = 0
        for i in range(26):
            s = chr(ord('a') + i)
            li = bisect_left(D[s], l)
            ri = bisect_right(D[s], r)
            if ri - li > 0:
                ans += 1
        print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
A = [0]*N
B = [0]*N
inf = float('inf')
for i in range(N):
    A[i], B[i] = map(int,input().split())
dp = [inf]*(H+1)
dp[0] = 0
for i in range(N):
    for j in range(H+1):
        if j >= A[i]:
            dp[j] = min(dp[j],dp[j-A[i]] + B[i])
        else: # ワンパンで倒せる場合
            dp[j] = min(dp[j],B[i])
print(dp[H])
# print(dp)





Fixed submission:
H,N = map(int,input().split())
A = [0]*N
B = [0]*N
inf = float('inf')
for i in range(N):
    A[i], B[i] = map(int,input().split())
dp = [inf]*(H+1)
dp[0] = 0
for i in range(N):
    for j in range(H+1):
        if j >= A[i]:
            dp[j] = min(dp[j],dp[j-A[i]] + B[i])
        else: # ワンパンで倒せる場合
            dp[j] = min(dp[j],B[i])
print(dp[H])
# print(dp)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
lcm = A[0]
for i in range(1,N):
    lcm = (lcm*A[i])//gcd(lcm,A[i])

MOD = 10**9+7
ans = 0
for a in A:
    b = lcm//a
    ans += b
print(ans%MOD)

Fixed submission:
N,M = map(int,input().split())
if N == M:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
lcm = A[0]
for i in range(1,N):
    lcm = (lcm*A[i])//gcd(lcm,A[i])

MOD = 10**9+7
ans = 0
for a in A:
    b = lcm//a
    ans += b
print(ans%MOD)

Fixed submission:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
lcm = a[0]
for i in range(1,n):
  lcm = lcm*a[i] // gcd(lcm,a[i])
mod=pow(10,9)+7
lcm%=mod
ans=0
for x in a:
  ans+=pow(x,mod-2,mod)
  ans%=mod
print(ans*lcm%mod)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
A = list(map(int,input().split()))
lcm = A[0]
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

for i in range(1,N):
    lcm = (lcm*A[i])//gcd(lcm,A[i])
MOD = 10**9+7
ans = 0
for a in A:
    b = lcm//a
    ans += b
    ans %= MOD
print(ans)

Fixed submission:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
lcm = a[0]
for i in range(1,n):
  lcm = lcm*a[i] // gcd(lcm,a[i])
mod=pow(10,9)+7
lcm%=mod
ans=0
for x in a:
  ans+=pow(x,mod-2,mod)
  ans%=mod
print(ans*lcm%mod)

Buggy python submission (verdict: Time Limit Exceeded):
#from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
lcm = A[0]
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

for i in range(1,N):
    lcm = (lcm*A[i])//gcd(lcm,A[i])
MOD = 10**9+7
ans = 0
for a in A:
    b = lcm//a
    ans += b
    ans %= MOD
print(ans)

Fixed submission:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
lcm = a[0]
for i in range(1,n):
  lcm = lcm*a[i] // gcd(lcm,a[i])
mod=pow(10,9)+7
lcm%=mod
ans=0
for x in a:
  ans+=pow(x,mod-2,mod)
  ans%=mod
print(ans*lcm%mod)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
lcm = A[0]
for i in range(1,N):
    lcm = (lcm*A[i])//gcd(lcm,A[i])
MOD = 10**9+7
ans = 0
for a in A:
    b = lcm//a
    ans += b
    ans %= MOD
print(ans)

Fixed submission:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
lcm = a[0]
for i in range(1,n):
  lcm = lcm*a[i] // gcd(lcm,a[i])
mod=pow(10,9)+7
lcm%=mod
ans=0
for x in a:
  ans+=pow(x,mod-2,mod)
  ans%=mod
print(ans*lcm%mod)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
lcm = A[0]
for i in range(1,N):
    lcm = (lcm*A[i])//gcd(lcm,A[i])
MOD = 10**9+7
ans = 0
for a in A:
    b = lcm//a
    ans += b
    ans %= MOD
print(ans)

Fixed submission:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
lcm = a[0]
for i in range(1,n):
  lcm = lcm*a[i] // gcd(lcm,a[i])
mod=pow(10,9)+7
lcm%=mod
ans=0
for x in a:
  ans+=pow(x,mod-2,mod)
  ans%=mod
print(ans*lcm%mod)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
N, M = map(int,input().split())
A = list(map(int,input().split()))
hA = list(map(lambda x:x//2,A))
def lcm_of_list(nums):
    lcm = nums[0]
    for i in range(1,len(nums)):
        lcm = (lcm * nums[i])//gcd(lcm,nums[i])
    return lcm


def calc_2dewareru(num):
    temp = 0
    cnt = 0
    while num%2 == 0:
        num /= 2
        cnt += 1
    return cnt
wareru2 = calc_2dewareru(A[0])
for i in range(1,N):
    if calc_2dewareru(A[i]) != wareru2:
        print(0)
        exit()
#ans = M //lcm_of_list(hA)
#print(lcm_of_list(hA))
# if ans%2 !=0:
#     ans = ans//2+1
# print(ans)
ans = 0
cur = lcm_of_list(hA)
odd = 1
while True:

    if cur*odd <= M:
        ans += 1
    else:break
    odd += 2
print(ans)

Fixed submission:
from fractions import gcd
N, M = map(int,input().split())
A = list(map(int,input().split()))
hA = list(map(lambda x:x//2,A))
def lcm_of_list(nums):
    lcm = nums[0]
    for i in range(1,len(nums)):
        lcm = (lcm * nums[i])//gcd(lcm,nums[i])
    return lcm


def calc_2dewareru(num):
    temp = 0
    cnt = 0
    while num%2 == 0:
        num /= 2
        cnt += 1
    return cnt
wareru2 = calc_2dewareru(A[0])
for i in range(1,N):
    if calc_2dewareru(A[i]) != wareru2:
        print(0)
        exit()
temp = (M //lcm_of_list(hA))
if temp %2 == 0:
    print(temp//2)
else:
    print(temp//2+1)

# if ans%2 !=0:
#     ans = ans//2+1
# print(ans)
# ans = 0
# cur = lcm_of_list(hA)
# odd = 1
# while True:
#
#     if cur*odd <= M:
#         ans += 1
#     else:break
#     odd += 2
#print(ans)
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
D = [[0]*2 for _ in range(101010)]
E = [[] for _ in range(n)]


def dfs(cur, pre, d, id):
    D[cur][id] = d
    for nv in E[cur]:
        if nv != pre:
            dfs(nv, cur, d+1, id)


a -= 1
b -= 1
for i in range(n-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
dfs(a, a, 0, 0)
dfs(b, b, 0, 1)
max_d = 0
for i in range(n):
    if D[i][0] < D[i][1]:
        max_d = max(max_d, D[i][1]-1)
print(max_d)


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, a, b = map(int, input().split())
D = [[0]*2 for _ in range(101010)]
E = [[] for _ in range(n)]


def dfs(cur, pre, d, id):
    D[cur][id] = d
    for nv in E[cur]:
        if nv != pre:
            dfs(nv, cur, d+1, id)


a -= 1
b -= 1
for i in range(n-1):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    E[x].append(y)
    E[y].append(x)
dfs(a, a, 0, 0)
dfs(b, b, 0, 1)
max_d = 0
for i in range(n):
    if D[i][0] < D[i][1]:
        max_d = max(max_d, D[i][1]-1)
print(max_d)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().split())

answer = 0
for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= MOD
    answer += x
answer %= MOD
print(answer)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().split(),np.int64)

answer = 0
for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= MOD
    answer += x
answer %= MOD
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
import numpy as np
flagbox = np.zeros(1000).reshape(10,10,10)
flagtable = np.zeros(100).reshape(10,10)
flaglist = np.zeros(10)
# flagbox = [[[0]*10 for _ in range(10)] for _ in range(10)]
# flagtable = [[0]*10 for _ in range(10)]
# flaglist = [0]*10
for s in S:
    ss = int(s)
    for i in range(10):
        for j in range(10):
            if flagtable[i][j] == 1:
                flagbox[i][j][ss] = 1

    for i in range(10):
        if flaglist[i] == 1:
            flagtable[i][ss] = 1

    if flaglist[ss] == 0:
        flaglist[ss] = 1

# print sum of flagbox
print(int(np.sum(flagbox)))




Fixed submission:
N = int(input())
S = input()
# import numpy as np
# flagbox = np.zeros(1000).reshape(10,10,10)
# flagtable = np.zeros(100).reshape(10,10)
# flaglist = np.zeros(10)
flagbox = [[[0]*10 for _ in range(10)] for _ in range(10)]
flagtable = [[0]*10 for _ in range(10)]
flaglist = [0]*10
for s in S:
    ss = int(s)
    for i in range(10):
        for j in range(10):
            if flagtable[i][j] == 1:
                flagbox[i][j][ss] = 1

    for i in range(10):
        if flaglist[i] == 1:
            flagtable[i][ss] = 1

    if flaglist[ss] == 0:
        flaglist[ss] = 1

# print sum of flagbox
#print(int(np.sum(flagbox)))
ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            if flagbox[i][j][k] == 1:
                ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import factorial
X, Y = map(int,input().split())

MOD = 10**9+7


if (X+Y)%3 != 0:
    ans = 0
else:
    N = int((X+Y)/3)

    if X >= Y:
        #K = N - (X - Y) + 1
        K = N/2 - (X - Y) + 1

    else:
        K = N/2 + (Y - X) + 1

    #ans = factorial(N-1)/(factorial(N-K)*factorial(K-1))
    # ans = factorial(N+1-1)/(factorial(N-K+1)*factorial(K-1))
    # ans %= MOD
    bunsi = factorial(N)%MOD
    bunbo = (factorial(N-K+1)*factorial(K-1))%MOD
    ans = int(bunsi/bunbo)


#print(N)
#print(K)
print(ans)

Fixed submission:
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

X, Y = map(int, input().split())
if (X+Y) % 3 != 0 or not (X <= 2*Y and Y <= 2*X):
    print(0)
    exit()

n = (X+Y) // 3
r = Y - n
#print(n, r)
print(combination(n, r))

Buggy python submission (verdict: Runtime Error):
from math import factorial
X, Y = map(int,input().split())

MOD = 10**9+7


if (X+Y)%3 != 0:
    ans = 0
else:
    N = int((X+Y)/3)

    if X >= Y:
        #K = N - (X - Y) + 1
        K = N/2 - (X - Y) + 1

    else:
        K = N - (Y - X) + 1

    #ans = factorial(N-1)/(factorial(N-K)*factorial(K-1))
    ans = factorial(N+1-1)/(factorial(N-K+1)*factorial(K-1))
    ans %= MOD


#print(N)
#print(K)
print(ans)

Fixed submission:
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

X, Y = map(int, input().split())
if (X+Y) % 3 != 0 or not (X <= 2*Y and Y <= 2*X):
    print(0)
    exit()

n = (X+Y) // 3
r = Y - n
#print(n, r)
print(combination(n, r))
Buggy python submission (verdict: Time Limit Exceeded):
N, T = map(int, input().split())
A = [0]*N
B = [0]*N
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
dp = [[0]*(T) for _ in range(N+1)]
ans = 0
for i in range(N):
    for j in range(T):
        dp[i+1][j] = dp[i][j]
        ans = max(ans, dp[i][j] + AB[i][1])
        if j - AB[i][0] >= 0:
            dp[i+1][j] = max(dp[i][j], dp[i][j-AB[i][0]] + AB[i][1])
print(ans)


Fixed submission:
N, T = map(int, input().split())
A = [0]*N
B = [0]*N
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
dp = [[0]*(T) for _ in range(N+1)]
ans = 0
for i in range(N):
    for j in range(T):
        dp[i+1][j] = dp[i][j]
        ans = max(ans, dp[i][j] + AB[i][1])
        # 上は この時刻jまでで商品i-1個を入れた後に時間制約の無いi個目の商品を追加している
        if j - AB[i][0] >= 0:
            dp[i+1][j] = max(dp[i][j], dp[i][j-AB[i][0]] + AB[i][1])
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int,input().split()))
BIGNUM = 998244353

ans = 1
# 距離:頂点に対応する辞書
if D[0] != 0:
    ans = 0
distance_dict = {0:1}
for i in D[1:]:
    if not i in distance_dict:
        distance_dict[i] = 1
    else:
        distance_dict[i] += 1

#dist_list = list((distance_dict.keys())) # 0~N-1 一つでもとんでったらアウト。距離がない
#print(distance_dict)

for i in range(1,max(distance_dict.keys())+1):
    if not i in distance_dict:
        ans = 0
    else:
        ans *= distance_dict[i-1]**distance_dict[i] # どこにつながるかの候補とつながる点の数
print(ans%BIGNUM)

Fixed submission:
N = int(input())
D = list(map(int,input().split()))
BIGNUM = 998244353

ans = 1
# 距離:頂点に対応する辞書
if D[0] != 0:
    ans = 0
distance_dict = {0:1}
for i in D[1:]:
    if not i in distance_dict:
        distance_dict[i] = 1
    else:
        distance_dict[i] += 1

#dist_list = list((distance_dict.keys())) # 0~N-1 一つでもとんでったらアウト。距離がない
#print(distance_dict)

if distance_dict[0] != 1:
    print(0)
    exit()

for i in range(1,max(distance_dict.keys())+1):
    if not i in distance_dict: # 一つでもとんでったらアウト。距離がない。連結できない
        ans = 0
        print(0)
        exit()

    elif i != 0:
        ans *= (distance_dict[i-1]**distance_dict[i]) # どこにつながるかの候補とつながる点の数
print(ans%BIGNUM)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ok = 10**12
ng = -1


def check(time):
    shugyou = 0
    for i in range(N):
        if A[i]*F[i] > time:
            shugyou += A[i] - (time//F[i])
    return shugyou <= K


while ok - ng > 1:
    mid = (ok + ng)//2
    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ok = 10**12
ng = -1


def check(time):
    shugyou = 0
    for i in range(N):
        if A[i]*F[i] > time:
            shugyou += A[i] - (time//F[i])
    return shugyou <= K


while ok - ng > 1:
    mid = (ok + ng)//2
    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok)
Buggy python submission (verdict: Time Limit Exceeded):
N, M, L = map(int, input().split())

INF = float('inf')
d1 = [[INF]*N for _ in range(N)]


for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d1[a][b] = c
    d1[b][a] = c
for i in range(N):
    d1[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            d1[i][j] = min(d1[i][k] + d1[k][j], d1[i][j])

d2 = [[INF]*N for _ in range(N)]

for i in range(N):
    for j in range(N):
        if i == j:
            d2[i][j] = 0
        if d1[i][j] <= L and i != j:
            d2[i][j] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d2[i][j] = min(d2[i][k] + d2[k][j], d2[i][j])
Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if d2[s][t] == INF:
        print(-1)
    else:
        print(d2[s][t]-1)


Fixed submission:
N, M, L = map(int, input().split())

INF = float('inf')
d1 = [[INF]*N for _ in range(N)]


for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d1[a][b] = c
    d1[b][a] = c
for i in range(N):
    d1[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            d1[i][j] = min(d1[i][k] + d1[k][j], d1[i][j])

d2 = [[INF]*N for _ in range(N)]

for i in range(N):
    for j in range(N):
        if i == j:
            d2[i][j] = 0
        if d1[i][j] <= L and i != j:
            d2[i][j] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            d2[i][j] = min(d2[i][k] + d2[k][j], d2[i][j])
Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if d2[s][t] == INF:
        print(-1)
    else:
        print(d2[s][t]-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N%2:
    print((N+1)/(2*N))
else:
    print(0.5)N = int(input())
if N%2:
    print((N+1)/(2*N))
else:
    print(0.5)

Fixed submission:
N = int(input())
if N%2:
    print((N+1)/(2*N))
else:
    print(0.5)