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*<sub class="lower-index">*i*</sub>.

Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d*<sub class="lower-index">*i*</sub> — 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.
The first line of the input contains integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) — the initial number of legs in the table Arthur bought.

The second line of the input contains a sequence of *n* integers *l*<sub class="lower-index">*i*</sub> (1 ≤ *l*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">5</sup>), where *l*<sub class="lower-index">*i*</sub> 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*<sub class="lower-index">*i*</sub> (1 ≤ *d*<sub class="lower-index">*i*</sub> ≤ 200), where *d*<sub class="lower-index">*i*</sub> is the number of energy units that Arthur spends on removing the *i*-th leg off the table.
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict


def main():
    INF = int(1e9)

    n = int(input())
    ll = list(map(int, input().split()))
    dd = list(map(int, input().split()))

    tab = list(zip(ll, dd))
    tab.sort()

    suml = [0] * (int(1e5) + 1)
    costl = [0] * (int(1e5) + 1)
    for l, d in tab:
        suml[l] += 1
        costl[l] += d

    for i in range(len(suml)):
        if i > 0:
            suml[i] += suml[i-1]
            costl[i] += costl[i-1]

    # USE THE FACT THAT d <= 200
    stack = [0] * 201

    ans = INF

    i = 0
    while i < n:
        l, d = tab[i]

        countl = suml[l] - suml[l-1]

        if countl > n / 2:
            ans = 0
            break

        greater = suml[-1] - suml[l]

        cur = costl[-1] - costl[l]

        if countl > (n - greater) / 2:
            ans = min(ans, cur)
        else:
            # you want to pick ml CHEAPEST legs that are < l
            ml = n - greater - (2 * countl - 1)
            pos = 0
            while pos <= 200 and ml > 0:
                if stack[pos] <= ml:
                    cur += stack[pos] * pos
                    ml -= stack[pos]
                else:
                    cur += ml * pos
                    ml = 0
                pos += 1


            ans = min(ans, cur)

        prev = i
        while i < n and tab[i][0] == l:
            stack[tab[i][1]] += 1
            i += 1
        #if i != prev:
        #    i -= 1

    print(ans)

    # k cheapest legs < L
    # (l, d)
    # find k cheapest (over d) among l < L

    # like closest pair of points
    # you keep two arrays: sorted over d and l
    # you make a sweep over x's
    # and you add y's
    # this should enable to perform the needed computations





# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()
