Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
    while a[i] > 0 and b[i] > 0:
        a[i] -= 1
        b[i] -= 1
        cnt += 1
    if a[i] == 0 and b[i] > 0:
        while a[i+1] > 0 and b[i] > 0:
            a[i+1] -= 1
            b[i] -= 1
            cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    else:
        ans += a[i]
        b[i] -= a[i]
        if a[i+1] >= b[i]:
            ans += b[i]
            a[i+1] -= b[i]
        else:
            ans += a[i+1]
            a[i+1] = 0
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
s = input()

def cont(s):
    ret = []
    if s[0] == '0':
        ret.append(0)
    tgt = s[0]
    i = 0
    count = 0
    while i < len(s):
        if s[i] == tgt:
            count += 1
        else:
            ret.append(count)
            count = 1
            if tgt == '0': tgt = '1'
            else: tgt = '0'
        if i == len(s)-1:
            ret.append(count)
        i += 1
    return ret        
cont_s = cont(s)
if len(cont_s) <= 2*k+1:
    print(sum(cont_s))
else:
    acum = [sum(cont_s[i:i+2*k+1]) for i in range(0, n+2*k+1, 2)]
    print(max(acum))

### FIXED CODE ###

n, k = map(int, input().split())
s = list(map(int, list(input())))

i = 0
a = []
while i < n:
    l = 1
    while i+1 < n and s[i]==s[i+1]:
        l+=1
        i+=1
    a.append(l)
    i+=1

if s[0] == 0:
    a = [0] + a
if s[-1] == 0:
    a = a + [0]
n = len(a)

acum = [0]*(n+1)
for i in range(n):
    acum[i+1] = acum[i]+a[i]

ans = 0
for i in range(0, n, 2):
    end = min(i+2*k+1, n)
    ans = max(ans, acum[end] - acum[i])
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul  7 18:47:41 2020

@author: naoki
"""
import sys
def func():
    N, M = map(int, input().split())
    uvs = [list(map(lambda x:int(x)-1, input().split())) for _ in range(M)]
    S, T = map(lambda x:int(x)-1, input().split())
    
    roots = [[] for _ in range(N)]
    
    for uv in uvs:
        roots[uv[0]].append(uv[1])
    
    costs = [-10000]*(N)
    
    from collections import deque
    
    todo = deque([S])
    costs[S] = 0
    todo_set = set([S])
    
    while len(todo)>0:
        checking = todo.popleft()
        next_targets = deque([checking])
        for i in range(3):
            purposes = set()
            while len(next_targets) > 0:
                now = next_targets.pop()
                for root in roots[now]:
                    purposes.add(root)
            next_targets = deque(purposes)
        for next_target in next_targets:
            if costs[next_target] < 0 and next_target not in todo_set:
                costs[next_target] = costs[checking]+1
                todo.append(next_target)
                todo_set.add(next_target)
            if next_target == T:
                print(costs[next_target])
                sys.exit()
    print(-1)
if __name__ == "__main__":
    func()

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul  7 18:47:41 2020

@author: naoki
"""
import sys
import copy
def func():
    N, M = map(int, input().split())
    uvs = [list(map(lambda x:int(x)-1, input().split())) for _ in range(M)]
    S, T = map(lambda x:int(x)-1, input().split())
    
    roots = [[] for _ in range(N)]
    
    for uv in uvs:
        roots[uv[0]].append(uv[1])
    
    costs = [-10000]*(N)
    
    from collections import deque
    
    todo = deque([S])
    costs[S] = 0
    todo_set = set([S])
    
    layers = [set() for _ in range(3)]
    
    while len(todo)>0:
        checking = todo.popleft()
        next_targets = deque([checking])
        for i in range(3):
            purposes = set()
            while len(next_targets) > 0:
                now = next_targets.pop()
                for root in roots[now]:
                    if root not in layers[i]:
                        layers[i].add(root)
                        purposes.add(root)
            next_targets = purposes.copy()
        for next_target in next_targets:
            if costs[next_target] < 0 and next_target not in todo_set:
                costs[next_target] = costs[checking]+1
                todo.append(next_target)
                todo_set.add(next_target)
                if next_target == T:
                    print(costs[next_target])
                    sys.exit()
    print(-1)
if __name__ == "__main__":
    func()
### BUGGY CODE ###

n = int(input())
ns = list(map(int, input().split()))
ns = sorted(ns)
rslt = 0
for i in range(n):
    for j in range(i+1, n):
        a = ns[i]+ns[j]
        b = abs(ns[i]-ns[j])
        for k in range(j+1, n):
            if ns[k] < a and ns[k] > b:
                rslt += 1
            elif ns[k] >= a:
                break
print(rslt)

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
rslt = 0
for i in range(n-1):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        c = bisect.bisect_left(l, a+b)
        rslt += c-j-1
print(rslt)
### BUGGY CODE ###

#  入力
N = int(input())
A = [int(x) for x in input().split()]
 
# 初期化
dp = [[0] * (N+1) for _ in range(N+1)]
dp[0][0] = 0
 
for i in range(0,N):
 
    # 最も嬉しさの高い子供から場所を選択していく
    id = A.index(max(A))
    
    for x in range(0,i+1):
        y = i - x
        
        dp[x+1][y] = max(dp[x+1][y], dp[x][y] + A[id] * (id - x))
        dp[x][y+1] = max(dp[x][y+1], dp[x][y] + A[id] * (((N-1)-y) - id))
        
    A[id] = 0

ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])
print(ans)

### FIXED CODE ###

#  入力
N = int(input())
A = [int(x) for x in input().split()]

# 初期化
dp = [[0] * (N+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(0,N):

    # 最も嬉しさの高い子供から場所を選択していく
    a = max(A)
    id = A.index(a)
    
    for x in range(0,i+1):
        y = i - x

        d = dp[x][y]
        tmp = d + a * (id - x)
        if dp[x+1][y] < tmp:
        	dp[x+1][y] = tmp
        tmp = d + a * (((N-1)-y) - id)            
        if dp[x][y+1] < tmp:
        	dp[x][y+1] = tmp
        
    A[id] = 0

ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])
print(ans)
### BUGGY CODE ###

import bisect
n=int(input())
A=[int(input())]
for i in range(n-1):
  a=int(input())
  b=bisect.bisect_right(A,a,lo=0,hi=len(A))
  if b!=0 and A[b-1]<a:
    A[b-1]=a
  elif A[b-1]==a:
    b=bisect.bisect_right(A,a-1,lo=0,hi=len(A))
    if b!=0:
      A[b-1]=a
    else:
      A.insert(0,a)
  else:
    A.insert(0,a)
print(len(A))


### FIXED CODE ###

import bisect
from collections import deque
n=int(input())
A=deque([int(input())])

for i in range(n-1):
  a=int(input())
  b=bisect.bisect_left(A,a,lo=0,hi=len(A))
  if b==0:
    A.appendleft(a)
  else:
    A[b-1]=a
print(len(A))
### BUGGY CODE ###

a,b,n= list(map(int, input().split()))
ma=(a*n/b)//1-a*((n/b)//1)
for i in range(b-1,n+1,b):
    tmp=(a*i/b)//1-a*((i/b)//1)
    ma=max(tmp,ma)
print(int(ma))

### FIXED CODE ###

a,b,n= list(map(int, input().split()))
if b==1:
    print(0)
    exit(0)
ma=(a*n/b)//1-a*((n/b)//1)
for i in range(b-1,n+1,b):
    tmp=(a*i/b)//1-a*((i/b)//1)
    ma=max(tmp,ma)
print(int(ma))
### BUGGY CODE ###

N, M, K = map(int, input().split())

DIV = 10**9+7

def comb(l, r):
    if l == 0:
        return 1
    val = 1
    for i in range(r, r-l, -1):
        val *= i
    for i in range(l, 0, -1):
        val //= i
    return val

def calc_rec_num(N, M, xi, xj, yi, yj):
    cnt = 1
    cnt *= N - yi
    cnt *= M - yj
    # rotate
    if xi != yi and xj != yj:
        cnt *= 2
    return cnt


p = comb(K-2, N*M-2)
#print(K-2, N*M-2, p)
ans = 0
for i in range(N):
    for j in range(M):
        if i == 0 and j == 0:
            continue
        d = i+j
        #print(i, j, calc_rec_num(N, M, 0, 0, i, j))
        ans += d * calc_rec_num(N, M, 0, 0, i, j)
        if ans > DIV:
            ans %= DIV
        #print(ans)

print((ans*p)%DIV)


### FIXED CODE ###

from math import factorial
N, M, K = map(int, input().split())

MOD = 10**9+7

fact = [1] * (N*M+1)
for i in range(2, N*M+1):
    fact[i] = fact[i-1] * i % MOD

def comb(n, r):
    r = n-r if n-r < r else r
    return fact[n] * pow(fact[r], MOD-2, MOD) * pow(fact[n-r], MOD-2, MOD) % MOD

p = comb(N*M-2, K-2)
ans = 0
for i in range(N):
    for j in range(M):
        if i == 0 and j == 0:
            continue
        d = i+j
        cnt = (N-i) * (M-j)
        if i != 0 and j != 0:
            cnt *= 2
        ans += d * cnt % MOD
ans = ans * p % MOD

print(ans)
### BUGGY CODE ###

n,q = map(int,input().split())
y = [[] for _ in range(n)]
c = [0 for _ in range(n)]
for _ in range(n-1):
  ai,bi = map(int,input().split())
  y[ai-1].append(bi-1)
  y[bi-1].append(ai-1)
for _ in range(q):
  pi,xi = map(int,input().split())
  c[pi-1] += xi
z = [[0,-1]]
while z:
  j,b = z.pop(0)
  for yj in y[j]:
    if yj != b:
      z.append([yj,j])
      c[yj] += c[j]
for i in range(n):
  print(c[i],end=" ")

### FIXED CODE ###

from collections import deque
def submit():
  n,q = map(int,input().split())
  y = [[] for _ in range(n)]
  c = [0]*n
  for _ in range(n-1):
    ai,bi = map(int,input().split())
    y[ai-1].append(bi-1)
    y[bi-1].append(ai-1)
  for _ in range(q):
    pi,xi = map(int,input().split())
    c[pi-1] += xi
  z = deque([[0,-1]])
  while z:
    j,b = z.popleft()
    for yj in y[j]:
      if yj != b:
        z.append([yj,j])
        c[yj] += c[j]
  for i in range(n):
    print(c[i],end=" ")
submit()
### BUGGY CODE ###

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A)

for a in A:
    sum = 0
    for i in c:
        if a ==i:
            n =c[i]-1
        else:
            n=c[i]
        sum += n * (n - 1) // 2
    print(sum)



### FIXED CODE ###

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

import collections 
c=collections.Counter(A)
sum=0
for i in c:
  sum+=c[i]*(c[i]-1)//2  
for a in A:
  print(sum - c[a]*(c[a]-1)//2 + (c[a]-1)*(c[a]-2)//2)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
mod = 10**9+7

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    L = max(A[-1], X)

    dp = [[0]*N for _ in range(L+1)]
    a = A[0]
    for x in range(L+1):
        dp[x][0] = x%a

    dp1 = [[0]*N for _ in range(L+1)] #累積和見たいな
    for n in range(1, N):
        a = A[n]
        for x in range(L+1):
            dp1[x][n] = ((n-1) * dp1[x][n-1] + dp[x][n-1]) % mod
        for x in range(L+1):
            dp[x][n] = dp1[x%a][n]

    ans = 0
    t = 1
    for n in reversed(range(N)):
        ans = (ans + dp[X][n]*t) % mod
        t = t * n % mod

    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
mod = 10**9+7

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    L = max(A[-1], X)

    dp = [[0]*N for _ in range(L+1)]
    a = A[0]
    for x in range(L+1):
        dp[x][0] = x%a

    dp1 = [0 for _ in range(L+1)] #累積和見たいな
    for n in range(1, N):
        a = A[n]
        for x in range(L+1):
            dp1[x] = ((n-1) * dp1[x] + dp[x][n-1]) % mod
            dp[x][n] = dp1[x%a]

    ans = 0
    t = 1
    for n in reversed(range(N)):
        ans = (ans + dp[X][n]*t) % mod
        t = t * n % mod

    print(ans)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

import itertools
n=int(input())
s=input()
k=list(set(s))

d = {}

counta=0
for i in k:
    p=s.count(i)
    d[i]=p
    counta+=p



for i in range(2,len(k)+1):
    li=itertools.combinations(k,i) 
    for h in li:
        z="".join(h)
        q=d[z[0:(len(h)-1)]]*d[z[-1]]
        d[z]=q
        counta+=q
    
print(counta%(10**9+7))

### FIXED CODE ###

n=int(input())
s=input()
k=list(set(s))
d = {i: s.count(i) for i in k}
counta=0

for i in k:
    counta=counta*d[i]+d[i]+counta


print(counta%(10**9+7))
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
a = int()
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(i,j,k)

print(ans)

### FIXED CODE ###

import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
K = int(input())
B = list()
a = int()
b = int()
c = int()
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(i,j,k)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N=int(input())
P=[list(map(int,input().split())) for i in range(N)]
ANS=[1<<60]*(N+1)
ANS[-1]=0

DP1=[1<<60]*N

for i in range(N):
    x,y,p=P[i]
    DP1[i]=min(abs(x),abs(y))*p

ANS[0]=sum(DP1)

def dfs(DP,now,used):
    if used==N-1:
        return
    for next_town in range(now,N):
        x,y,p=P[next_town]

        DP2=list(DP)
        S=0
        for i in range(N):
            DP2[i]=min(DP2[i],abs(P[i][0]-x)*P[i][2])
            S+=DP2[i]

        #print(DP,now,used,next_town,DP2)
            
        ANS[used+1]=min(ANS[used+1],S)
        dfs(tuple(DP2),next_town+1,used+1)



        DP2=list(DP)
        S=0
        for i in range(N):
            DP2[i]=min(DP2[i],abs(P[i][1]-y)*P[i][2])
            S+=DP2[i]

        #print(DP,now,used,next_town,DP2)
            
        ANS[used+1]=min(ANS[used+1],S)
        dfs(tuple(DP2),next_town+1,used+1)

dfs(tuple(DP1),0,0)

print(*ANS)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N=int(input())
P=[list(map(int,input().split())) for i in range(N)]
ANS=[1<<60]*(N+1)
ANS[-1]=0

DP1=[20000]*N

S=0
for i in range(N):
    x,y,p=P[i]
    DP1[i]=min(abs(x),abs(y))
    S+=DP1[i]*p

ANS[0]=S

def dfs(DP,now,used):
    if used==N-1:
        return
    for next_town in range(now,N):
        x,y,p=P[next_town]

        DP2=list(DP)
        S=0
        for i in range(N):
            DP2[i]=min(DP2[i],abs(P[i][0]-x))
            S+=DP2[i]*P[i][2]

        #print(DP,now,used,next_town,DP2)
            
        ANS[used+1]=min(ANS[used+1],S)
        if S!=0:
            dfs(DP2,next_town+1,used+1)

        DP2=list(DP)
        S=0
        for i in range(N):
            DP2[i]=min(DP2[i],abs(P[i][1]-y))
            S+=DP2[i]*P[i][2]

        #print(DP,now,used,next_town,DP2)
            
        ANS[used+1]=min(ANS[used+1],S)
        if S!=0:
            dfs(DP2,next_town+1,used+1)

dfs(DP1,0,0)

for i in range(1,N):
    ANS[i]=min(ANS[i],ANS[i-1])

print(*ANS)
### BUGGY CODE ###

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0

for i in range(n-1, -1, -1):
    for j in range(i-1, -1, -1):
        imin = 0
        imax = j-1

        while imin <= imax:
            mid = (imin + imax)//2
            if l[mid] + l[j] >= l[i]+1:
                imax = mid-1
            else:
                imin = mid+1

        cnt += j-imin

print(cnt)

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        x = bisect.bisect_left(l, l[i]+l[j])
        cnt += x-j-1

print(cnt)
### BUGGY CODE ###

from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
P = [p for _, _, p in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        stateX <<= 1
        stateY <<= 1
        if s == 0: M -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1

    cost = sum(map(min, zip(costX[stateX], costY[stateY])))
    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from numba import njit
import numpy as np
INF = 10**18

@njit('(i8, i8[:,:])')
def solve(N, XYP):
    X = XYP[:, 0]
    Y = XYP[:, 1]

    def calcCost(sign, A):
        ret = np.ones((1 << N, N), dtype=np.int64) * INF
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i in range(N):
                xyp = XYP[i]
                cost = abs(xyp[sign])
                for z in useA:
                    cost = min(cost, abs(xyp[sign] - z))
                ret[state][i] = cost * xyp[2]
        return ret

    costX = calcCost(0, X)
    costY = calcCost(1, Y)
    ans = np.ones(N + 1, dtype=np.int64) * INF

    for state in range(pow(3, N)):
        stateX = 0
        stateY = 0
        M = N
        for _ in range(N):
            state, r = divmod(state, 3)
            stateX <<= 1
            stateY <<= 1
            if r == 0: M -= 1
            if r == 1: stateX |= 1
            if r == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = 0
        for i in range(N):
            cost += min(cx[i], cy[i])
        ans[M] = min(ans[M], cost)

    for a in ans:
        print(a)

def sol():
    N = int(input())
    XYP = np.asarray([list(map(int, input().split())) for _ in range(N)])
    solve(N, XYP)

sol()
### BUGGY CODE ###

from decimal import Decimal
import sys
input=sys.stdin.readline

def factorization(n):
    arr={}
    tmp=n
    for i in range(2,int(n**0.5)+1):
        if(tmp%i==0):
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr[i]=cnt
    if(tmp!=1):
        arr[tmp]=1
    return arr

N=int(input())
A=[int(Decimal(input())*Decimal(1000000000)) for i in range(N)]
dic=[None for i in range(N)]
dp=[[0]*51 for i in range(51)]

for i in range(N):
    d=factorization(A[i])
    dp[d.get(2,0)][d.get(5,0)]+=1
    dic[i]=d

for i in reversed(range(51)):
    for j in reversed(range(51)):
        if i==50 and j==50:
            continue
        if i==50:
            dp[i][j]+=dp[i][j+1]
        elif j==50:
            dp[i][j]+=dp[i+1][j]
        else:
            dp[i][j]+=dp[i][j+1]+dp[i+1][j]-dp[i+1][j+1]
ans=0

for i in range(N):
    d=dic[i]
    a,b=d.get(2,0),d.get(5,0)
    t,f=max(18-a,0),max(18-b,0)
    res=dp[t][f]
    if t<=a and f<=b:
        res-=1
    ans+=res
print(ans//2)

### FIXED CODE ###

from decimal import Decimal
import sys
input=sys.stdin.readline

    
def w(i,m):
    cnt=0
    while(i>0 and i%m==0):
        i//=m
        cnt+=1
    return cnt

N=int(input())
A=[int(Decimal(input())*Decimal(1000000000)) for i in range(N)]
dic=[None for i in range(N)]
dp=[[0]*51 for i in range(51)]

for i in range(N):
    d={}
    d[2],d[5]=w(A[i],2),w(A[i],5)
    dp[d[2]][d[5]]+=1
    dic[i]=d

for i in reversed(range(51)):
    for j in reversed(range(51)):
        if i==50 and j==50:
            continue
        if i==50:
            dp[i][j]+=dp[i][j+1]
        elif j==50:
            dp[i][j]+=dp[i+1][j]
        else:
            dp[i][j]+=dp[i][j+1]+dp[i+1][j]-dp[i+1][j+1]
ans=0

for i in range(N):
    d=dic[i]
    a,b=d[2],d[5]
    t,f=max(18-a,0),max(18-b,0)
    res=dp[t][f]
    if t<=a and f<=b:
        res-=1
    ans+=res
print(ans//2)
### BUGGY CODE ###

n,h =map(int,input().split())
a,b = [0]*n,[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
A = max(a)
s = list()
for i in range(n):
    if b[i] > A:
        s.append(b[i])
s.sort()
s.reverse()
c = sum(s)
if c < h:
    print(len(s) + (h-c)//A + [1,0][(h-c)%A==0])
else:
    for i in range(len(s)):
        if sum(s[:i+1]) >= h:
            print(i+1)
            break

### FIXED CODE ###

n,h =map(int,input().split())
a,b = [0]*n,[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
A = max(a)
s = list()
for i in range(n):
    if b[i] > A:
        s.append(b[i])
s.sort()
s.reverse()
c = sum(s)
if c < h:
    print(len(s) + (h-c)//A + [1,0][(h-c)%A==0])
else:
    S = 0
    for i in range(len(s)):
        S += s[i]
        if S >= h:
            print(i+1)
            break
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort()
f.sort()
f = f[::-1]

import heapq
af = []
heapq.heapify(af)
for i in range(len(a)):
    heapq.heappush(af, [a[i] * f[i] * -1, f[i]])

for i in range(k):
    tmp = heapq.heappop(af)
    tmp[0] = (tmp[0] // tmp[1] + 1) * tmp[1]
    heapq.heappush(af, tmp)

print(max(heapq.heappop(af)[0] * -1, 0))


### FIXED CODE ###

n, k = map(int, input().split())
aa = list(map(int, input().split()))
ff = list(map(int, input().split()))

a = sorted(aa, reverse=True)
f = sorted(ff)

def C(x):
    ret = 0
    for i in range(n):
        ret += max(0, a[i] - x // f[i])
    return ret

lb = -1
ub = 10 ** 12 + 1
while (ub - lb) > 1:
    mid = (ub + lb) // 2

    if C(mid) > k:
        lb = mid
    else:
        ub = mid
print(ub)
### BUGGY CODE ###

import heapq
class Graph:
    def __init__(self,w_v,w_e):
        super().__init__()
        self.size = len(w_v)
        self.w_v = [v_i for v_i in w_v]#value of vartex
        self.w_e = [{} for _ in [0]*self.size]

        self.maxw = 0

        self.neighbor = [[] for _ in [0]*self.size]
        for a_i,b_i,w_i in w_e:
            self.w_e[a_i][b_i] = w_i#weight of edge
            self.w_e[b_i][a_i] = w_i#weight of edge

            self.neighbor[a_i].append(b_i)
            self.neighbor[b_i].append(a_i)
            self.maxw+=w_i

    def dijkstra(self,v_n):
        d = [self.maxw]*self.size
        d[v_n] = 0
        prev = [-1]*self.size

        queue = []
        for i,d_i in enumerate(d): heapq.heappush(queue,(d_i,i))
        
        while len(queue)>0:
            d_u,u = queue.pop()
            if d[u]<d_u :continue
            for v in self.neighbor[u]:
                alt = d[u]+self.w_e[u][v]
                if d[v]>alt:
                    d[v] = alt
                    prev[v] = u
                    heapq.heappush(queue,(alt,v))

        return d,prev

def main():
    n,x,y = tuple([int(t)for t in input().split()])

    w_v = [0]*n
    w_e = [(i,i+1,1) for i in range(n-1)]
    w_e.append((x-1,y-1,1))

    g = Graph(w_v,w_e)

    distance = [g.dijkstra(i)[0] for i in range(n)]

    res = [0]*n
    for dmin_ in distance:
        for d in dmin_:
            res[d] += 1

    for r in res[1:n]:
        print(r//2)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n,x,y = tuple([int(t)for t in input().split()])

    dmin = [[n]*n for _ in [0]*n]

    nlist = list(range(n))

    for i in range(n):
        for j in range(i,n):
            dmin[i][j] = j-i
            dmin[j][i] = j-i

    for i in range(x):
        for j in range(y-1,n):
            dmin[i][j] -= y-x-1
            dmin[j][i] -= y-x-1


    for i in range(n):
        for j in range(x,(x+y)//2):
            t = dmin[j][x-1]+dmin[x-1][i]
            if dmin[i][j]>t:
                dmin[i][j] = t
                dmin[j][i] = t

        for j in range((x+y)//2,y):
            t = dmin[j][y-1]+dmin[y-1][i]
            if dmin[i][j]>t:
                dmin[i][j] = t
                dmin[j][i] = t

    res = [0]*(n+1)
    for dmin_ in dmin:
        for d in dmin_:
            res[d] += 1

    for r in res[1:n]:
        print(r//2)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())

X = list(map(int,input().split()))

add = []

for p in range(99999):
    psum = 0
    for i in range(N):
        power = (X[i] - p)**2
        psum = psum + power
        i = i + 1
    add.append(psum)
    
print(min(add))

### FIXED CODE ###

N = int(input())

X = list(map(int,input().split()))

add = []

for p in range(1000):
    psum = 0
    for i in range(N):
        power = (X[i] - p)**2
        psum = psum + power
        i = i + 1
    add.append(psum)
    
print(min(add))