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.

Difficulty: interview

Starter code:

Solutions:
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 = list(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)


#https://codeforces.com/problemset/problem/1075/B

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)


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(list(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 list(d.keys()):
	z = len(d[i])
	if z>1:
		d[i].sort()
		l+=d[i][:z-1]
l.sort()
print(sum(l[:rem]))








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)]))


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 = list(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])

'''
print(a)
print(b)
print('--------')
print(d)
'''
for i in d:
    if len(d[i]) > 1:
        d[i].pop(d[i].index(max(d[i])))
        e.extend(d[i])
e.sort()
'''
print(d)
print(e)
'''

w = k - len(set(a))
#print(w)

#print(e[0:w])
print(sum(e[0:w]))








3
# -*- coding: utf-8 -*-

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 = 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)

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)

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)


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

    # Selection step, remove those with highest jobs

    idler_needed_nos = job_nos - job_chosen_nos
    for i in reversed(list(range(len(remain_tuples)-idler_needed_nos, len(remain_tuples)))):
        persuade_time += remain_tuples[i][1]

    return persuade_time
    # Persuade step


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())
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()))
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]))


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())
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)

#In the name of GOD!
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)


n,k=map(int,input().split())
a=map(int,input().split())
b=map(int,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=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]))

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, 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)

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)

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)]))


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)