Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.

In total the table Arthur bought has n legs, the length of the i-th leg is l_{i}.

Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d_{i} — the amount of energy that he spends to remove the i-th leg.

A table with k legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.

Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.


-----Input-----

The first line of the input contains integer n (1 ≤ n ≤ 10^5) — the initial number of legs in the table Arthur bought.

The second line of the input contains a sequence of n integers l_{i} (1 ≤ l_{i} ≤ 10^5), where l_{i} is equal to the length of the i-th leg of the table.

The third line of the input contains a sequence of n integers d_{i} (1 ≤ d_{i} ≤ 200), where d_{i} is the number of energy units that Arthur spends on removing the i-th leg off the table.


-----Output-----

Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.


-----Examples-----
Input
2
1 5
3 2

Output
2

Input
3
2 4 4
1 1 1

Output
0

Input
6
2 2 1 1 3 3
4 3 5 5 2 1

Output
8

Difficulty: interview

Starter code:

Solutions:
from collections import defaultdict


def main():
    n = int(input())
    hh = list(map(int, input().split()))
    ee = list(map(int, input().split()))
    dd = defaultdict(set)
    for i, h in enumerate(hh):
        dd[h].add(i)
    idx = sorted(list(range(n)), key=ee.__getitem__, reverse=True)
    res = 0
    for h, s in list(dd.items()):
        x = sum(ee[i] for i in s)
        le = len(s) - 1
        if le:
            for i in idx:
                if hh[i] < h and i not in s:
                    x += ee[i]
                    le -= 1
                    if not le:
                        break
        if res < x:
            res = x
    print(sum(ee) - res)


def __starting_point():
    main()

__starting_point()

def read_data():
    n = int(input())
    Ls = list(map(int, input().split()))
    Ds = list(map(int, input().split()))
    return n, Ls, Ds

def solve(n, Ls, Ds):
    freqD = [0] * 201
    for d in Ds:
        freqD[d] += 1
    LDs = list(zip(Ls, Ds))
    LDs.sort(reverse = True)
    prevL = 0
    ni = 0
    record = float('inf')
    cost_long = 0
    cost_me = 0
    for L, D in LDs:
        if prevL != L:
            n -= ni
            record = min(record, cost_long + calc_cost(ni, n, freqD))
            prevL = L
            ni = 0
            cost_long += cost_me
            if cost_long >= record:
                return record
            cost_me = 0
        freqD[D] -= 1
        cost_me += D
        ni += 1
    record = min(record, cost_long)
    return record

def calc_cost(ni, n, freqD):
    if n < ni:
        return 0
    cost = 0
    for d, f in enumerate(freqD):
        if n - f >= ni:
            cost += f * d
            n -= f
        else:
            cost += (n - ni + 1) * d
            return cost
    return float('inf')

n, Ls, Ds = read_data()
print(solve(n, Ls, Ds))

def main():
    _, dd, res = input(), {}, 0
    he = list(zip(list(map(int, input().split())), list(map(int, input().split()))))
    for h, e in he:
        le, x = dd.get(h, (-1, 0))
        dd[h] = (le + 1, x + e)
    he.sort(key=lambda _: _[1], reverse=True)
    for h, (le, x) in list(dd.items()):
        if le:
            for h1, e in he:
                if h1 < h:
                    x += e
                    le -= 1
                    if not le:
                        break
        if res < x:
            res = x
    print(sum(e for h, e in he) - res)


def __starting_point():
    main()

__starting_point()

n = int(input())
INF = -1
arr = [0] * n
d = [0] * 201
l = list(map(int, input().split()))
e = list(map(int, input().split()))
s = 0
for i in range(n):
    arr[i] = (l[i], e[i])
    s += e[i]
    d[e[i]] += 1
l = []
e = []
ans = [INF] * 3
ans[2] = 10 ** 10

p = arr[-1][0]
k = [0, 0]        
arr.sort()
arr = [(-1, -1)] + arr
e = 0
c = 0
for i in range(n, -1, -1):
    if arr[i][0] == p:
        c += 1
        e += arr[i][1]
        d[arr[i][1]] -= 1
    else:
        if c == 1:
            ans[0] = max(ans[0], e)
        elif c == 2:
            ans[1] = max(ans[1], arr[i + 1][1] + arr[i + 2][1])        
        if c >= 2:
            mx = c + c - 1
            eng = k[1]
            if k[0] >= n - mx:
                ans[2] = min(ans[2], eng)
            else:
                g = n - mx - k[0]
                j = 1
                while j < 201 and g > 0:
                    if d[j] > 0:
                        if g > d[j]:
                            eng += d[j] * j
                            g -= d[j]
                        else:
                            eng += g * j
                            g = 0
                    j += 1
                if g == 0:
                    ans[2] = min(ans[2], eng)                     
        k[0] += c
        k[1] += e
        c = 1
        e = arr[i][1]
        d[arr[i][1]] -= 1
        p = arr[i][0]
mn = 10 ** 10
for i in range(2):
    ans[i] = s - ans[i]
for i in range(3):
    if ans[i] != -1 and mn > ans[i]:
        mn = ans[i]
if mn != 10 ** 10:
    print(mn)
else:
    print(0)
        




n = int(input())
lengths = list(map(int, input().split()))
costs = list(map(int, input().split()))
sum = 0
length_to_sum = {}
length_to_count = {}
cost_to_lengths = {}

for i in range(n):
  length, cost = lengths[i], costs[i]
  sum += cost
  length_to_sum[length] = length_to_sum.setdefault(length, 0) + cost
  length_to_count[length] = length_to_count.setdefault(length, 0) + 1
  cost_to_lengths.setdefault(cost, []).append(length)

length_set = set(lengths)
for lengths in list(cost_to_lengths.values()):
  lengths.sort()
unique_costs = list(reversed(sorted(cost_to_lengths.keys())))
best = -1

for length in length_set:
  total = sum - length_to_sum[length]
  seek = length_to_count[length] - 1
  if seek != 0:
    for cost in unique_costs:
      for x in cost_to_lengths[cost]:
        if x >= length:
          break
        total -= cost
        seek -= 1
        if seek == 0:
          break
      if seek == 0:
        break
  if best == -1 or total < best:
    best = total

print(best)


#!/usr/bin/env python
# 557C_table.py - Codeforces.com 557C Table quiz
#
# Copyright (C) 2015 Sergey
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Input

The first line of the input contains integer n  the initial number of legs
in the table Arthur bought.

The second line of the input contains a sequence of n integers li, where
li is equal to the length of the i-th leg of the table.

The third line of the input contains a sequence of n integers di, where di
is the number of energy units that Arthur spends on removing the i-th leg
off the table.
Output

Print a single integer the minimum number of energy units that Arthur
needs to spend in order to make the table stable.
"""

# Standard libraries
import unittest
import sys
import re
import random
import bisect

# Additional libraries


###############################################################################
# Table Class
###############################################################################


class Table:
    """ Table representation """

    LIM = 201

    def __init__(self, args):
        """ Default constructor """

        self.legs = args[0]
        self.energy = args[1]
        self.n = len(self.legs)

        # Sort lists
        self.srt = sorted((l, e) for l, e in zip(self.legs, self.energy))
        self.legs = []
        self.energy = []
        for n in self.srt:
            self.legs.append(n[0])
            self.energy.append(n[1])

        # Prepare accumulator variables

        self.itot = 0
        self.ieltot = [0 for i in range(self.LIM)]
        self.ielprev = [0 for i in range(self.LIM)]
        self.ielprev_eng = 0
        self.ires_eng = sys.maxsize

    def get_new_layer_info(self, legs, energy):

        ll = len(legs)
        for (i, l) in enumerate(legs):

            self.ilen = l
            e = energy[i]

            if i == 0:
                self.itop_eng = sum(energy)

            if i == 0 or self.ilen != prev:
                self.irep = 0
                self.ielsum_eng = 0
                self.ielprev = list(self.ieltot)

            self.irep += 1

            self.itop_eng -= e
            self.ielprev_eng += e
            self.ielsum_eng += e
            self.ieltot[e] += 1

            if i == ll - 1 or legs[i+1] != self.ilen:
                self.irem = self.irep - 1
                self.irem_eng = self.ielprev_eng - self.ielsum_eng
                if self.irem != 0:
                    sumh = self.energyl_sum_high(self.ielprev, self.irem)
                    self.irem_eng -= sumh
                summ = self.itop_eng + self.irem_eng
                self.ires_eng = min(self.ires_eng, summ)
                yield
            prev = self.ilen

    def energyl_sum_high(self, l, n):
        result = 0
        for i in range(len(l) - 1, -1, -1):
            e = l[i]
            if e == 0:
                continue
            if n <= 0:
                break
            result += i * (n if e > n else e)
            n -= e
        return result

    def calculate(self):
        """ Main calcualtion function of the class """

        iter = self.get_new_layer_info(self.legs, self.energy)

        for g in iter:
            pass

        result = self.ires_eng

        return str(result)


###############################################################################
# Executable code
###############################################################################


def get_inputs(test_inputs=None):

    it = iter(test_inputs.split("\n")) if test_inputs else None

    def uinput():
        """ Unit-testable input function wrapper """
        if it:
            return next(it)
        else:
            return input()

    # Getting string inputs. Place all uinput() calls here
    num = int(uinput())
    str1 = [int(s) for s in uinput().split()]
    str2 = [int(s) for s in uinput().split()]

    # Decoding inputs into a list
    inputs = []
    inputs.append(str1)
    inputs.append(str2)

    return inputs


def calculate(test_inputs=None):
    """ Base class calculate method wrapper """
    return Table(get_inputs(test_inputs)).calculate()


###############################################################################
# Unit Tests
###############################################################################


class unitTests(unittest.TestCase):

    def test_sample_tests(self):
        """ Quiz sample tests. Add \n to separate lines """

        # my tests
        imax = 100000
        test = "0\n"
        for i in range(imax):
            test += str(i) + " "
        test += "\n"
        for i in range(imax):
            test += str(random.randint(1, 200)) + " "
        calculate(test)

        # Sample test 1
        test = "2\n1 5\n3 2"
        self.assertEqual(calculate(test), "2")
        self.assertEqual(get_inputs(test), [[1, 5], [3, 2]])

        # Other tests
        test = "3\n2 4 4\n1 1 1"
        self.assertEqual(calculate(test), "0")
        test = "6\n2 2 1 1 3 3\n4 3 5 5 2 1"
        self.assertEqual(calculate(test), "8")

        test = (
            "10\n20 1 15 17 11 2 15 3 16 3\n" +
            "129 114 183 94 169 16 18 104 49 146")
        self.assertEqual(calculate(test), "652")

    def test_Table_class__basic_functions(self):
        """ Table class basic functions testing """

        # Constructor test
        d = Table([[2, 2, 1, 1, 3, 3], [2, 2, 3, 3, 1, 1]])
        self.assertEqual(d.legs[0], 1)
        self.assertEqual(d.energy[0], 3)

        # Get layer info (length, number of legs, energy list, energy sum)
        iter = d.get_new_layer_info([1, 1, 2, 2, 4, 5], [2, 2, 3, 3, 1, 1])
        next(iter)
        self.assertEqual(d.itop_eng, 8)
        self.assertEqual(d.ilen, 1)
        self.assertEqual(d.irep, 2)
        self.assertEqual(d.irem, 1)
        self.assertEqual(d.irem_eng, 0)
        self.assertEqual(d.ires_eng, 8)

        next(iter)
        self.assertEqual(d.ilen, 2)
        self.assertEqual(d.irep, 2)
        self.assertEqual(d.irem, 1)
        self.assertEqual(d.irem_eng, 2)
        self.assertEqual(d.ires_eng, 4)

        # Get layer info (length, number of legs, energy list, energy sum)
        d = Table([[], []])
        iter = d.get_new_layer_info([1, 1, 2, 2, 3, 3], [5, 5, 4, 3, 2, 1])
        next(iter)
        self.assertEqual(d.ilen, 1)
        self.assertEqual(d.irep, 2)
        self.assertEqual(d.irem, 1)
        self.assertEqual(d.irem_eng, 0)
        self.assertEqual(d.ires_eng, 10)
        next(iter)
        self.assertEqual(d.ilen, 2)
        self.assertEqual(d.irep, 2)
        self.assertEqual(d.irem, 1)
        self.assertEqual(d.irem_eng, 5)
        self.assertEqual(d.ires_eng, 8)
        next(iter)
        self.assertEqual(d.ilen, 3)
        self.assertEqual(d.irep, 2)
        self.assertEqual(d.irem, 1)
        self.assertEqual(d.irem_eng, 12)
        self.assertEqual(d.ires_eng, 8)

def __starting_point():

    # Avoiding recursion limitaions
    sys.setrecursionlimit(100000)

    if sys.argv[-1] == "-ut":
        unittest.main(argv=[" "])

    # Print the result string
    print(calculate())

__starting_point()

rr = lambda: map(int, input().split())
_, d, res, he = input(), {}, 0, list(zip(rr(), rr()))
for h, e in he:
    f, x = d.get(h, (-1, 0))
    d[h] = (f + 1, x + e)
he.sort(key = lambda x: x[1], reverse=True)
for h, (f, x) in d.items():
    if not f:
    	res = max(x, res)
    	continue
    for h1, e in he:
        if h1 < h:
            x += e
            f -= 1
            if not f: break
    res = max(x, res)
print(sum(e for h, e in he) - res)

rr = lambda: map(int, input().split())
_, d, res, he = input(), {}, 0, list(zip(rr(), rr()))
for h, e in he:
    f, x = d.get(h, (-1, 0))
    d[h] = (f + 1, x + e)
he.sort(key = lambda x: x[1], reverse=True)
for h, (f, x) in d.items():
    if not f:
    	res = max(x, res)
    	continue
    for h1, e in he:
        if h1 < h:
            x += e
            f -= 1
            if not f: break
    res = max(x, res)
print(sum(e for h, e in he) - res)

rr = lambda: list(map(int, input().split()))
_, d, res, he = input(), {}, 0, list(zip(rr(), rr()))
for h, e in he:
    f, x = d.get(h, (-1, 0))
    d[h] = (f + 1, x + e)
he.sort(key = lambda x: x[1], reverse=True)
for h, (f, x) in list(d.items()):
    if not f:
    	res = max(x, res)
    	continue
    for h1, e in he:
        if h1 < h:
            x += e
            f -= 1
            if not f: break
    res = max(x, res)
print(sum(e for h, e in he) - res)


"""
	Author		: Arif Ahmad
	Date  		: 
	Algo  		: 
	Difficulty	: 
"""
from sys import stdin, stdout

def main():
	n 	= int(stdin.readline())
	leg	= [int(_) for _ in stdin.readline().split()]
	d 	= [int(_) for _ in stdin.readline().split()]

	pairedLD = []
	for x, y in zip(leg, d):
		pairedLD.append((x, y))
	pairedLD = sorted(pairedLD)

	legSet 		= set()
	suffixSum  	= dict()
	legFreq		= dict()
	for length, energy in zip(leg, d):
		legSet.add(length)
		if length in suffixSum: 
			suffixSum[length] += energy
			legFreq[length] += 1
		else: 
			suffixSum[length] = energy
			legFreq[length] = 1
		

	legList = [x for x in legSet]
	legList = sorted(legList, reverse=True)
	total 	= 0
	for length in legList:
		suffixSum[length] += total
		total = suffixSum[length]

	ans = int(2e7)
	toRemove = 0
	available = 0
	removable = [0] * 201
	legList = sorted(legList)
	listLen = len(legList)
	idx = 0
	for i in range(listLen):
		curr = 0
		if i+1 < listLen: curr += suffixSum[legList[i+1]]
		toRemove = available - (legFreq[legList[i]] - 1)
		if toRemove < 0: toRemove = 0
		for j in range(1, 201):
			if removable[j] != 0 and removable[j] <= toRemove:
				curr += (removable[j] * j)
				toRemove -= removable[j]
			elif removable[j] > toRemove:
				curr += (toRemove * j)
				toRemove = 0
			if toRemove == 0: break
		available += legFreq[legList[i]]
		for j in range(legFreq[legList[i]]): 
			removable[pairedLD[idx][1]] += 1
			idx += 1
		ans = min(ans, curr)

	print(ans)


def __starting_point():
    main()

__starting_point()

rr = lambda: map(int, input().split())
_, d, res, he = input(), {}, 0, list(zip(rr(), rr()))
for h, e in he:
    f, x = d.get(h, (-1, 0))
    d[h] = (f + 1, x + e)
he.sort(key = lambda x: x[1], reverse=True)
for h, (f, x) in d.items():
    if not f:
    	res = max(x, res)
    	continue
    for h1, e in he:
        if h1 < h:
            x += e
            f -= 1
            if not f: break
    res = max(x, res)
print(sum(e for h, e in he) - res)

f = lambda: map(int, input().split())
n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1])
for L, d in s:
    k, D = p.get(L, (-1, 0))
    p[L] = (k + 1, D + d)
for L, (k, D) in p.items():
    if k:
        for l, d in s:
            if l < L:
                D += d
                k -= 1
                if k == 0: break
    m = max(D, m)
print(sum(d for l, d in s) - m)

f = lambda: map(int, input().split())
k, n = 1, f()
s = sorted(zip(f(), f()), key=lambda q: q[0])

t = [0] * 201
for l, d in s: t[d] += 1

j = [i for i in range(201) if t[i]]
j.reverse()

S = sum(i * t[i] for i in j)
L, D = s.pop()
t[D] -= 1
s.reverse()
s.append((0, 0))

m = 0
for l, d in s:
    if l < L:
        L = l
        for i in j:
            if t[i] > k - 2:
                D += i * (k - 1)
                break
            D += i * t[i]
            k -= t[i]
        m = max(m, D)
        k = D = 0
    k += 1
    D += d
    
    t[d] -= 1
    if not t[d]: j.remove(d)
    
print(S - m)

f = lambda: list(map(int, input().split()))
n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1])
for L, d in s:
    k, D = p.get(L, (-1, 0))
    p[L] = (k + 1, D + d)
for L, (k, D) in list(p.items()):
    if k:
        for l, d in s:
            if l < L:
                D += d
                k -= 1
                if k == 0: break
    m = max(D, m)
print(sum(d for l, d in s) - m)


f = lambda: list(map(int, input().split()))
n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1])
for L, d in s:
    k, D = p.get(L, (-1, 0))
    p[L] = (k + 1, D + d)
for L, (k, D) in list(p.items()):
    if k:
        for l, d in s:
            if l < L:
                D += d
                k -= 1
                if k == 0: break
    m = max(D, m)
print(sum(d for l, d in s) - m)


f = lambda: list(map(int, input().split()))
n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1])
for L, d in s:
    k, D = p.get(L, (-1, 0))
    p[L] = (k + 1, D + d)
for L, (k, D) in list(p.items()):
    if k:
        for l, d in s:
            if l < L:
                D += d
                k -= 1
                if k == 0: break
    m = max(D, m)
print(sum(d for l, d in s) - m)


f = lambda: list(map(int, input().split()))
n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1])
for L, d in s:
    k, D = p.get(L, (-1, 0))
    p[L] = (k + 1, D + d)
for L, (k, D) in list(p.items()):
    if k:
        for l, d in s:
            if l < L:
                D += d
                k -= 1
                if k == 0: break
    m = max(D, m)
print(sum(d for l, d in s) - m)


f = lambda: list(map(int, input().split()))
n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1])
for L, d in s:
    k, D = p.get(L, (-1, 0))
    p[L] = (k + 1, D + d)
for L, (k, D) in list(p.items()):
    if k:
        for l, d in s:
            if l < L:
                D += d
                k -= 1
                if k == 0: break
    m = max(D, m)
print(sum(d for l, d in s) - m)


f = lambda: list(map(int, input().split()))
n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1])
for L, d in s:
    k, D = p.get(L, (-1, 0))
    p[L] = (k + 1, D + d)
for L, (k, D) in list(p.items()):
    if k:
        for l, d in s:
            if l < L:
                D += d
                k -= 1
                if k == 0: break
    m = max(D, m)
print(sum(d for l, d in s) - m)


f = lambda: list(map(int, input().split()))
n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1])
for L, d in s:
    k, D = p.get(L, (-1, 0))
    p[L] = (k + 1, D + d)
for L, (k, D) in list(p.items()):
    if k:
        for l, d in s:
            if l < L:
                D += d
                k -= 1
                if k == 0: break
    m = max(D, m)
print(sum(d for l, d in s) - m)


f = lambda: list(map(int, input().split()))
n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1])
for L, d in s:
    k, D = p.get(L, (-1, 0))
    p[L] = (k + 1, D + d)
for L, (k, D) in list(p.items()):
    if k:
        for l, d in s:
            if l < L:
                D += d
                k -= 1
                if k == 0: break
    m = max(D, m)
print(sum(d for l, d in s) - m)


f = lambda: list(map(int, input().split()))

n, p, m, s = input(), {}, 0, sorted(zip(f(), f()), key=lambda q: -q[1])

for L, d in s:

    k, D = p.get(L, (-1, 0))

    p[L] = (k + 1, D + d)

for L, (k, D) in list(p.items()):

    if k:

        for l, d in s:

            if l < L:

                D += d

                k -= 1

                if k == 0: break

    m = max(D, m)

print(sum(d for l, d in s) - m)




# Made By Mostafa_Khaled


n = int(input())
legs = list(zip(list(map(int, input().split())), list(map(int, input().split()))))
legs.sort(key=lambda x: x[1], reverse=True)
# print(legs)
cnt = {}
s = 0
for i in range(n):
    s += legs[i][1]
    if legs[i][0] not in cnt:
        cnt[legs[i][0]] = [1, legs[i][1]]
    else:
        cnt[legs[i][0]][0] += 1
        cnt[legs[i][0]][1] += legs[i][1]

temp = sorted(cnt.items())
mn = 9999999999999
f = 0
while temp:
    l, t = temp.pop()
    c, e = t
    s -= e
    val = s
    i = 0
    count = 0
    while count < c-1:
        if legs[i][0] < l:
            count += 1
            val -= legs[i][1]
        i += 1
        if i == n:
            break
    # print(l, c, e, val+f)
    if val+f < mn:
        mn = val+f
    f += e
print(mn)


def buscaEnergia(perna,qtd):
    total = 0
    if(qtd == 0):
        return total
    for i in range(len(d)-1,-1,-1):
        for v in d[i]:
            if(v <perna):
                qtd-=1
                total+=i
            else:
                break
            if(qtd == 0):
                break
        if(qtd == 0):
            break
    return total

n = int(input())
tamanhoPerna = [int(i) for i in input().split()]
energiaPerna = [int(i) for i in input().split()]
d = [[] for i in range(201)]
cntPerna = [0]*100001
sumPerna = [0]*100001
corteTotal = 0
maxTam = 0

for i in range(len(tamanhoPerna)):
    d[energiaPerna[i]].append(tamanhoPerna[i])
    sumPerna[tamanhoPerna[i]]+=energiaPerna[i]
    cntPerna[tamanhoPerna[i]]+=1
    corteTotal+=energiaPerna[i]
    maxTam = max(tamanhoPerna[i],maxTam)

for i in range(len(d)):
    d[i].sort()

currentMin = float("inf")
for perna in tamanhoPerna:
    somaMesa = sumPerna[perna]
    somaMesa+=buscaEnergia(perna,cntPerna[perna]-1)
    currentMin = min(currentMin,corteTotal-somaMesa)
print(currentMin)


def buscaEnergia(perna,qtd):
    total = 0
    if(qtd == 0):
        return total
    for i in range(len(d)-1,-1,-1):
        for v in d[i]:
            if(v <perna):
                qtd-=1
                total+=i
            else:
                break
            if(qtd == 0):
                break
        if(qtd == 0):
            break
    return total

n = int(input())
tamanhoPerna = [int(i) for i in input().split()]
energiaPerna = [int(i) for i in input().split()]
d = [[] for i in range(201)]
cntPerna = [0]*100001
sumPerna = [0]*100001
corteTotal = 0
maxTam = 0

for i in range(len(tamanhoPerna)):
    d[energiaPerna[i]].append(tamanhoPerna[i])
    sumPerna[tamanhoPerna[i]]+=energiaPerna[i]
    cntPerna[tamanhoPerna[i]]+=1
    corteTotal+=energiaPerna[i]
    maxTam = max(tamanhoPerna[i],maxTam)

for i in range(len(d)):
    d[i].sort()

currentMin = float("inf")
for perna in tamanhoPerna:
    somaMesa = sumPerna[perna]
    somaMesa+=buscaEnergia(perna,cntPerna[perna]-1)
    currentMin = min(currentMin,corteTotal-somaMesa)
print(currentMin)