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

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W, M = LI()
    hw = [LI() for _ in range(M)]
    hw_set = set([(h, w) for h, w in hw])

    cnt_h = collections.Counter([h for h, w in hw])
    cnt_w = collections.Counter([w for h, w in hw])

    # i行目にはどの列にあります
    # print(cnt_h)
    # print(cnt_w)
    max_h = max(cnt_h.values())
    max_w = max(cnt_w.values())
    max_h_k = [k for k, v in cnt_h.items() if v == max_h]
    max_w_k = [k for k, v in cnt_w.items() if v == max_w]
    is_on_target = True
    for i, j in itertools.product(max_h_k, max_w_k):
        if (i, j) not in hw_set:
            is_on_target = False

    if is_on_target:
        ans = max(cnt_h.values()) + max(cnt_w.values()) - 1
    else:
        ans = max(cnt_h.values()) + max(cnt_w.values())
    print(ans)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W, M = LI()
    hw = [LI() for _ in range(M)]
    hw_set = set([(h, w) for h, w in hw])

    cnt_h = collections.Counter([h for h, w in hw])
    cnt_w = collections.Counter([w for h, w in hw])

    # i行目にはどの列にあります
    # print(cnt_h)
    # print(cnt_w)
    max_h = max(cnt_h.values())
    max_w = max(cnt_w.values())
    max_h_k = [k for k, v in cnt_h.items() if v == max_h]
    max_w_k = [k for k, v in cnt_w.items() if v == max_w]
    is_on_target = True
    for i, j in itertools.product(max_h_k, max_w_k):
        if (i, j) not in hw_set:
            is_on_target = False
            break

    if is_on_target:
        ans = max_h + max_w - 1
    else:
        ans = max_h + max_w
    print(ans)

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

import math
a, b, n = map(int, input().split())
m = 0
t = min(b, n)
for i in range(b//a, t+1):
    if m < math.floor((a*i)/b) - a*math.floor(i/b):
        m = math.floor((a*i)/b) - a*math.floor(i/b)
print(m)

### FIXED CODE ###

import math
a, b, n = map(int, input().split())
if n < b: print(math.floor((a*n)/b) - a*math.floor(n/b))
else: print(math.floor((a*(b-1))/b) - a*math.floor((b-1)/b))
### BUGGY CODE ###

def gcd(x, y):
  if x % y == 0:
    return y
  
  return gcd(y, x % y)


K = int(input())
count = 0
ab = []

for a in range(1, K+1):
  for b in range(1, K+1):
    ab.append(gcd(a, b))

for c in range(1, K+1):
  for i in ab:
    count += gcd(i, c)

print(count)

### FIXED CODE ###

def gcd(x, y):
  if x % y == 0:
    return y
  
  return gcd(y, x % y)


K = int(input())
count = 0

# a, b, cが全て一致する場合
count += K * (K+1) / 2

# a, b, cのうち、いずれか二つが一致する場合
for a in range(1, K):
  for b in range(a+1, K+1):
    count += gcd(b, a) * 6

# a, b, cが全て異なる場合
for a in range(1, K-1):
  for b in range(a+1, K):
    ab = gcd(b, a)
    
    for c in range(b+1, K+1):
      count += gcd(c, ab)  * 6

print(int(count))
### BUGGY CODE ###


def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))

n,c,k = readInts()
t = []
for i in range(n):
	t.append(readInt())
t.sort()

def people(n):
	ans = 0
	for i in t:
		if n>=i:
			ans+=1
		else:
			break
	#print(n,t,ans)
	return ans

ans = 0
while len(t)>0:
	pi = t[0]
	mens = people(pi+k)
	bus = mens//c
	if bus!=0:
		ans+=bus
		t = t[bus*c:]
	else:
		ans+=1
		t = t[mens:]

	#print(pi,mens,bus,t)
print(ans)

### FIXED CODE ###

import bisect

n,c,k = list(map(int, input().split()))
t = []
for i in range(n):
	t.append(int(input()))
t.sort()

ans = 0
remain = c-1
if c==1:
	print(n)
	exit()
time = t[0]
for i in range(1,len(t)):
	if time+k<t[i]:
		time = t[i]
		remain = c
		ans+=1
	if remain==0:
		remain=c
		time = t[i]
		ans+=1
	remain-=1

print(ans+1)
### BUGGY CODE ###

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

if K == 1:
    for a, b in zip(A[:-1], A[1:]):
        if a < b:
            print("Yes")
        else:
            print("No")
else:
    score = 1
    for i in range(K):
        score *= A[i]
    for i in range(K, N):
        tmp = score // A[i - K] * A[i]
        if tmp > score:
            print("Yes")
        else:
            print("No")
        score = tmp

### FIXED CODE ###

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

if K == 1:
    for a, b in zip(A[:-1], A[1:]):
        if a < b:
            print("Yes")
        else:
            print("No")
else:
    for i in range(K, N):
        if A[i] > A[i-K]:
            print("Yes")
        else:
            print("No")
### BUGGY CODE ###

import numpy as np
import sys
input = sys.stdin.readline


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    dp[i][:w_v[i][0]] = dp[i-1][:w_v[i][0]]
    for w in range(w_v[i][0], W+1):
        dp[i][w] = max(dp[i-1][w], dp[i-1][w - w_v[i][0]] + w_v[i][1])

print(dp[-1][-1])

### FIXED CODE ###

import numpy as np


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    key = w_v[i][0]
    dp[i][:key] = dp[i-1][:key]
    dp[i][key:] = np.maximum(dp[i-1][key:], dp[i-1][:-key] + w_v[i][1])

print(dp[-1][-1])
### BUGGY CODE ###

# from copy import deepcopy
from collections import deque
import sys
input = sys.stdin.readline

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

B = list(map(int, input().split()))
B.sort(reverse=True)
C = deque(B)
# C = deepcopy(B)
# C.reverse()
# C = deque(C)

ans = []

for i in range(N):
    p = C.popleft()
    if A[i] != p:
        ans.append(p)
        continue

    if len(C) >= 1:
        # q = p
        cnt = 1
        while C:
            q = C.popleft()
            if q == A[i]:
                cnt += 1
            else:
                break

        if len(C) == 0 and A[i] == q:
            print("No")
            exit()

        ans.append(q)
        for _ in range(cnt):
            C.appendleft(A[i])
        continue

    print("No")
    exit()

print("Yes")
if len(ans) >= 2:
    print(*ans)
else:
    print(ans[0])


### FIXED CODE ###

"""
T E S T
"""

from collections import Counter, deque

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

cnt_a = Counter(A)
cnt_b = Counter(B)

cnt_ab = cnt_a + cnt_b

for i in cnt_ab.values():
    if i > N:
        print("No")
        exit()


print("Yes")
dq_a = deque(A)
dq_b = deque(B)

ans = []

dq_b.rotate(N // 2)

while dq_a:
    if dq_a[0] != dq_b[0]:
        dq_a.popleft()
        p = dq_b.popleft()
        ans.append(p)
        # ans.append(b.popleft())
    else:
        dq_b.rotate()
print(*ans)
### BUGGY CODE ###

import sys

def main():
    input = sys.stdin.readline
    H, W, D = map(int, input().split())
    d = {}

    for i in range(H):
        row = list(map(int, input().split()))
        for j in range(W):
            d[row[j]] = [i, j]

    A = [[0 for _ in range(H*W)] for _ in range(H*W)]
    for i in range(H * W):
        for j in range(i + D, H * W):
            ans = 0
            L, R = i + 1, j + 1
            if (R - L) % D != 0:
                continue
            while L != R:
                a = d[L]
                b = d[L+D]
                ans += abs(a[0] - b[0]) + abs(a[1] - b[1])
                L += D
            A[i][j] = ans

    Q = int(input())
    for _ in range(Q):
        L, R = map(int, input().split())
        print(A[L-1][R-1])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline
    H, W, D = map(int, input().split())
    d = [0] * (H*W + 1)

    for i in range(H):
        row = list(map(int, input().split()))
        for j in range(W):
            d[row[j]] = [i, j]

    A = [0] * (H*W + 1)
    for l in range(H * W - D, 0, -1):
        a = d[l]
        b = d[l+D]
        A[l] = A[l+D] + abs(a[0] - b[0]) + abs(a[1] - b[1])

    Q = int(input())
    for _ in range(Q):
        L, R = map(int, input().split())
        print(A[L] - A[R])


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

L, R = [int(i) for i in input().split()]
num_list = []
for i in range(R-L):
  for j in range(R-L-i):
    x = L + i
    y = L + i + j + 1
    num = (x*y)%2019
    num_list.append(num)
print(min(num_list))

### FIXED CODE ###

L, R = [int(i) for i in input().split()]
num_list = []
if R-L > 2019:
  print(0)
else:
  for i in range(R-L):
    for j in range(R-L-i):
      x = (L + i)%2019
      y = (L + i + j + 1)%2019
      num = (x*y)%2019
      num_list.append(num)
  print(min(num_list))
### BUGGY CODE ###

s = input()
s = s[::-1]

L = [0]
for i in range(len(s)):
    L.append((L[-1]+(int(s[i])*10**i)%2019)%2019)

D = dict()
for j in L:
    if j in D:
        D[j] += 1
    else:
        D[j] = 1
ans = 0
for k in D.values():
    ans += k * (k-1) //2

print(ans)

### FIXED CODE ###

s = input()
n = len(s)

memo = [0] * 2019
memo[0] += 1

num = 0
t = 1
for i in reversed(s):
    num += int(i) * t
    num %= 2019
    t *= 10
    t %= 2019
    memo[num] += 1

ans = 0
for p in memo:
    ans += p*(p-1)//2

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

import sys
sys.setrecursionlimit(10**9)
n, m = map(int, input().split())

root = [-1]*n

def find(n):
    if root[n] < 0:
        return n
    else:
        root[n] = find(root[n])
        return root[n]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    else:
        root[x] += root[y]
        root[y] = x

def size(n):
    return -root[find(n)]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a, b)

ans = max(map(size, range(n)))
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
n, m = map(int, input().split())

root = [-1]*n

def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x

def size(x):
    x = r(x)
    return -root[x]

for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    unite(x, y)

ans = 0
for i in range(n):
    ans = max(ans, size(i))

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

import copy

n, k = map(int, input().split())
l = [int(x) for x in input().split()]

x = 1
ll = []
for i in l:
    x *= i
    ll.append(x)

lll = [copy.deepcopy(ll[k-1])]
for i in range(n-k):
    lll.append(int(ll[i+k]/ll[i]))

for i in range(len(lll)-1):
    if lll[i] < lll[i+1]:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

n, k = map(int, input().split())
l = [int(x) for x in input().split()]

for i in range(n-k):
    if l[i] < l[k+i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
A,B,C = a[:k[3]],b[:k[3]],c[:k[3]]

ab = list(ax+bx for ax in A for bx in B)
ab.sort(reverse=True)
AB = ab[:k[3]]
abc = list(aby+cy for aby in ab for cy in C)
abc.sort(reverse=True)
for i in range(k[3]): print(abc[i])


### FIXED CODE ###

k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

A = sorted(a, reverse=True)[:k[3]]
B = sorted(b, reverse=True)[:k[3]]
C = sorted(c, reverse=True)[:k[3]]

ab = sorted(list(ax+bx for ax in A for bx in B), reverse=True)[:k[3]]
abc = sorted(list(aby+cy for aby in ab for cy in C), reverse=True)[:k[3]]
for i in abc: print(i)
### BUGGY CODE ###

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    B.sort()
    C.sort()

    def is_ok(mid, S, K):
        if K < S[mid]:
            return True
        else:
            return False

    def binary_search_meguru(S, K):
        left = -1
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid, S, K):
                right = mid
            else:
                left = mid
        return right

    ans = 0
    for a in A:
        b = binary_search_meguru(B, a)
        for tar in B[b:]:
            c = binary_search_meguru(C, tar)
            ans += N-c
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    A.sort()
    B.sort()
    C.sort()

    def is_ok1(mid, S, K):
        if K <= S[mid]:
            return True
        else:
            return False

    def is_ok2(mid, S, K):
        if K < S[mid]:
            return True
        else:
            return False

    def binary_search_meguru(S, K, is_ok):
        left = -1
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid, S, K):
                right = mid
            else:
                left = mid
        return right

    ans = 0
    for b in B:
        a = binary_search_meguru(A, b, is_ok1)
        c = binary_search_meguru(C, b, is_ok2)
        ans += a * (N-c)
    print(ans)


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


import bisect

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

count = 0
for first in A:
    idx = bisect.bisect_left(B, first)
    seconds = B[idx:]

    for second in seconds:
        if first >= second:
            continue

        idx = bisect.bisect_left(C, second)
        thirds = C[idx:]

        for third in thirds:
            if second >= third:
                continue

            count += 1


print(count)

### FIXED CODE ###


import bisect

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

ans = 0
for second in B:
    ai = bisect.bisect_left(A, second)
    ci = bisect.bisect_right(C, second)

    ans += (ai*(N-ci))

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

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

Rewards_0, Rewards_1 = [], []  # i桁目を0 or 1にしたときの報酬
for i in range(40):
    reward_0, reward_1 = 0, 0
    for a in A:
        if a & (2 ** i):
            reward_0 += 2 ** i
        elif 2 ** i <= K:
            reward_1 += 2 ** i
    Rewards_0.append(reward_0)
    Rewards_1.append(reward_1)

dp0 = [0] * 41  # K以下か未確定
dp1 = [0] * 41  # K以下であることが確定

for i in reversed(range(40)):
    if K & (2 ** i):
        dp0[i] = dp0[i + 1] + Rewards_1[i]
        dp1[i] = dp0[i + 1] + Rewards_0[i]
    else:
        dp0[i] = dp0[i + 1] + Rewards_0[i]

    if dp1[i + 1] != 0:
        dp1[i] = max(dp1[i], dp1[i + 1] + max(Rewards_0[i], Rewards_1[i]))

print(max(dp0[0], dp1[0]))


### FIXED CODE ###

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


# 上からi桁(0-indexed)のbitが立っているものがいくつあるか
bit_stand_counts = [0] * 40
for a in A:
    a = bin(a)[2:].zfill(40)
    for i in range(40):
        if a[i] == '1':
            bit_stand_counts[i] += 1


# 上からi番目のbitまでみたときに、dp[i][0]: K以下であることが未確定 dp[i][1]: K以下であることが確定 のときの最大値
dp = [[-1, -1] for i in range(41)]
dp[0][0] = 0


# Kをbitで表したもの
K_bit = bin(K)[2:].zfill(40)


for i in range(40):
    value_0 = (2 ** (39 - i)) * bit_stand_counts[i]  # i桁目を0にした時の報酬
    value_1 = (2 ** (39 - i)) * (N - bit_stand_counts[i])  # i桁目を1にした時の報酬
    
    if K_bit[i] == '0':  # Kの上からiビット目が0なら、K以下か未確定のほうは合わせるしかない
        dp[i + 1][0] = dp[i][0] + value_0
    else:
        dp[i + 1][0] = dp[i][0] + value_1
        dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + value_0)  # Kの上からiビット目が1ならK以下確定に飛べる

    if dp[i][1] != -1:  # K以下であることが確定しているなら、あとは貪欲にとれる
        dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + max(value_0, value_1))


print(max(dp[-1]))
### BUGGY CODE ###

from functools import reduce
def gcm(a,b):
    if b == 0:
        return a
    if a<b:
        a,b=b,a
    return gcm(b, a%b)

def lcm(a,b):
    return a*b//gcm(a,b)

n,m = map(int, input().split())
a = list(map(int, input().split()))
b = [n//2 for n in a]

l = reduce(lcm,b)

for i in range(n):
    if l//b[i]%2 == 0:
        print(0)
        break
else:
    print(m//l//2+m//l%2)

### FIXED CODE ###

from functools import reduce
from fractions import gcd

def lcm(a,b):
    return a*b//gcd(a,b)

n,m = map(int, input().split())
a = list(map(int, input().split()))
b = [n//2 for n in a]

l = reduce(lcm,b)

for i in range(n):
    if l//b[i]%2 == 0:
        print(0)
        break
else:
    print(m//l//2+m//l%2)
### BUGGY CODE ###

def find(parents, x):
    if parents[x] == x:
        return x
    else:
        parents[x] = find(parents, parents[x])
        return parents[x]

def union(parents, x1, x2):
    y1 = find(parents, x1)
    y2 = find(parents, x2)
    if y1 != y2:
        parents[y2] = y1 


n, m = map(int, input().split())
alist = []
blist = []
for _ in range(m):
    a, b = map(int, input().split())
    alist.append(a - 1)
    blist.append(b - 1)

parents = list(range(n))
answers = [n * (n - 1) // 2]

for a, b in zip(reversed(alist), reversed(blist)):
    answers.append(answers[-1])
    c = find(parents, a)
    d = find(parents, b)
    if c == d: continue
    
    e = f = 0
    for i in range(n):
        j = find(parents, i)
        if c == j: e += 1
        if d == j: f += 1
    
    answers[-1] -= e * f
    union(parents, a, b)

for i in reversed(range(m)):
    print(answers[i])

### FIXED CODE ###

class UnionFind(object):
    def __init__(self, size):
        self.size = size
        self.parents = list(range(size))
        self.counts = [1] * size

    def find(self, x):
        history = []
        while self.parents[x] != x:
            history.append(x)
            x = self.parents[x]
        
        for i in history: 
            self.parents[i] = x
        return x
    
    def union(self, x1, x2):
        y1 = self.find(x1)
        y2 = self.find(x2)
        if y1 != y2:
            self.parents[y2] = y1
            self.counts[y1] += self.counts[y2]

    def count(self, x):
        return self.counts[self.find(x)]
    
if __name__ == '__main__':
    n, m = map(int, input().split())
    alist = []
    blist = []
    for _ in range(m):
        a, b = map(int, input().split())
        alist.append(a - 1)
        blist.append(b - 1)

    answers = [n * (n - 1) // 2]
    uf = UnionFind(n)

    for a, b in zip(reversed(alist), reversed(blist)):
        answers.append(answers[-1])
        c = uf.find(a)
        d = uf.find(b)
        if c == d: 
            continue
  
        answers[-1] -= uf.count(a) * uf.count(b)
        uf.union(a, b)

    for i in reversed(range(m)):
        print(answers[i])
### BUGGY CODE ###

from collections import Counter

n = int(input())

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

ans_dict = {}
for i in range(n):
    if i in ans_dict.keys():
        print(ans_dict[i])
    else:
        buff = a_list[:i]
        buff.extend(a_list[i+1:])
        c = Counter(buff)

        tmp_ans = 0
        for key, value in c.items():
            if value == 1:
                continue
            else:
                tmp_ans += (value * (value - 1))/2
        ans_dict[i] = tmp_ans
        print(int(tmp_ans))




### FIXED CODE ###

from collections import Counter

n = int(input())

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

c = Counter(a_list)

all_count = 0
for value in c.values():
    if value == 1:
        continue
    else:
        tmp = int((value * (value - 1))/2)
        all_count += tmp

for i in a_list:
    print(all_count - c[i] + 1)
### BUGGY CODE ###

L, R = [int(x) for x in input().split()]

min = 1000000000000000000000000000

for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        if min > i * j % 2019:
            min = i * j % 2019
        if min == 0:
            break

print(min)



### FIXED CODE ###

L, R = [int(x) for x in input().split()]

min = 1000000000000000000000000000

if R - L > 2019:
    print(0)
    exit()

for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        if min > i * j % 2019:
            min = i * j % 2019
        if min == 0:
            break

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

import heapq
N, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
F = sorted([int(i) for i in input().split()])

if sum(A) <= K:
    print(0)
    exit()
else:
    hq = [(-(A[i]*F[i]), A[i], F[i]) for i in range(N)]
    heapq.heapify(hq)  # リストhqのheap化

    for i in range(K):
        c, a, f = heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力

        a -= 1
        heapq.heappush(hq, (-(a*f), a, f))

    c, a, f = heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    print(-c)


### FIXED CODE ###

N, K = map(int, input().split())
A = sorted([int(i) for i in input().split()])
F = sorted([int(i) for i in input().split()], reverse=True)

if sum(A) <= K:
    print(0)
    exit()
else:
    OK = 10**12
    NG = -1

    while OK-NG > 1:
        mid = (OK+NG)//2
        cnt = 0

        for i, a in enumerate(A):
            cnt += max(0, a-mid//F[i])
        if cnt <= K:
            OK = mid
        else:
            NG = mid

print(OK)
### BUGGY CODE ###

N=int(input())
S=input()
sum=0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if j-i==k-j: continue
            if (S[i]!=S[j]) and (S[j]!=S[k]) and (S[i]!=S[k]):
                sum+=1
print(sum)

### FIXED CODE ###

N=int(input())
S=input()
cnt=S.count('R')*S.count('G')*S.count('B')
for i in range(N-2):
    for j in range(i+1, N-1):
        k=2*j-i
        if k<N:
            if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]: cnt-=1
print(cnt)
### BUGGY CODE ###

import itertools

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

def binary_search(l,r,v):
    while r >= l:
        h = (l+r) // 2
        if A[h] < v:
            l = h+1
        else:
            r = h-1
    return r

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = binary_search(j,n-1,A[i]+A[j])
        ans += a-j

print(ans) 


### FIXED CODE ###

import itertools
 
n = int(input())
A = list(map(int,input().split()))
A.sort()
 
def binary_search(l,r,v):
    while r >= l:
        h = (l+r) // 2
        if A[h] < v:
            l = h+1
        else:
            r = h-1
    return r
 
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = binary_search(j,n-1,A[i]+A[j])
        ans += a-j
 
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
kind=set(a)
c=len(kind)
ans=0
if len(kind)<=k:
    print(0)
else:
    for i in kind:
        b.append(a.count(i))
    b.sort()
    for i in range(c-k):
        ans+=b[i]
    print(ans)


### FIXED CODE ###

from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=len(set(a))
b=dict(Counter(a).most_common())
d=list(b.values())
d.sort()
if c<=k:
    print(0)
else:
    tmp=c-k
    ans=0
    for i in range(tmp):
        ans+=d[i]
    print(ans)