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
# 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 bisect

# Additional libraries


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


class Table:
    """ Table representation """

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

        self.legs = args[0]
        self.energy = args[1]

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

        self.result_energy = 0

    def get_top(self):
        x = self.legs[-1]
        i = bisect.bisect_left(self.legs, x)
        if i != len(self.legs) and self.legs[i] == x:
            return i
        raise ValueError

    def remove_top_layer(self):

        top = self.get_top()

        # Energy to remove the top layer
        energy_top = 0
        n = len(self.legs)
        for i in range(top, n):
            energy_top += self.energy[i]
            self.legs.pop()

        # Energy to make max
        max_legs = n - top
        remove_legs = max(n//2 - max_legs + 1, 0)
        en_sorted = sorted([self.energy[i] for i in range(top)])
        energy_bottom = 0
        for i in range(remove_legs):
            energy_bottom += en_sorted[i]

        if energy_top > energy_bottom:
            self.result_energy += energy_bottom
            return 0
        else:
            self.result_energy += energy_top
            return 1

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

        while self.remove_top_layer():
            pass

        result = self.result_energy

        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 """

        # 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")

    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)
        self.assertEqual(d.result_energy, 0)

        self.assertEqual(d.get_top(), 4)

        # Remove layer 1 - we can remove top layer, 0 - we've removed low
        self.assertEqual(d.remove_top_layer(), 1)
        self.assertEqual(d.legs, [1, 1, 2, 2])
        self.assertEqual(d.result_energy, 2)

if __name__ == "__main__":

    # Avoiding recursion limitaions
    sys.setrecursionlimit(100000)

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

    # Print the result string
    print(calculate())
