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

# -*- coding: utf-8 -*-
import sys
L, R = list(map(int, str(input()).split()))

output = 2 * pow(10,9)
for i in range(L,R+1):
    for j in range(i+1, R+1):
        if (i*j) % 2019 < output:
            output =  (i*j) % 2019
            if output == 0:
                break
print(output)

### FIXED CODE ###

L, R = list(map(int, str(input()).split()))

# L と Rの差が十分に大きければ、答えは0になる
# それ以外の状況であれば愚直に計算しても大した計算量ではない。

MOD = 2019
ouput = 2020 * 2020
for i in range(L, R + 1):
    for j in range(L, R + 1):
        if j > i and ouput > (i * j) % MOD:
            ouput = (i * j) % MOD
            if ouput == 0:
                print(ouput)
                exit()

print(ouput)
### BUGGY CODE ###

import math
ans = math.inf
n = int(input())
c = list(map(int, input().split()))
s, a = 0, 0
for i in range(n - 1):
    s = sum(c[:i+1])
    a = sum(c[i+1:])
    ans = min(ans, abs(s-a))
print(ans)


### FIXED CODE ###

import math
ans = math.inf
n = int(input())
c = list(map(int, input().split()))
acm = [0]*(n+1)
for i, v in enumerate(c, 1):
    acm[i] += acm[i-1] + v

s, a = 0, acm[n]
for i in range(1, n):
    s = acm[i]
    ans = min(ans, abs((a-s)-s))

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

n = int(input())
s = input()

result = 10e6

for i in range(n):
    a = s[:i]
    b = s[i+1:]
    result = min(result, a.count('W') + b.count('E'))

print(result)


### FIXED CODE ###

n = int(input())
s = input()

e = [0 for _ in range(n)]
w = [0 for _ in range(n)]

for i in range(1, n):
    w[i] = w[i - 1] + 1 if s[i - 1] == 'W' else w[i - 1]
    e[-i - 1] = e[-i] + 1 if s[-i] == 'E' else e[-i]

res = [0 for _ in range(n)]

for i in range(n):
    res[i] = w[i] + e[i]

print(min(res))
### BUGGY CODE ###

#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------


s = input()
q = int(input())

r=0

for i in range(q):
	t = input()
	
	if t=='1':
		r = (r+1)%2
#		p("t,r,s",t,r,s)
		continue
	
	_,f,c = t.split()

	z=r
	if f=='1': z =  r
	if f=='2': z = (r+1)%2
	
	if z==0: s = c + s
	if z==1: s = s + c

#	p("t,r,_,f,c,z,s","[",t,"]",r,_,f,c,z,s)

if (r==0):
	print(s)
else:
	print(s[::-1])


	
	

### FIXED CODE ###

#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
s = input()
q = int(input())

r=0

a=""
z=""

for i in range(q):
	t = input()
	
	if t=='1':
		if r==0:
			r=1
		else:
			r=0
#		p("t,r,s",t,r,s)
		continue
	
	_,f,c = t.split()

	if f=='1':
		if r==0: a = a + c
		if r==1: z = z + c
	if f=='2':
		if r==0: z = z + c
		if r==1: a = a + c


#	p("t,r,_,f,c,x,s","[",t,"]",r,_,f,c,x,s)

ans=""
if (r==0):
	ans = a[::-1] + s + z
else:
	ans = z[::-1] + s[::-1] + a

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

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

MOD = 10**9 + 7

def comb(n, r):
    if n < r or n < 0 or r < 0:
        return 0

    n += 1
    over = 1
    under = 1
    for i in range(1,r + 1):
      over *= (n - i) % MOD
      under *= i % MOD
    return over * pow(under, MOD - 2, MOD) % MOD

if (X + Y) % 3 != 0:
    print(0)
else:
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3
    print(comb(a+b, a))



### FIXED CODE ###

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

MOD = 10**9 + 7

def comb(n, r):
    if n < r or n < 0 or r < 0:
        return 0

    n += 1
    over = 1
    under = 1
    for i in range(1,r + 1):
      over = over * (n - i) % MOD
      under = under * i % MOD
    return over * pow(under, MOD - 2, MOD) % MOD

if (X + Y) % 3 != 0:
    print(0)
else:
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3
    print(comb(a+b, a))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=[]
for j in range(1,N+1):
    for i in range(N): 
        if A[i]==j:
            ans.append(i+1)
print(*ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = [0] * N
for i, a in enumerate(A):
    ans[a-1] = i+1
print(*ans)
### BUGGY CODE ###

import copy

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
dis = copy.deepcopy(a)

def warshall_floyd(dis):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])
    return dis

data = warshall_floyd(dis)
flag = True
for i in range(n):
    for j in range(i + 1, n):
        if data[i][j] < a[i][j]:
            flag = False
            break
    if flag == False:
        break
if flag == False:
    print(-1)
else:
    count = 0
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(n):
                if k == i or k == j:
                    continue
                if data[i][k] + data[k][j] == data[i][j]:
                    break
            else:
                count += data[i][j]
    print(count)

### FIXED CODE ###

import copy

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
dis = copy.deepcopy(a)

def warshall_floyd(dis):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])
    return dis

data = warshall_floyd(dis)
flag = True
for i in range(n):
    for j in range(i + 1, n):
        if data[i][j] < a[i][j]:
            flag = False
            break
    if flag == False:
        break
if flag == False:
    print(-1)
else:
    count = 0
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(n):
                if k == i or k == j:
                    continue
                if data[i][k] + data[k][j] == data[i][j]:
                    break
            else:
                count += data[i][j]
    print(count)
### BUGGY CODE ###

n,a,b = map(int, input().split())        
X,Y = 1,1
for i in range(b):
    X *= n-i
    X %= 10**9+7
    Y *= i+1
    Y %= 10**9+7

    if a-1 == i:
        Xa,Ya = X,Y

comb_a = (Xa*pow(Ya,10**9+5))%(10**9+7)
comb_b = (X*pow(Y,10**9+5))%(10**9+7)

result = pow(2,n)-1-comb_a-comb_b
print(result if result>=0 else result+10**9+7)

### FIXED CODE ###

def pow_self(x,n):
    ans = 1
    while n>0:
        if n&1 == 1:
            ans = (ans*x)%(10**9+7)
            
        x = (x*x)%(10**9+7)
        n >>= 1
    return ans

  
n,a,b = map(int, input().split())        
X,Y = 1,1
for i in range(b):
    X *= n-i
    X %= 10**9+7
    Y *= i+1
    Y %= 10**9+7

    if a-1 == i:
        Xa,Ya = X,Y

comb_a = (Xa*pow_self(Ya,10**9+5))%(10**9+7)
comb_b = (X*pow_self(Y,10**9+5))%(10**9+7)

result = pow_self(2,n)-1-comb_a-comb_b
while result <0:
    result += 10**9+7
print(result)
### BUGGY CODE ###

import array

def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count

def merge(left, right):
    lpos = 0
    rpos = 0
    rcount = 0
    merged = array.array('L', [])
    len_left = len(left)
    len_right = len(right)
    while lpos < len_left and rpos < len_right:
        if left[lpos] < right[rpos]:
            merged.append(left[lpos])
            lpos += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            rcount += len(left[lpos:])
    
    if left[lpos:]:
        merged.extend(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
    
    return merged, rcount
    
if __name__ == '__main__':
    n = int(raw_input())
    A = array.array('L', map(int, raw_input().split()))
    
    sorted, count = merge_sort(A)
    #print ' '.join(str(x) for x in sorted)
    print count

### FIXED CODE ###

from array import array

def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count

def merge(left, right):
    lpos = 0
    rpos = 0
    rcount = 0
    merged = array('I', [])  # List is too slow. Use an array instead.
    len_left = len(left)
    len_right = len(right)
    while lpos < len_left and rpos < len_right:
        if left[lpos] < right[rpos]:
            merged.append(left[lpos])
            lpos += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            #rcount += len(left[lpos:])
            rcount += len_left - lpos
    
    if left[lpos:]:
        merged.extend(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
    
    return merged, rcount
    
if __name__ == '__main__':
    n = int(raw_input())
    A = array('I', map(int, raw_input().split()))
    
    sorted, count = merge_sort(A)
    #print ' '.join(str(x) for x in sorted)
    print count
### BUGGY CODE ###

N,D,A=map(int,input().split())
XH=[]
for _ in range(N):
  x,h=map(int,input().split())
  XH.append([x,h])
XH=sorted(XH, key=lambda x:x[0])
X=[XH[i][0] for i in range(N)]
H=[XH[i][1] for i in range(N)]

import numpy as np
from bisect import bisect_right

H=np.array(H)
ans=0

for i in range(N):
  if H[i]<=0:
    continue
  else:
    xj=2*D+X[i]
    j=bisect_right(X, xj)
    att=[H[i]//A if H[i]%A==0 else H[i]//A+1]
    H[i:j]-=A*att[0]
    ans+=att[0]
#print(H)
print(ans)

### FIXED CODE ###

N,D,A=map(int,input().split())
XH=[]
for _ in range(N):
  x,h=map(int,input().split())
  XH.append([x,h])
XH=sorted(XH, key=lambda x:x[0])
X=[XH[i][0] for i in range(N)]
H=[XH[i][1] for i in range(N)]
from math import ceil
from bisect import bisect_right
imos=[0]*(N+1)
hit=0
ans=0
for i in range(N):
  hit+=imos[i]
  restH=H[i]-hit*A
  if restH>0:
    ans+=ceil(restH/A)
    hit+=ceil(restH/A)
    ind=bisect_right(X,X[i]+2*D)
    imos[ind]-=ceil(restH/A)
print(ans)
### BUGGY CODE ###

# B
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*(n+1)
 
for i in range(2, n+1):
    c_list = []
    if i-2 >= k:
        for j in range(1,k+1):
            c_list.append(dp[i-j] + abs(h[i-1-j] - h[i-1]))
        dp[i] = min(c_list)
    else:
        for j in range(1, i):
            c_list.append(dp[i-j] + abs(h[i-1-j] - h[i-1]))
        dp[i] = min(c_list)
print(dp[-1])

### FIXED CODE ###

# B
import numpy as np
N, K = map(int, input().split())
h = np.array(input().split(), dtype="int32")
dp = np.zeros(N, dtype="int32")
 
for i in range(1, N):
    if i < K:
        dp[i] = np.min(dp[:i] + np.abs(h[i]-h[:i]))
    else:
        dp[i] = np.min(dp[i-K:i] + np.abs(h[i]-h[i-K:i]))
print(dp[-1])
### BUGGY CODE ###

#!/home/ryo/.pyenv/versions/anaconda3-2019.03/envs/hoge/bin/python
import sys

lim=10**9+7
N,M = map(int,input().split())
A=[]
for i in range(0,M):
    A.append(int(input()))

memo = [0] * (N+1)
memo[0]=1
for i in range(0,M-1):
    if A[i+1] - A[i] == 1:
        print(0)
        sys.exit()
if not 2 in A:
    memo[1]=1
for i in range(2, N+1):
    if not i in A:
        if not ((i-1 in A) or (i-2 in A)):
            memo[i] = (memo[i - 1] + memo[i - 2]) % lim
        elif i-1 in A:
            memo[i] = memo[i - 2]
        elif i-2 in A:
            memo[i] = memo[i - 1]
        elif (i-1 in A) and (i-2 in A):
            print(0)
            sys.exit()
print(memo[-1])


### FIXED CODE ###

#!/home/ryo/.pyenv/versions/anaconda3-2019.03/envs/hoge/bin/python
import sys

lim=10**9+7
N,M = map(int,input().split())
A = set([int(input()) for _ in range(M)])
memo = [0] * (N+1)
memo[0]=1

if not 1 in A:
    memo[1]=1
for i in range(2, N+1):
    if not i in A:
        memo[i] = (memo[i - 1] + memo[i - 2]) % lim
print(memo[-1])
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()
lr_list = [list(map(int, input().split())) for i in range(Q)]

for lr in lr_list:
    tmp = (S[lr[0] - 1:lr[1]]).replace("G","").replace("T","")
    print(tmp.count("AC")) 

### FIXED CODE ###

N,Q = map(int,input().split())
S = input()
lr_list = [list(map(int, input().split())) for i in range(Q)]

ac_list  = [0]*N
cnt = 0
for i in range(N-1):
    if i < len(S) and S[i:i+2] == "AC":
        cnt += 1
    ac_list[i+1] = cnt
        
for lr in lr_list:
    print(ac_list[lr[1]-1] - ac_list[lr[0]-1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
A.sort() # 一応

count = 0
while A:
    new = []
    b = A[0]
    for a in A[1:]:
        if a % b > 0: # bで割れなければ続投
            new.append(a)
    # かぶりがないなら
    if len(A) > 1:
        if b < A[1]:
            count += 1
    else: # 最後なら
        count += 1

    A = new


print(count)


### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split()]
D=set()
S=set()
for i in range(N):
    if A[i] in S:
        D.add(A[i]) # ダブったやつ
    else:
        S.add(A[i])# かぶり除去
M=max(S) #最大値
X=[1 for i in range(M+1)] #M個の1のリスト
for a in S:
    if a in D:# かぶってたらフラグ除去
        X[a]=0
    for i in range(2*a,M+1,a): # aのN倍をフラグ除去
        X[i]=0
ans=0
for i in range(N):
    if X[A[i]]==1:
        ans+=1
print(ans)
### BUGGY CODE ###

n = int(input())
a = input().split()
b = []
for i in range(n):
    b.append(a.pop(0))
    b.reverse()
    # print(b)
ans = ''
for i in b:
    ans += i
    ans += ' '
print(ans[:-1])

### FIXED CODE ###

from collections import deque

n = int(input())
b = deque()
flag = 1
for i in input().split():
    if flag > 0:
        b.append(i)
    else:
        b.appendleft(i)
    flag *= -1
if flag < 0:
    b.reverse()
print(' '.join(b))
### BUGGY CODE ###

s=str(input())
q=int(input())
l=[list(map(str,input().split())) for i in range(q)]
#print(l)
ans=s
for i in range(q):
	if l[i][0]=='1':
		ans=ans[::-1]
	else:
		if l[i][1]=='1':
			ans=l[i][2]+ans
		else:
			ans=ans+l[i][2]
print(ans)





### FIXED CODE ###

from collections import deque
ans=deque()
ans.append(str(input()))
q=int(input())
l=[list(map(str,input().split())) for i in range(q)]
#print(l)
c=0
for i in range(q):
	if l[i][0]=='1':
		c+=1
	else:
		if c%2==0:
			if l[i][1]=='1':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
		else:
			if l[i][1]=='2':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
A="".join(map(str,list(ans)))
if c%2==1:
	print(A[::-1])
else:
	print(A)
### BUGGY CODE ###

def ans(p,k):
    if k==1:
        return 1 # 便宜上
    elif k==2:
        if p[-1]==2:
            return 1
        else:
            return 0
    else:
        if p[-1]==k:
            return 1+ans(p[:-2],k-2)
        else:
            return ans(p[:-1],k-1)

N=int(input())
p=list(map(int,input().split()))

print(ans(p,N))

### FIXED CODE ###

N=int(input())
p=list(map(int,input().split()))

ans=0
i=0
while i <N:
    if p[i]==i+1:
        ans+=1
        i+=2
    else:
        i+=1

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

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

for i in range(N):
    sum = 0

    for j in range(N - 1):
        if i + 1 == A[j]:
            sum += 1
    
    print(sum)


### FIXED CODE ###

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

sum =[0] * N

for i in range(N - 1):
    num = A[i - 1] - 1
    sum[num] += 1

for i in range(N):
    print(sum[i])
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
t=[0]*N
for i in range(N):
    t[i]=(A.index(i+1))+1

    print(t[i],end=' ')

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
t=[0]*N
for idx,i in enumerate(A):
    t[i-1]=idx+1

print(*t)
### BUGGY CODE ###

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

ws = list(map(int, sys.stdin.read().split()))
h = sum(ws)
p = h // k


def isEnough(A, n, k, w):
    one = w
    count = 0
    for a in A:
        if one < a:
            count += 1
            if count < k:
                one = w
            else:
                return False
        dif = one - a
        if dif < 0:
            return False
        else:
            one = dif
    return True

while not isEnough(ws, n, k, p):
    p += 1

print(p)

### FIXED CODE ###

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

ws = list(map(int, sys.stdin.read().split()))

def check(A, n, k, mid):
    j = 0
    for i in range(k):
        p = mid
        s = 0
        while (s + A[j]) <= p:
            s += A[j]
            j += 1
            if ( j == n ):
                return n
    return j

def solve(A, n, k):
    h = 100000 * 10000
    l = 0
    while 1 < (h - l):
        mid = (h + l) // 2
        v = check(A, n, k, mid)
        if v < n:
            l = mid
        else:
            h = mid
    return h

print(solve(ws, n, k))
### BUGGY CODE ###

# 考えると、隣り合う列は結局 2*H 回ずることになり、
# それぞれの列間について最適な沈め順を見つけると、
# その順序関係を崩さないように全体の順番も構築できる（トポロジカルソートみたいに）ので、
# 各列間の最適解を求めて総和をとればいい

def accumulate_reverse(S1, S2):
    res = [0]
    c = 0
    for i in range(min(len(S1), len(S2))):
        if S1[i] == S2[i]:
            c += 1
        res.append(c)
    res.reverse()
    return res

inf = 10**8
H, W = map(int, input().split())
C = [input() for _ in range(H)]
C_T = list(zip(*C))
C_T = ["".join(s) for s in C_T]
ans = 0
for C1, C2 in zip(C_T[:-1], C_T[1:]):
    # Z[i][j] := i 個ずれてて沈んでない方が j 個沈んでる状態の連結個数
    Z1 = []  # 左を押したとき（右が上にあるとき）
    Z2 = []  # 右を押したとき（左が上にあるとき）
    z1 = accumulate_reverse(C1, C2);  Z1.append(z1)
    for j in range(1, H+1):
        z1 = accumulate_reverse(C1, C2[j:]);  Z1.append(z1)
        z2 = accumulate_reverse(C1[j:], C2);  Z2.append(z2)
    Z1 += Z2[::-1]
    # dp[i][j] := 左を i 個、右を j 個沈めるまでの最小コスト  # 逆かも（どっちでもいい）
    dp = [[inf] * (H+2) for _ in range(H+2)]
    dp[0][0] = 0
    for j in range(H+1):
        for k in range(H+1):
            cost = dp[j][k] + Z1[j-k][min(j, k)]
            dp[j+1][k] = min(dp[j+1][k], cost)
            dp[j][k+1] = min(dp[j][k+1], cost)
    ans += dp[H][H]
print(ans)


### FIXED CODE ###

# 考えると、隣り合う列は結局 2*H 回ずることになり、
# それぞれの列間について最適な沈め順を見つけると、
# その順序関係を崩さないように全体の順番も構築できる（トポロジカルソートみたいに）ので、
# 各列間の最適解を求めて総和をとればいい

def accumulate_reverse(S1, S2):
    n = min(len(S1), len(S2))
    res = [0] * (n+1)
    c = 0
    for i in range(n):
        if S1[i] == S2[i]:
            c += 1
        res[n-i-1] = c
    return res

inf = 10**8
H, W = map(int, input().split())
C = [input() for _ in range(H)]
C_T = list(zip(*C))
C_T = ["".join(s) for s in C_T]
ans = 0
for C1, C2 in zip(C_T[:-1], C_T[1:]):
    # Z[i][j] := i 個ずれてて沈んでない方が j 個沈んでる状態の連結個数
    Z1 = []  # 左を押したとき（右が上にあるとき）
    Z2 = []  # 右を押したとき（左が上にあるとき）
    Z1.append(accumulate_reverse(C1, C2))
    for j in range(1, H+1):
        Z1.append(accumulate_reverse(C1, C2[j:]))
        Z2.append(accumulate_reverse(C1[j:], C2))
    Z1 += Z2[::-1]
    # dp[i][j] := 左を i 個、右を j 個沈めるまでの最小コスト  # 逆かも（どっちでもいい）
    dp = [[inf] * (H+2) for _ in range(H+2)]
    dp[0][0] = 0
    for j in range(H+1):
        for k in range(H+1):
            cost = dp[j][k] + Z1[j-k][min(j, k)]
            dp[j+1][k] = min(dp[j+1][k], cost)
            dp[j][k+1] = min(dp[j][k+1], cost)
    ans += dp[H][H]
print(ans)
### BUGGY CODE ###

from math import floor
A, B, N = map(int, input().split())
AdB = A/B

m = 0
for x in range(1, N + 1):
    if x < B:
        n = floor(x * AdB)
        if n > m:
            m = n
    else:
        n = floor(x * AdB) - A * floor(x / B)
        if n > m:
            m = n
print(m)


### FIXED CODE ###

from math import floor
A, B, N = map(int, input().split())
print(floor((min(N + 1, B) - 1) * A / B))
### BUGGY CODE ###

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

# もし修行により消化コストが全て0になる場合
if sum(a_list) <= k:
    print(0)
    exit()

# 更新メソッド
def update_cost(max_idx, result_cost, a_list, f_list):

    result_cost[max_idx] = a_list[max_idx] * f_list[max_idx]

    if max_idx == 0:
        pass
    else:
        result_cost[max_idx-1] = a_list[max_idx-1] * f_list[max_idx-1]

    return result_cost

# ソート
a_list.sort()
f_list.sort(reverse=True)

# コストリストinit
result_cost = [a_list[idx] * f_list[idx] for idx in range(len(a_list))]


# 修行する
while k > 0:
    # 現状で最もコストが大きいものについて考える
    max_idx = result_cost.index(max(result_cost))

    # 修行実行
    a_list[max_idx] -= 1
    a_list.sort()

    # コストリスト更新
    result_cost = update_cost(max_idx, result_cost, a_list, f_list)

    # 修行数減らす
    k -= 1

print(max(result_cost))

### FIXED CODE ###

# # もし修行により消化コストが全て0になる場合
# if sum(a_list) <= k:
#     print(0)
#     exit()

# # 更新メソッド
# def update_cost(max_idx, result_cost, a_list, f_list):

#     result_cost[max_idx] = a_list[max_idx] * f_list[max_idx]

#     if max_idx == 0:
#         pass
#     else:
#         result_cost[max_idx-1] = a_list[max_idx-1] * f_list[max_idx-1]

#     return result_cost

# # ソート
# a_list.sort()
# f_list.sort(reverse=True)

# # コストリストinit
# result_cost = [a_list[idx] * f_list[idx] for idx in range(len(a_list))]


# # 修行する
# while k > 0:
#     # 現状で最もコストが大きいものについて考える
#     max_idx = result_cost.index(max(result_cost))

#     # 修行実行
#     a_list[max_idx] -= 1
#     a_list.sort()

#     # コストリスト更新
#     result_cost = update_cost(max_idx, result_cost, a_list, f_list)

#     # 修行数減らす
#     k -= 1

# print(max(result_cost))

import numpy as np
n, k = map(int, input().split())

A = np.array(input().split(), np.int)
F = np.array(input().split(), np.int)

A.sort()
F.sort()
F = F[::-1]

left = -1 
right = (A * F).sum()

while (right-left) > 1:
    # print(left, right)
    split_line = (left + right) // 2
    r = np.maximum(0, A-split_line // F).sum() <= k
    if r:
        right = split_line
    else:
        left = split_line

print(right)
### BUGGY CODE ###

def solve():
    import numpy as np
    from sys import stdin
    f_i = stdin
    
    H, W = map(int, f_i.readline().split())
    A = tuple(tuple(map(int, f_i.readline().split())) for i in range(H))
    B = tuple(tuple(map(int, f_i.readline().split())) for i in range(H))
    
    dp1 = [dict() for i in range(W)]
    dp1[0][0] = True
    for A_i, B_i in zip(A, B):
        dp2 = [dict() for i in range(W)]
        
        diff = A_i[0] - B_i[0]
        for pre_bias in dp1[0]:
            dp2[0][abs(pre_bias + diff)] = True
            dp2[0][abs(pre_bias - diff)] = True
        
        for j, t in enumerate(zip(A_i[1:], B_i[1:]), start=1):
            A_ij, B_ij = t
            diff = A_ij - B_ij
            for pre_bias in dp1[j]:
                dp2[j][abs(pre_bias + diff)] = True
                dp2[j][abs(pre_bias - diff)] = True
            for pre_bias in dp2[j-1]:
                dp2[j][abs(pre_bias + diff)] = True
                dp2[j][abs(pre_bias - diff)] = True
                
        dp1 = dp2
    
    print(min(dp2[-1]))
 
solve()

### FIXED CODE ###

def solve():
    from sys import stdin
    f_i = stdin
    
    H, W = map(int, f_i.readline().split())
    A = tuple(tuple(map(int, f_i.readline().split())) for i in range(H))
    B = tuple(tuple(map(int, f_i.readline().split())) for i in range(H))
    
    dp1 = [0] * W
    bit_width = 80 * (H + W - 2)
    dp1[0] = 1 << (bit_width)
    for A_i, B_i in zip(A, B):
        dp2 = [0] * W
        
        diff = abs(A_i[0] - B_i[0])
        dp2[0] = (dp1[0] << diff) | (dp1[0] >> diff)
        
        for j, t in enumerate(zip(A_i[1:], B_i[1:]), start=1):
            A_ij, B_ij = t
            diff = abs(A_ij - B_ij)
            b = dp1[j] | dp2[j-1]
            dp2[j] = (b << diff) | (b >> diff)
        
        dp1 = dp2
    
    b = bin(dp2[-1])
    b = b[-bit_width-1:]
    print(b.index('1'))
 
solve()