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

import sys
import itertools

N, K = map(int, input().split())
a = list(map(int, input().split()))
a = list(itertools.combinations(a, 2))
L = []
for i in a:
  L.append(i[0] * i[1])
print(sorted(L)[K-1])


### FIXED CODE ###

import numpy as np

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

A = np.array(input().split(), np.int64)

A.sort()

posA = A[A > 0]
negA = A[A < 0]
zeros = (A==0).sum()

left = -10**18
right = 10**18

while left+1 < right:
    num = (left+right)//2
    
    less_count = 0
    
    if num >= 0:
        less_count += zeros * n
    
    limit_pair_for_pos = num // posA
    limit_idxs = np.searchsorted(A, limit_pair_for_pos, side='right')
    less_count += limit_idxs.sum()

    limit_pair_for_neg = -(num // -negA)
    limit_idxs = n - np.searchsorted(A, limit_pair_for_neg, side='left')
    less_count += limit_idxs.sum()

    duplicate_cases = (A**2 <= num).sum()
    less_count -= duplicate_cases
    less_count //= 2
    
    if less_count >= k:
        right = num
    else:
        left = num

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

from fractions import gcd
from collections import Counter
slope=Counter()
slope_zero=0
slope_inf=0
both_zero=0
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        both_zero+=1
    else:
        if a==0:
            slope_zero+=1
        elif b==0:
            slope_inf+=1
        else:
            sign=(a//abs(a))*(b//abs(b))
            a=abs(a)
            b=abs(b)
            gc=gcd(a,b)
            a//=gc
            b//=gc
            if sign==1:
                slope[(a,b)]+=1
            else:
                slope[(-a,b)]+=1
ans=1
mod=10**9+7
for a,b in slope.keys():
    if slope[(a,b)]>0:
        aa=-b
        bb=a
        if bb<0:
            bb*=-1
            aa*=-1
        if slope[(aa,bb)]>0:
            ans*=(pow(2,slope[(a,b)],mod)+pow(2,slope[(aa,bb)],mod)-1+mod)%mod
            ans%=mod
            slope[(aa,bb)]=0
        else:
            ans*=(pow(2,slope[(a,b)],mod))%mod
            ans%=mod
ans*=(pow(2,slope_zero,mod)+pow(2,slope_inf,mod)-1+mod)%mod
ans%=mod
ans+=both_zero
if ans>=mod:
    ans%=mod
print((ans-1+mod)%mod)




### FIXED CODE ###

from fractions import gcd
from collections import Counter
slope=Counter()
slope_zero=0
slope_inf=0
both_zero=0
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        both_zero+=1
    else:
        if a==0:
            slope_zero+=1
        elif b==0:
            slope_inf+=1
        else:
            sign=(a//abs(a))*(b//abs(b))
            a=abs(a)
            b=abs(b)
            gc=gcd(a,b)
            a//=gc
            b//=gc
            if sign==1:
                slope[(a,b)]+=1
            else:
                slope[(-a,b)]+=1
ans=1
mod=10**9+7
for a,b in slope.keys():
    if slope[(a,b)]>0:
        aa=-b
        bb=a
        if bb<0:
            bb*=-1
            aa*=-1
        if slope[(aa,bb)]>0:
            ans*=(pow(2,slope[(a,b)],mod)+pow(2,slope[(aa,bb)],mod)-1+mod)%mod
            ans%=mod
            slope[(aa,bb)]=0
        else:
            ans*=(pow(2,slope[(a,b)],mod))%mod
            ans%=mod
ans*=(pow(2,slope_zero,mod)+pow(2,slope_inf,mod)-1+mod)%mod
ans%=mod
ans+=both_zero
if ans>=mod:
    ans%=mod
print((ans-1+mod)%mod)
### BUGGY CODE ###

N = int(input())
x = 1
mod = 10**9+7
for i in range(1,N+1):
  x *= i
print(x%mod)

### FIXED CODE ###

n = int(input())
mod = 10**9+7
ans = 1
for i in range(1,n+1):
  ans = i * ans%mod
print(ans)
### BUGGY CODE ###

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

area = []
for i in range(K):
    L, R = map(int, input().split())
    area.append((L, R))

d = [0] * N


def func(pos):
    for a in area:
        for i in range(a[0], a[1]+1):
            if pos - i > -1:
                d[pos-i] += d[pos]


d[N-1] = 1
for i in range(N-1, -1, -1):
    if d[i] > 0:
        func(i)

print(d[0] % 998244353)


### FIXED CODE ###

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

area = []
for i in range(K):
    L, R = map(int, input().split())
    area.append((L, R))

area.sort()
d = [0] * N
a = [0] * N


def func(pos):
    for l, r in area:
        if pos + l - 1 < N:
            a[pos + l-1] += d[pos]
        if pos + r < N:
            a[pos + r] -= d[pos]
    d[pos+1] = (d[pos] + a[pos]) % 998244353


d[0] = 1
a[0] = -1
for i in range(0, N-1):
    func(i)

print(d[N-1] % 998244353)
### BUGGY CODE ###

import sys
n = input()
d = [int(i) for i in raw_input().split()]
m = input()
t = [int(i) for i in raw_input().split()]

for i in t:
    if i in d:
        d.remove(i)

    else:
        print 'NO'
        sys.exit()

print 'YES'

### FIXED CODE ###

import sys
n = input()
d = [int(i) for i in raw_input().split()]
m = input()
t = [int(i) for i in raw_input().split()]

dd = {}
tt = {}

for ddd in d:
    dd.setdefault(ddd,0)
    dd[ddd] += 1

for ttt in t:
    tt.setdefault(ttt,0)
    tt[ttt] += 1




for search in tt.keys():
    if search in dd:
        if tt[search] > dd[search]:
            
            print 'NO'
            sys.exit()

    else:
        print 'NO'
        sys.exit()

print 'YES'
### BUGGY CODE ###

n = int(input())
s = input()
S = list(s)
a = 0
for k in range(n):
        for j in range(k):
            for i in range(j):
                if  S[i] != S[j] and S[j] != S[k] and S[k] != S[i] and 2*j != i + k:
                    # print(i, j, k)
                    a += 1
print(a)

### FIXED CODE ###

n = int(input())
s = input()
S = list(s)
r = S.count('R')
g = S.count('G')
b = S.count('B')
ans = r * g * b
for k in range(n):
        for j in range(k):
            i = 2*j - k
            if i >= 0 and i < j and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
print(ans)
### BUGGY CODE ###

from pprint import pprint
from copy import deepcopy

#N <= 10**5なので、全探索はNG
#Greedyでいける？


n,m = map(int,input().split())

requests = [list(map(int,input().split())) for _ in range(m)]

bridge_list = [[] for _ in range(n-1)]

for i in range(m):
    startpoint = requests[i][0]
    endpoint = requests[i][1]
    for j in range(startpoint,endpoint):
        bridge_list[j-1].append(i)

#pprint(bridge_list)

checked_requests = [0] * m

#bridge_list = sorted(bridge_list, key=lambda x: len(x))

counter = 0

while sum(checked_requests) != m:
    #max_index = bridge_list.index(max(list(map(len,bridge_list))))
    length_list = list(map(len,bridge_list))
    max_index = length_list.index(max(length_list))

    #bridge_list[max_index]を直接 for k in に突っ込むと、removeメソッドがあるため動作がおかしくなってしまう。
    temp = deepcopy(bridge_list[max_index])

    for k in temp:
        checked_requests[k] = 1
        for l in range(n-1):
            try:
                bridge_list[l].remove(k)
            except ValueError:
                pass
    
    counter += 1
    
pprint(counter)







### FIXED CODE ###

#この方法だとTLEになるためNG

from pprint import pprint
from copy import deepcopy

#N <= 10**5なので、全探索はNG
#Greedyでいける？


n,m = map(int,input().split())

requests = [list(map(int,input().split())) for _ in range(m)]

#区間スケジュール問題と考え、終端が小さい順で並べる。その後Greedyで計算。
requests = sorted(requests, key=lambda x:x[1])

counter = 0
before_point = -float('inf')

#pprint(requests)

for i in range(m):
    if requests[i][0] >= before_point:
        counter += 1
        before_point = requests[i][1]
        #print("requests[{}]={} YES".format(i,requests[i]))
    else:
        #print("requests[{}]={} NO".format(i,requests[i]))
        pass

print(counter)
### BUGGY CODE ###

import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    s = IS()
    n = len(s)
    cnt = 0
    for i in reversed(range(3,n)):
        if int(s[i-1])%2==0:
            if int(s[i])%2==0: pass
        for j in reversed(range(0,i-3)):
            if int(s[j:i+1])%2019 == 0:
                cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    s = list(map(int, IS()))
    n = len(s)
    p = 2019
    cnt = 0
    d = [0]*p
    d[0] = 1 # 0(mod p)はそれ単体で割り切れるため+1しておく
    ss = 0
    x = 1
    for si in s[::-1]:
        ss += x*si
        ss %= p
        d[ss] += 1
        x = (10*x)%p # %p無しだとTLE
    cnt = 0
    for di in d:
        cnt += di*(di-1)//2 # calc combination(n_C_2)
    print(cnt)

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

import math

N,A,B,K=map(int,input().split())

def Combi(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


ran=min(N,K//(A+B))
ANS=0
#i緑j赤k青
for i in range(ran+1):
    for j in range(min(N-i,(K-(A+B)*i)//A)+1):
        if (K-(A+B)*i-A*j)%B==0:
            k=(K-(A+B)*i-A*j)//B

            if k<=N-i-j:
                ANS=(ANS+Combi(N,i)*Combi(N-i,j)*Combi(N-i-j,k))%998244353
            else:
                break
            #print([i,j,k],Combi(N,i)*Combi(N-i,j)*Combi(N-i-j,k))


print(ANS)

### FIXED CODE ###

N,A,B,K=map(int,input().split())
mod=998244353

INV=[None]*(N+1)
for i in range(1,N+1):
    INV[i]=pow(i,mod-2,mod)

Combi=[None]*(N+1)
Combi[0]=1
Combi[1]=N
for i in range(2,N//2+2):
    Combi[i]=Combi[i-1]*(N-i+1)*INV[i] %mod
for i in range(N//2+2,N+1):
    Combi[i]=Combi[N-i]


ANS=0

if B>A:
    (A,B)=(B,A)

ran=K//A

for i in range(min(ran,N)+1):
    q, r = divmod(K-(A*i), B)
    if r==0 and q<=N:
        ANS = (ANS+(Combi[i]*Combi[q])%mod)%mod

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

s = input()
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
m[0] = 1
ans = 0

for i in range(l - 1, 0, -1):
    t[i - 1] = (t[i] + int(s[i - 1]) * 10 ** (l - i)) % 2019
    m[t[i - 1]] += 1

for i in m:
    ans += i * (i - 1) // 2

print(ans)

### FIXED CODE ###

S = input() [::-1]
ans = 0
mod = 0
ten = 1
count = [0]* 2019
count[0] = 1
for i in range(len(S)):
    mod = (mod + int(S[i]) * ten) % 2019
    ten = ten*10 % 2019
    count[mod] += 1
for c in count:
    ans += c*(c-1)//2
print(ans)
### BUGGY CODE ###

s=input()
n=len(s)
p=10**9+7

dp=[[0]*13 for i in range(n)]
 
if s[0]!='?':
    a=int(s[0])*10**(n-1)%13
    dp[0][a]=1
else:
    for k in range(10):
        a=k*10**(n-1)%13
        dp[0][a]=1
 
for i in range(1,n):
    m=10**(n-i-1)%13
    if s[i]!='?':
        for j in range(13):
            dp[i][j]=dp[i-1][(j-int(s[i])*m)%13]%p
    else:
        for k in range(10):
            for j in range(13):
                dp[i][j]+=dp[i-1][(j-k*m)%13]%p
print(dp[n-1][5]%(10**9+7))

### FIXED CODE ###

s=input()
n=len(s)
p=10**9+7
 
dp=[[0]*13 for i in range(n)]
m=[0]*(n-1)+[1]
for i in range(n-1):
    m[-i-2]=m[-i-1]*10%13
 
if s[0]!='?':
    a=int(s[0])*m[0]%13
    dp[0][a]=1
else:
    for k in range(10):
        a=k*m[0]%13
        dp[0][a]=1
 
for i in range(1,n):
    if s[i]!='?':
        for j in range(13):
            dp[i][j]=dp[i-1][(j-int(s[i])*m[i])%13]%p
    else:
        for k in range(10):
            for j in range(13):
                dp[i][j]+=dp[i-1][(j-k*m[i])%13]%p
print(dp[n-1][5]%p)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
    
def main():
    n,m=map(int,input().split())
    A=[int(input())for _ in range(m)]
    mod=10**9+7
    dp=[0]*(n+1)
    dp[0]=1
    for i in range(n):
        if not(i+1 in A):
            dp[i+1]+=dp[i]%mod
        if not(i+2 in A) and i<n-1:
            dp[i+2]+=dp[i]%mod
    print(dp[n]%mod)

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
    
def main():
    n,m=map(int,input().split())
    A=[int(input())for _ in range(m)]
    flag=[True]*(n+2)
    for a in A:
        flag[a]=False
    mod=10**9+7
    dp=[0]*(n+1)
    dp[0]=1
    for i in range(n):
        if flag[i+1]:
            dp[i+1]+=dp[i]%mod
        if flag[i+2] and i<n-1:
            dp[i+2]+=dp[i]%mod
    print(dp[n]%mod)

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

import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
cnt = 0
for a in A:
  pos_b = bisect.bisect_right(B, a)
  for pb in range(pos_b, N):
    pos_c = bisect.bisect_right(C, B[pb])
    cnt += N-pos_c
print(cnt)


### FIXED CODE ###

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

nums = []
for idx in range(N):
  nums.append((1, A[idx]))
  nums.append((2, B[idx]))
  nums.append((3, C[idx]))
nums.sort(key=lambda x:(x[1], -x[0]))
sum_a = 0
sum_b = 0
sum_c = 0
for idx in range(3*N):
  if nums[idx][0] == 1:
    sum_a += 1
  elif nums[idx][0] == 2:
    sum_b += sum_a
  elif nums[idx][0] == 3:
    sum_c += sum_b
print(sum_c)
### BUGGY CODE ###

# D - String Formation

S = input()
Q = int(input())
rev = False

for _ in range(Q):
    T = [t for t in input().split()]
    t = int(T[0])
    if t == 1:
        rev = not rev
    if t == 2:
        f, c = int(T[1]), T[2]
        if f == 1:
            if rev:
                S = S + c
            else:
                S = c + S
        if f == 2:
            if rev:
                S = c + S
            else:
                S = S + c

print(S if not rev else S[::-1])


### FIXED CODE ###

# D - String Formation

from collections import deque

S = deque([s for s in input()])
Q = int(input())
rev = False

for _ in range(Q):
    T = [t for t in input().split()]
    t = int(T[0])
    if t == 1:
        rev = not rev
    if t == 2:
        f, c = int(T[1]), T[2]
        if f == 1:
            if rev:
                S.append(c)
            else:
                S.appendleft(c)
        if f == 2:
            if rev:
                S.appendleft(c)
            else:
                S.append(c)

S = ''.join(list(S))
print(S if not rev else S[::-1])
### BUGGY CODE ###

n=int(raw_input())
t=a=1

for i in range(n):
    x,y=map(int,raw_input().split())
    if t<=x and a<=y:
        t=x
        a=y
    else:
        tmp=min(t/x,y/a)
        while 1:
            if x*tmp>=t and y*tmp>=a:
                t=x*tmp
                a=y*tmp
                break
            tmp+=1
print t+a
exit()

### FIXED CODE ###

n=int(raw_input())
t=a=1

for i in range(n):
    x,y=map(int,raw_input().split())
    n=max((t+x-1)/x,(a+y-1)/y)
    t=n*x
    a=n*y
print t+a
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def can_reach(x, default_pos, x_moves):
    for tries in range(2**len(x_moves)):
        result = default_pos
        for digit in range(len(x_moves)):
            result += (x_moves[digit] if tries & (1<<digit) else -x_moves[digit])
        if result == x:
            return True
    return False

def main(): 
    s = SI()
    x, y = LI()

    x_moves = []
    y_moves = []
    moving_x = True
    for i in s.split('T'):
        if moving_x:
            x_moves.append(len(i))
        else:
            y_moves.append(len(i))
        moving_x = not moving_x

    if can_reach(x, x_moves[0], x_moves[1:]) and can_reach(y, 0, y_moves):
        print('Yes')
    else:
        print('No')


main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

# def can_reach(x, default_pos, x_moves):
#     for tries in range(2**len(x_moves)):  # x_moves は最大 4000, 2**100 で既に 10**30 なのでぜんぜん間に合わない。
#         result = default_pos
#         for digit in range(len(x_moves)):
#             result += (x_moves[digit] if tries & (1<<digit) else -x_moves[digit])
#         if result == x:
#             return True
#     return False

def can_reach(x_aim, default_pos, x_moves):  # ソートして貪欲？
    for i in sorted(x_moves, reverse=True):
        if x_aim > default_pos:
            default_pos += i
        else:
            default_pos -= i
    if default_pos == x_aim:
        return True
    else:
        return False

def main(): 
    s = SI()
    x, y = LI()

    x_moves = []
    y_moves = []
    moving_x = True
    for i in s.split('T'):
        if moving_x:
            x_moves.append(len(i))
        else:
            y_moves.append(len(i))
        moving_x = not moving_x

    if can_reach(x, x_moves[0], x_moves[1:]) and can_reach(y, 0, y_moves):
        print('Yes')
    else:
        print('No')


main()
### BUGGY CODE ###

import time
from collections import deque
H, W = map(int, input().split())
maze = [input()for _ in range(H)]


def bfs(queue: deque, reached: set) -> int:
    ans = 0
    dxdy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    while queue:
        d = queue.pop()
        if ans < d[2]:
            ans = d[2]
        for a in dxdy:
            x = d[0] + a[0]
            y = d[1] + a[1]
            if 0 <= x < W and 0 <= y < H and not reached[y][x]:
                queue.appendleft((x, y, d[2] + 1))
                reached[y][x] = True
    return ans


queue = deque()
reached = [[False for i in range(W)] for j in range(H)]
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            queue.append((j, i, 0))
            reached[i][j] = True
print(bfs(queue, reached))


### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
maze = [input()for _ in range(H)]


def bfs(queue: deque, reached: set) -> int:
    ans = 0
    dxdy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    while queue:
        d = queue.pop()
        if ans < d[2]:
            ans = d[2]
        for a in dxdy:
            x = d[0] + a[0]
            y = d[1] + a[1]
            if 0 <= x < W and 0 <= y < H and not reached[y][x]:
                queue.appendleft((x, y, d[2] + 1))
                reached[y][x] = True
    return ans


queue = deque()
reached = [[False for i in range(W)] for j in range(H)]
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            queue.append((j, i, 0))
            reached[i][j] = True
print(bfs(queue, reached))
### BUGGY CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns()) #int
na = lambda: list(map(int, stdin.readline().split())) #int,list
ns = lambda: stdin.readline().rstrip()  # str

n,m=na()
a=na()
for i in range(m):
	b,c=na()
	for i in range(b):
		a.append(c)

print(sum(sorted(a)[-n:]))

### FIXED CODE ###

import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n,m = rl()
a = rl()

li=dict(Counter(a))
for _ in range(m):
    b, c = rl()
    if c in li:
        li[c]+=b
    else:
        li[c]=b
li=sorted(li.items(),key=lambda x: -x[0])
ans=0
res=n
for pair in li:
    if res<=0:
        continue
    if res>=pair[1]:
        ans+=pair[0]*pair[1]
        res-=pair[1]
    else:
        ans+=pair[0]*res
        res=0
print(ans)
### BUGGY CODE ###

import numpy as np

N,K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" "))) # consumption coefficient of members
F = list(map(int, input().split(" "))) # difficulty of food

# pair fastest eaters (low consumption coefficient) with most difficult foods
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)

def how_many_K(A,F,T,K):
    """
    Returns whether the number of training sessions needed for group A with foods F to have a score equal to T is less than K
    """
    num_trains = 0
    for i in range(len(A)):
        a = A[i]
        f = F[i]
        num_trains += max(0, a-T//f)

    if num_trains > K:
        return False
    else:
        return True

maxT = np.max(A*F)
# use binary search to find lowest possible T
left = -1
right = maxT
while left+1< right:
    mid = (left+right)//2
    if how_many_K(A,F,mid,K):
        right  = mid
    else:
        left = mid
print(right)

### FIXED CODE ###

import numpy as np

N,K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" "))) # consumption coefficient of members
F = list(map(int, input().split(" "))) # difficulty of food

# pair fastest eaters (low consumption coefficient) with most difficult foods
A.sort()
F.sort(reverse=True)
A = np.array(A)
F = np.array(F)

maxT = np.max(A*F)
# use binary search to find lowest possible T
left = -1
right = maxT
while left+1< right:
    mid = (left+right)//2
    if np.maximum(0, A - (mid//F)).sum() <= K:
        right  = mid
    else:
        left = mid
print(right)
### BUGGY CODE ###

N = int(input())
S = input()

R_index = [n for n, v in enumerate(S) if v == 'R']
G_index = [n for n, v in enumerate(S) if v == 'G']
B_index = [n for n, v in enumerate(S) if v == 'B']
ans = 0
for i in range(N):
    if S[i] == 'R':
        for j in G_index:
            if j < i:
                continue
            diff = j - i
            if j+diff in B_index:
                ans += sum(x > j for x in B_index) -1
            else:
                ans += sum(x > j for x in B_index) 
        for j in B_index:
            if j < i:
                continue
            diff = j - i
            if j+diff in G_index:
                ans += sum(x > j for x in G_index) -1
            else:
                ans += sum(x > j for x in G_index)
    elif S[i] == 'G':
        for j in R_index:
            if j < i:
                continue
            diff = j - i
            if j+diff in B_index:
                ans += sum(x > j for x in B_index) -1
            else:
                ans += sum(x > j for x in B_index) 
        for j in B_index:
            if j < i:
                continue
            diff = j - i
            if j+diff in R_index:
                ans += sum(x > j for x in R_index) -1
            else:
                ans += sum(x > j for x in R_index)
    elif S[i] == 'B':
        for j in R_index:
            if j < i:
                continue
            diff = j - i
            if j+diff in G_index:
                ans += sum(x > j for x in G_index) -1
            else:
                ans += sum(x > j for x in G_index) 
        for j in G_index:
            if j < i:
                continue
            diff = j - i
            if j+diff in R_index:
                ans += sum(x > j for x in R_index) -1
            else:
                ans += sum(x > j for x in R_index)
print(ans)

### FIXED CODE ###

from collections import Counter

N = int(input())
S = input()
index = Counter(S)
ans = index["R"]*index["G"]*index["B"]

for diff in range(1, N//2 +1):
    for i in range(N):
        j = i +diff
        k = j +diff
        if k >= N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1
print(ans)