The kingdom of Lazyland is the home to $n$ idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland. 

Today $k$ important jobs for the kingdom ($k \le n$) should be performed. Every job should be done by one person and every person can do at most one job. The King allowed every idler to choose one job they wanted to do and the $i$-th idler has chosen the job $a_i$. 

Unfortunately, some jobs may not be chosen by anyone, so the King has to persuade some idlers to choose another job. The King knows that it takes $b_i$ minutes to persuade the $i$-th idler. He asked his minister of labour to calculate the minimum total time he needs to spend persuading the idlers to get all the jobs done. Can you help him? 


-----Input-----

The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 10^5$) — the number of idlers and the number of jobs.

The second line of the input contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le k$) — the jobs chosen by each idler.

The third line of the input contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le 10^9$) — the time the King needs to spend to persuade the $i$-th idler.


-----Output-----

The only line of the output should contain one number — the minimum total time the King needs to spend persuading the idlers to get all the jobs done.


-----Examples-----
Input
8 7
1 1 3 1 5 3 7 1
5 7 4 8 1 3 5 2

Output
10

Input
3 3
3 1 2
5 3 4

Output
0



-----Note-----

In the first example the optimal plan is to persuade idlers 1, 6, and 8 to do jobs 2, 4, and 6.

In the second example each job was chosen by some idler, so there is no need to persuade anyone.

Source: codeforces | Difficulty: EASY


Solutions:
from sys import stdin
(n, k) = map(int, input().split())
jobs = list(map(int, stdin.readline().split()))
t = list(map(int, stdin.readline().split()))
exch = k - len(set(jobs))
doubleJobs = [0] * (k + 1)
timeOfDouble = []
for l in range(len(jobs)):
	if doubleJobs[jobs[l]] < t[l]:
		if doubleJobs[jobs[l]] != 0:
			timeOfDouble.append(doubleJobs[jobs[l]])
		doubleJobs[jobs[l]] = t[l]
	else:
		timeOfDouble.append(t[l])
timeOfDouble.sort()
print(sum(timeOfDouble[:exch]))


(n, k) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
d = {}
for i in range(n):
	if a[i] in d.keys():
		d[a[i]].append(b[i])
	else:
		d[a[i]] = [b[i]]
lst = []
for (key, v) in d.items():
	v.remove(max(v))
	lst.extend(v)
lst.sort()
ans = sum(lst[:k - len(d)])
print(ans)


(n, k) = list(map(int, input().strip().split()))
jobs = list(map(int, input().strip().split()))
times = list(map(int, input().strip().split()))
counts_jobs = {}
for job in jobs:
	if job in counts_jobs:
		counts_jobs[job] += 1
	else:
		counts_jobs[job] = 1
times_i = []
for (i, time) in enumerate(times):
	times_i.append((time, i))
times_i.sort()
jobs_left = k - len(counts_jobs.keys())
ans = 0
for (time, i) in times_i:
	if jobs_left == 0:
		break
	if counts_jobs[jobs[i]] > 1:
		ans += time
		jobs_left -= 1
		counts_jobs[jobs[i]] -= 1
print(ans)


(n, k) = map(int, input().split())
mas = list(map(int, input().split()))
lizt = list(map(int, input().split()))
di = {i: [] for i in range(1, k + 1)}
e = set()
for (i, x) in enumerate(mas):
	di[x].append(lizt[i])
	e.add(x)
c = k - len(e)
if c == 0:
	print(0)
	from sys import exit
	exit()
ops = []
for (i, x) in enumerate(di):
	m = 0
	for (j, y) in enumerate(di[x]):
		if m < y:
			m = y
	k = 0
	for (i, y) in enumerate(di[x]):
		if y != m:
			ops.append(y)
		elif k == 0:
			k = 1
		else:
			ops.append(y)
ops.sort()
print(sum(ops[:c]))


(n, k) = list(map(int, input().split()))
ideal = list(map(str, input().split()))
relocation = list(map(int, input().split()))
jobs = {}
uqjobs = {}
extra_jobs = []
for i in range(n):
	uqjobs[ideal[i]] = 1
	try:
		jobs[str(ideal[i])].append(relocation[i])
	except:
		jobs[str(ideal[i])] = [relocation[i]]
for i in jobs:
	if len(jobs[i]) > 1:
		jobs[i].sort()
		for j in range(len(jobs[i]) - 1):
			extra_jobs.append(jobs[i][j])
missing = 0
summ = 0
extra_jobs.sort()
for i in range(k - len(uqjobs)):
	summ += extra_jobs[i]
print(summ)


(n, k) = map(int, input().split())
jobs = [int(s) for s in input().split()]
cost = [int(s) for s in input().split()]
d = []
c = [0] * (k + 1)
for i in range(n):
	d.append((cost[i], jobs[i]))
	c[jobs[i]] += 1
rest = 0
for i in range(1, k + 1):
	if c[i] == 0:
		rest += 1
d.sort(key=lambda x: x[0])
allcost = 0
i = 0
while rest > 0:
	if c[d[i][1]] > 1:
		c[d[i][1]] -= 1
		allcost += d[i][0]
		rest -= 1
	i += 1
print(allcost)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations, permutations
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
(n, k) = r()
a = rr()
b = rr()
workers = Counter(a)
arr = [[i, j] for (i, j) in zip(a, b)]
arr.sort(key=lambda x: x[1])
need = k - len(set(a))
ans = 0
for (i, j) in arr:
	if not need:
		break
	if workers[i] > 1:
		workers[i] -= 1
		ans += j
		need -= 1
print(ans)


from itertools import zip_longest
from operator import itemgetter

def persuade(idler_nos, job_nos, job_chosen, idlers_persuade_time):
	persuade_time = 0
	job_chosen_nos = 0
	job_item_chosen = {}
	job_tuples = sorted(list(zip_longest(job_chosen, idlers_persuade_time)), key=itemgetter(1), reverse=True)
	remain_tuples = []
	for t in job_tuples:
		if t[0] not in job_item_chosen:
			job_item_chosen[t[0]] = 0
			job_chosen_nos += 1
		else:
			remain_tuples.append(t)
			pass
	idler_needed_nos = job_nos - job_chosen_nos
	for i in reversed(range(len(remain_tuples) - idler_needed_nos, len(remain_tuples))):
		persuade_time += remain_tuples[i][1]
	return persuade_time
(idler_nos, job_nos) = list(map(int, input().split()))
job_chosen = list(map(int, input().split()))
idlers_persuade_time = list(map(int, input().split()))
print('{}'.format(persuade(idler_nos, job_nos, job_chosen, idlers_persuade_time)))


(n, k) = map(int, input().split())
jobs = list(map(int, input().split()))
t = list(map(int, input().split()))
exch = k - len(set(jobs))
doubleJobs = [0] * (k + 1)
timeOfDouble = []
for l in range(len(jobs)):
	if doubleJobs[jobs[l]] < t[l]:
		if doubleJobs[jobs[l]] != 0:
			timeOfDouble.append(doubleJobs[jobs[l]])
		doubleJobs[jobs[l]] = t[l]
	else:
		timeOfDouble.append(t[l])
timeOfDouble.sort()
print(sum(timeOfDouble[:exch]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
t = list(map(int, input().split()))
d = {}
ans = []
for i in range(n):
	if l[i] in d:
		if d[l[i]] < t[i]:
			ans.append(d[l[i]])
			d[l[i]] = t[i]
		else:
			ans.append(t[i])
	else:
		d[l[i]] = t[i]
rem = k - len(d)
if rem > 0:
	ans.sort()
	print(sum(ans[:rem]))
else:
	print(0)


from collections import defaultdict as dd
from sys import stdin

def solve(a, b, n, q):
	jobs = dd(int)
	v = []
	for i in range(n):
		if not jobs[a[i]]:
			jobs[a[i]] = b[i]
		elif jobs[a[i]] < b[i]:
			v += [jobs[a[i]]]
			jobs[a[i]] = b[i]
		else:
			v += [b[i]]
	n1 = q - len(jobs)
	return sum(sorted(v)[:n1])

def bruh():
	(n, k) = [int(i) for i in stdin.readline().split()]
	a = [int(i) for i in stdin.readline().split()]
	b = [int(i) for i in stdin.readline().split()]
	print(solve(a, b, n, k))
bruh()


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
p = list(map(int, input().split()))
r = {}
r2 = []
for i in range(n):
	if s[i] in r:
		if r[s[i]] > p[i]:
			r2.append(p[i])
		else:
			r2.append(r[s[i]])
			r[s[i]] = p[i]
	else:
		r[s[i]] = p[i]
r1 = k - len(r)
print(sum(sorted(r2)[:r1]))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
no_id = [1] * k
pers_kn = []
for i in range(k):
	pers_kn.append([])
for i in range(n):
	pers_kn[a[i] - 1].append(i)
	no_id[a[i] - 1] = 0
no_job = sum(no_id)
cans = []
for p in pers_kn:
	if len(p) > 1:
		mx_index = 0
		mx = 0
		for t in p:
			if b[t] > mx:
				mx = b[t]
				mx_index = t
		for t in p:
			if t != mx_index:
				cans.append(b[t])
cans.sort()
print(sum(cans[:no_job]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(n):
	if a[i] not in d:
		d[a[i]] = [b[i]]
	else:
		d[a[i]].append(b[i])
p = []
for dd in d:
	z = sorted(d[dd])
	for i in range(len(z) - 1):
		p.append(z[i])
p = sorted(p)
s = 0
for i in range(k - len(d)):
	s += p[i]
print(s)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from heapq import *
(n, k) = f()
jb = il()
x = k - len(set(jb))
pql = []
l = [[i, j] for (i, j) in zip(jb, il())]
l.sort()
for i in range(n - 1):
	if l[i][0] == l[i + 1][0]:
		heappush(pql, l[i][1])
print(sum(nsmallest(x, pql)))


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [0] * k
d = []
for (ai, bi) in zip(a, b):
	if c[ai - 1] != 0:
		d.append(min(c[ai - 1], bi))
	else:
		k -= 1
	c[ai - 1] = max(c[ai - 1], bi)
d.sort()
print(sum(d[:k]))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dd = {}
for i in range(len(a)):
	if a[i] not in dd:
		dd[a[i]] = [b[i]]
	else:
		dd[a[i]].append(b[i])
lst = []
for j in dd:
	dd[j].sort()
	dd[j].pop()
	lst += dd[j]
lst.sort()
l = lst[:k - len(set(a))]
print(sum(l))


3
import sys

def rl(proc=None):
	if proc is not None:
		return proc(sys.stdin.readline())
	else:
		return sys.stdin.readline().rstrip()

def srl(proc=None):
	if proc is not None:
		return list(map(proc, rl().split()))
	else:
		return rl().split()

def main():
	(n, k) = srl(int)
	A = srl(int)
	B = srl(int)
	spare = []
	done = [-1] * k
	for i in range(n):
		task = A[i] - 1
		if done[task] == -1:
			done[task] = B[i]
			continue
		spare.append(min(done[task], B[i]))
		done[task] = max(done[task], B[i])
	spare.sort()
	i = 0
	r = 0
	for d in done:
		if d == -1:
			r += spare[i]
			i += 1
	print(r)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dic = {}
for (i, f) in zip(a, b):
	if i in dic:
		dic[i] += [f]
	else:
		dic[i] = [f]
for (_, value) in dic.items():
	value.sort()
	value.pop()
	k -= 1
res = []
for (_, value) in dic.items():
	for v in value:
		res.append(v)
res.sort()
print(sum(res[:k]))


(n, k) = map(int, input().split())
job_want = list(map(int, input().split()))
psd_time = list(map(int, input().split()))
daf = []
for i in range(n):
	daf.append([psd_time[i], job_want[i]])
job_left = set([i + 1 for i in range(k)])
daf.sort(reverse=True)
for i in range(n):
	if daf[i][1] in job_left:
		job_left.remove(daf[i][1])
		daf[i][1] = 0
daf = [[daf[i][0], daf[i][1]] for i in range(n) if daf[i][1] != 0]
daf = daf[::-1]
total = 0
for i in range(len(job_left)):
	total += daf[i][0]
print(total)


(n, j) = map(int, input().split())
A = list(map(int, input().split()))
V = list(map(int, input().split()))
M = {}
for (i, a) in enumerate(A):
	if a not in M:
		M[a] = [V[i]]
	else:
		M[a].append(V[i])
Ava = []
for m in M:
	if len(M[m]) > 1:
		M[m].sort()
		for i in range(len(M[m]) - 1):
			Ava += [M[m][i]]
Ava.sort()
ans = sum(Ava[:max(0, j - len(M))])
print(ans)


class Worker:

	def __init__(self, j, c):
		self.job = j
		self.cost = c

def read(type=1):
	if type:
		file = open('input.dat', 'r')
		line = list(map(int, file.readline().split()))
		a = list(map(int, file.readline().split()))
		b = list(map(int, file.readline().split()))
		file.close()
	else:
		line = list(map(int, input().strip().split()))
		a = list(map(int, input().strip().split()))
		b = list(map(int, input().strip().split()))
	c = []
	for i in range(line[0]):
		c.append(Worker(a[i], b[i]))
	return (line[0], line[1], c)

def solve():
	sols = [0 for i in range(k)]
	c = sorted(a, key=lambda x: x.cost, reverse=True)
	jobs = 0
	mins = []
	for i in range(n):
		if sols[c[i].job - 1]:
			mins.append(c[i].cost)
		else:
			jobs += 1
			sols[c[i].job - 1] = 1
	sol = 0
	for i in range(k - jobs):
		sol += mins[len(mins) - i - 1]
	return sol
(n, k, a) = read(0)
sol = solve()
print(sol)


(n, m) = map(int, input().split())
a = {}
R = lambda : map(int, input().split())
for (x, y) in zip(R(), R()):
	if x not in a:
		a[x] = []
	a[x] += (y,)
b = []
for (_, v) in a.items():
	t = sorted(v)
	t.pop()
	b += t
print(sum(sorted(b)[:m - len(a)]))


from collections import defaultdict

def delmax(lst):
	l = len(lst)
	if l == 0:
		return 0
	m = 0
	for i in range(l):
		v = lst[i]
		if v > m:
			(m, n) = (v, i)
	del lst[n]
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d = defaultdict(list)
for i in range(n):
	d[a[i]].append(b[i])
save = []
for key in d:
	u = d[key]
	delmax(u)
	save.extend(u)
save.sort(reverse=True)
del save[:n - k]
print(sum(save))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = list(zip(*sorted(zip(b, a))))
count = 0
result = 0
cnt = [0] * (n + 1)
count = k - len(set(a))
for i in a:
	cnt[i] += 1
for i in range(n):
	if count == 0:
		break
	if cnt[res[1][i]] == 1:
		continue
	else:
		cnt[res[1][i]] -= 1
		result += res[0][i]
		count -= 1
print(result)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
from io import BytesIO
import threading
import bisect
import operator
import heapq
input = lambda : sys.stdin.readline().rstrip('\r\n')

class C:

	def __init__(self, job, per):
		self.job = job
		self.per = per

	def __repr__(self):
		pass
(n, m) = map(int, input().split())
finAr = [C] * n
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))
for i in range(n):
	finAr[i] = C(listA[i], listB[i])
new_list = sorted(finAr, key=operator.attrgetter('per'), reverse=True)
arWord = []
sDone = set()
for i in range(n):
	if new_list[i].job not in sDone:
		sDone.add(new_list[i].job)
	else:
		arWord.append(new_list[i].per)
arWord.sort()
answer = 0
for i in range(m - len(sDone)):
	answer += arWord[i]
print(answer)


from operator import itemgetter
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
A = []
B = []
s = []
max = 0
sum = 0
c = k - len(set(a))
if c == 0:
	print(0)
else:
	for i in range(n):
		A.append((a[i], b[i]))
	B = sorted(A, key=itemgetter(0))
	max = B[0][1]
	for j in range(n - 1):
		if B[j][0] == B[j + 1][0]:
			if max < B[j + 1][1]:
				s.append(max)
				max = B[j + 1][1]
			else:
				s.append(B[j + 1][1])
		else:
			max = B[j + 1][1]
	s.sort()
	for k in range(c):
		sum += s[k]
	print(sum)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tmp = {}
var = []
for (x, y) in zip(a, b):
	old = tmp.get(x, -1)
	if y > old:
		if old > -1:
			var.append(old)
		tmp[x] = y
	else:
		var.append(y)
var.sort()
print(sum(var[:k - len(tmp)]))


l1 = [int(x) for x in input().split()]
(n, k) = (l1[0], l1[1])
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = []
d = []
for x in range(len(a)):
	if a[x] not in c:
		c.append(a[x])
		d.append([b[x]])
	else:
		d[c.index(a[x])].append(b[x])
for x in d:
	x.remove(max(x))
f = []
for x in d:
	for y in x:
		f.append(y)
f.sort()
print(sum(f[:k - len(d)]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
for i in range(n):
	l.append([a[i], b[i]])
l.sort()
l1 = []
for i in range(n - 1):
	if l[i][0] == l[i + 1][0]:
		l1.append(l[i][1])
l1.sort()
req = k - (n - len(l1))
sum1 = 0
for i in range(req):
	sum1 = sum1 + l1[i]
print(sum1)


n_k = input().split()
n = int(n_k[0])
k = int(n_k[1])
N = input().split()
T = input().split()
Svoboda = []
if len(set(N)) == n:
	s = 0
else:
	dict47 = {}
	j = 0
	for i in N:
		if i not in dict47:
			temp = {int(i): int(T[j])}
			dict47[i] = int(T[j])
		elif dict47.get(i) < int(T[j]):
			Svoboda.append(int(dict47.get(i)))
			dict47[i] = int(T[j])
		else:
			Svoboda.append(int(T[j]))
		j += 1
j = int(len(set(N)))
s = 0
Svoboda.sort()
for i in range(0, len(Svoboda)):
	if j < k:
		s += int(Svoboda[i])
		j += 1
print(s)


I = lambda : map(int, input().split())
(n, k) = I()
a = (*I(),)
b = (*I(),)
c = [0] * (k + 1)
for x in a:
	c[x] += 1
l = k - len({*a})
a = sorted(zip(b, a))
r = 0
for i in range(n):
	if l < 1:
		break
	if c[a[i][1]] > 1:
		r += a[i][0]
		c[a[i][1]] -= 1
		l -= 1
print(r)


from collections import defaultdict

def ans(a, b):
	tmp = defaultdict(list)
	for i in range(0, n):
		tmp[a[i]].append(i)
	if len(tmp.keys()) == k:
		return 0
	length = k - len(tmp.keys())
	dmp = []
	for i in tmp.keys():
		if len(tmp[i]) > 1:
			dmp.append(tmp[i])
	dmp = sorted(dmp, key=lambda x: len(x))
	cnt = 0
	temp = []
	for i in dmp:
		max_ = []
		for j in i:
			max_.append([b[j], j])
		max_.sort(reverse=True)
		max_.pop(0)
		temp += max_[:]
	temp.sort()
	temp = temp[:length]
	for i in temp:
		cnt += i[0]
	return cnt
nk = list(map(int, input().strip().split()))
(n, k) = (nk[0], nk[1])
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
print(ans(a, b))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	a[i] -= 1
tk = [0] * n
tm = []
for i in range(n):
	if tk[a[i]] == 0:
		tk[a[i]] = b[i]
	elif tk[a[i]] < b[i]:
		tm.append(tk[a[i]])
		tk[a[i]] = b[i]
	else:
		tm.append(b[i])
ans = cnt = 0
tm.sort()
for i in range(k):
	if tk[i] == 0:
		ans += tm[cnt]
		cnt += 1
print(ans)


a = list(map(int, input().split()))
idlers = a[0]
jobs = a[1]
choices = list(map(int, input().split()))
persuade = list(map(int, input().split()))
count_rep = []
count = {}
for i in range(len(choices)):
	if choices[i] not in count:
		count[choices[i]] = 1
	else:
		count_rep.append(choices[i])
count_rep_set = set(count_rep)
pers = {}
for j in count_rep_set:
	pers[j] = []
for k in range(len(choices)):
	if choices[k] in count_rep_set:
		pers[choices[k]].append(persuade[k])
mergedList = []
for key in pers.keys():
	pers[key].sort()
	pers[key].pop()
	mergedList += pers[key]
mergedList.sort()
num = jobs - len(set(choices))
sum = 0
for l in range(num):
	sum += mergedList[l]
print(sum)


from collections import Counter
(n, k) = map(int, input().split())
jobs = list(map(int, input().split()))
time = list(map(int, input().split()))
jobs_left = set(range(1, k + 1)) - set(jobs)
if len(jobs_left) == 0:
	print(0)
else:
	times = {}
	for i in range(k):
		times[i + 1] = []
	for i in range(len(jobs)):
		times[jobs[i]].append(time[i])
	extra_times = []
	for (key, value) in times.items():
		extra_times.extend(sorted(value)[:-1])
	print(sum(sorted(extra_times)[:len(jobs_left)]))


(n, k) = map(int, input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
ans = dict()
rem = []
for i in range(n):
	if alist[i] in ans:
		if blist[i] > ans[alist[i]]:
			rem += [ans[alist[i]]]
			ans[alist[i]] = blist[i]
		else:
			rem += [blist[i]]
	else:
		ans[alist[i]] = blist[i]
srem = sorted(rem)
index = 0
answer = 0
for i in range(1, k + 1):
	if not i in ans:
		answer += srem[index]
		index += 1
print(answer)


(n, k) = map(int, input().split())
chosen_job = list(map(int, input().split()))
time_persuade = list(map(int, input().split()))
jobs = []
for i in range(n):
	jobs.append((time_persuade[i], chosen_job[i]))
jobs.sort(reverse=True)
done = [False] * (1 + k)
can_persuade = []
for (time, job) in jobs:
	if not done[job]:
		done[job] = True
	else:
		can_persuade.append(time)
total_time = 0
id_job = len(can_persuade) - 1
for job in range(1, k + 1):
	if not done[job]:
		total_time += can_persuade[id_job]
		id_job -= 1
print(total_time)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
e = []
for i in range(n):
	if a[i] not in d:
		d[a[i]] = [b[i]]
	else:
		d[a[i]].append(b[i])
for i in d:
	if len(d[i]) > 1:
		d[i].pop(d[i].index(max(d[i])))
		e.extend(d[i])
e.sort()
w = k - len(set(a))
print(sum(e[0:w]))


from sys import stdin
(n, k) = map(int, input().split())
a = list(map(int, next(stdin).split()))
b = list(map(int, next(stdin).split()))
ans = 0
done = [0] * (k + 1)
unn = []
for i in range(n):
	if not done[a[i]]:
		done[a[i]] = b[i]
	elif done[a[i]] <= b[i]:
		unn.append(done[a[i]])
		done[a[i]] = b[i]
	else:
		unn.append(b[i])
print(sum(sorted(unn)[:k - len(set(a))]))


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
i = 0
done = {}
different = 0
dif = set()
for item in a:
	if item not in dif:
		dif.add(item)
		different += 1
	if item not in done:
		done[item] = [b[i]]
	else:
		done[item].append(b[i])
	i += 1
tot = []
for item in done:
	done[item].sort()
	for i in done[item]:
		tot.append(i)
	tot.pop()
tot.sort()
counter = 0
for item in range(k - different):
	counter += tot[item]
print(counter)


(n, k) = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
t = [[a[i], b[i]] for i in range(n)]
t.sort(key=lambda x: [x[0], -x[1]])
now = t[0][0]
time = []
chosen = 1
for i in range(1, n):
	if t[i][0] != now:
		chosen += 1
		now = t[i][0]
	else:
		time.append(t[i][1])
time.sort()
print(sum(time[:k - chosen]))


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import combinations
import sys
import math
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN():
	return map(int, sys.stdin.readline().strip().split())

def charIN():
	return sys.stdin.readline().strip().split()
(n, k) = numIN()
a = list(numIN())
b = list(numIN())
x = [0] * MAXN
d = {}
for i in range(n):
	if not x[a[i]]:
		x[a[i]] = 1
		d[a[i]] = [b[i]]
	else:
		d[a[i]].append(b[i])
rem = x[1:k + 1].count(0)
l = []
for i in d.keys():
	z = len(d[i])
	if z > 1:
		d[i].sort()
		l += d[i][:z - 1]
l.sort()
print(sum(l[:rem]))


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = dict()
timeConsumed = []
for i in range(n):
	if a[i] in d:
		if d[a[i]] > b[i]:
			timeConsumed.append(b[i])
		else:
			timeConsumed.append(d[a[i]])
			d[a[i]] = b[i]
	else:
		d[a[i]] = b[i]
jobs = k - len(d)
print(sum(sorted(timeConsumed)[:jobs]))


def main_function():
	(n, k) = [int(i) for i in input().split(' ')]
	a_n = [int(i) for i in input().split(' ')]
	b_n = [int(i) for i in input().split(' ')]
	s_n = [[a_n[i], b_n[i]] for i in range(n)]
	s_n.sort(key=lambda x: (x[0], x[1]))
	collector = []
	intermediate_closest = 100000000000000000
	for i in range(len(s_n)):
		if intermediate_closest != s_n[i][0]:
			collector.append([s_n[i]])
			intermediate_closest = s_n[i][0]
		else:
			collector[-1].append(s_n[i])
	collector_2 = []
	for i in range(len(collector)):
		if len(collector[i]) > 1:
			for j in range(len(collector[i]) - 1):
				collector_2.append(collector[i][j][1])
	needed = max(0, k - len(list(set(a_n))))
	collector_2.sort()
	time = 0
	for i in range(needed):
		time += collector_2[i]
	return time
print(main_function())


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = [0] * n
d = [0] * k
t = list(range(1, n + 1))
for i in range(n):
	if c[a[i] - 1] < b[i]:
		c[a[i] - 1] = b[i]
		d[a[i] - 1] = t[i]
rp = list(set(t) - set(d))
t2 = [0] * len(rp)
for i in range(len(rp)):
	t2[i] = b[rp[i] - 1]
t2.sort()
rj = d.count(0)
s = sum(t2[:rj])
print(s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
chose = []
for i in range(k):
	chose.append([])
for i in range(n):
	chose[a[i] - 1].append(b[i])
for i in range(k):
	chose[i].sort()
notdone = 0
useful = []
for i in range(k):
	l = len(chose[i])
	if l == 0:
		notdone += 1
	else:
		useful += chose[i][:-1]
useful.sort()
print(sum(useful[:notdone]))


def run():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	j = [[] for i in range(k)]
	(ex, nj) = ([], [])
	for i in range(n):
		j[a[i] - 1].append(b[i])
	for i in range(k):
		j[i].sort()
		if not len(j[i]):
			nj.append(i)
			continue
		ex += j[i][:-1]
	ex.sort()
	to = len(nj)
	print(sum(ex[0:to]))
run()


from collections import Counter
I = lambda : map(int, input().split())
(_, k) = I()
A = list(I())
C = Counter(A)
B = []
x = 0
for (b, a) in sorted(zip(I(), A)):
	if C[a] > 1:
		B.append(b)
		C[a] -= 1
	else:
		x += 1
print(sum(B[:k - x]))


(N, K) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
rec = [[] for i in range(K)]
for i in range(N):
	rec[a[i] - 1].append(i)
S = 0
rec2 = []
num = 0
for i in range(K):
	if len(rec[i]) > 0:
		S += 1
	if len(rec[i]) >= 1:
		rec[i] = sorted(rec[i], key=lambda x: -b[x])
		rec2 += rec[i][1:]
rec2 = sorted(rec2, key=lambda x: b[x])
for i in range(K - S):
	num += b[rec2[i]]
print(num)


import sys
import math
import bisect

def solve(A, B, m):
	n = len(A)
	d = dict()
	for i in range(n):
		if A[i] not in d:
			d[A[i]] = []
		d[A[i]].append(B[i])
	m -= len(d)
	C = []
	for k in d:
		d[k].sort()
		C.extend(d[k][:-1])
	C.sort()
	return sum(C[:m])

def main():
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = solve(A, B, m)
	print(ans)
main()


from collections import Counter
(n, k) = map(int, input().split())
jobs = list(map(int, input().split()))
time = list(map(int, input().split()))
chosen = len(set(jobs))
if chosen == k:
	print(0)
else:
	total = 0
	c = Counter(jobs)
	for i in range(n):
		time[i] = (time[i], jobs[i])
	time = sorted(time)
	for t in time:
		if c[t[1]] > 1:
			c[t[1]] -= 1
			total += t[0]
			chosen += 1
		if chosen == k:
			break
	print(total)


from sys import stdin, stdout, setrecursionlimit
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd, sqrt, factorial, log2, floor
from bisect import bisect_right as br, bisect_left as bl
import heapq
(n, k) = mp()
(a, b) = (mp(), mp())
x = set(a)
k = k - len(x)
d = dd(list)
for i in range(n):
	d[a[i]].append(b[i])
l = []
for i in d:
	d[i].sort()
	d[i].pop()
	l.extend(d[i])
l.sort()
print(sum(l[:k]))


I = lambda : map(int, input().split())
(_, k) = I()
B = []
C = [0] * (k + 1)
for (a, b) in zip(I(), I()):
	if C[a]:
		B.append(min(C[a], b))
	else:
		k -= 1
	C[a] = max(C[a], b)
print(sum(sorted(B)[:k]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
p = list(map(int, input().split()))
d = {}
d2 = []
for i in range(n):
	if l[i] in d:
		if d[l[i]] > p[i]:
			d2.append(p[i])
		else:
			d2.append(d[l[i]])
			d[l[i]] = p[i]
	else:
		d[l[i]] = p[i]
len = k - len(d)
print(sum(sorted(d2)[:len]))


from functools import lru_cache, reduce
from sys import setrecursionlimit
import math
nk = tuple(map(int, input().strip().split()))
job = list(map(int, input().strip().split()))
time = list(map(int, input().strip().split()))
time_job = []
for i in range(nk[0]):
	time_job.append((time[i], job[i]))
time_job.sort()
job.sort()
done = dict()
prec = -1
for i in job:
	if i != prec:
		done[i] = 1
	else:
		done[i] = done[i] + 1
	prec = i
leninit = len(done)
sumz = 0
for v in time_job:
	if nk[1] <= leninit:
		break
	if done[v[1]] > 1:
		done[v[1]] = done[v[1]] - 1
		sumz += v[0]
		leninit += 1
print(sumz)


(n, k) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
sor = []
for (i, j) in zip(arr2, arr1):
	sor.append([i, j])
sor = sorted(sor, reverse=True)
jobs = set(range(1, k + 1))
double = []
seen = set()
for (i, j) in sor:
	if j in seen:
		double.append(i)
	else:
		seen.add(j)
		jobs.remove(j)
double.sort()
ln = len(jobs)
ans = double[:ln]
print(sum(ans))


from heapq import *
(n, k) = map(int, input().split())
jb = list(map(int, input().split()))
x = k - len(set(jb))
pql = []
l = [[i, j] for (i, j) in zip(jb, list(map(int, input().split())))]
l.sort()
for i in range(n - 1):
	if l[i][0] == l[i + 1][0]:
		heappush(pql, l[i][1])
print(sum(nsmallest(x, pql)))


X = list(map(int, input().split()))
(CheckJobs, Remain) = ([False] * X[1], [])
People = sorted(zip(list(map(int, input().split())), list(map(int, input().split()))), key=lambda x: x[1], reverse=True)
for i in range(X[0]):
	if CheckJobs[People[i][0] - 1]:
		Remain.append(People[i][1])
	CheckJobs[People[i][0] - 1] = True
Remain = sorted(Remain)
print(sum(Remain[:CheckJobs.count(False)]))


(n, k) = input().split()
n = int(n)
k = int(k)
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
p = {}
for i in range(len(a)):
	if a[i] in p:
		p[a[i]].append(i)
	else:
		p[a[i]] = [i]
t = {}
for book in p:
	if len(p[book]) > 1:
		t[book] = []
		for i in p[book]:
			t[book].append(b[i])
ti = 0
u = []
for book in t:
	t[book].sort()
	u += t[book][:len(t[book]) - 1]
u.sort()
for i in range(k - len(p)):
	ti += u[i]
print(ti)


from math import sqrt

def phi(u):
	ans = u
	for i in range(2, int(sqrt(n)) + 1):
		if u % i == 0:
			while u % i == 0:
				u = u / i
			ans = ans - int(ans / i)
	if n > 1:
		ans = ans - int(ans / n)
	return ans

def binpow(u, a, mod):
	ans = 1
	if a == 0:
		return 1
	while a > 0:
		if a % 2 == 0:
			u = u ** 2 % mod
			a = int(a / 2)
		else:
			ans = ans * u % mod
			a = a - 1
	return int(ans)

def ffind(s, u):
	if u == 0:
		return -1
	ans = -1
	while u > 0:
		ans = s.find('1', ans + 1)
		u = u - 1
	return ans
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = -1
mn = [x] * (k + 1)
t = []
for i in range(n):
	if mn[a[i]] < b[i]:
		if mn[a[i]] != x:
			t.append(mn[a[i]])
		mn[a[i]] = b[i]
	else:
		t.append(b[i])
t.sort()
if n - len(t) == k:
	print(0)
else:
	print(sum(t[:k - n + len(t)]))


idle = []
(n, k) = map(int, input().split())
d = {i + 1: -1 for i in range(k)}
a = list(map(int, input().split()))
b = list(map(int, input().split()))
q = k
for i in range(n):
	if d[a[i]] < b[i]:
		if d[a[i]] != -1:
			idle += [d[a[i]]]
		else:
			q -= 1
		d[a[i]] = b[i]
	else:
		idle += [b[i]]
print(sum(sorted(idle)[:q]))


(n, k) = list(map(int, str(input()).split()))
a = list(map(int, str(input()).split(' ')))
b = list(map(int, str(input()).split(' ')))
l = []
for i in range(0, k):
	l.append(0)
for i in range(0, n):
	if b[i] > l[a[i] - 1]:
		t = b[i]
		b[i] = l[a[i] - 1]
		l[a[i] - 1] = t
b.sort(reverse=True)
for i in range(0, n - k):
	b[i] = 0
print(sum(b))