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.
from collections import defaultdict,Counter,deque
import math
import bisect
from itertools import accumulate, product
from math import ceil, log,gcd
from functools import lru_cache
from sys import stdin, stdout
import time
import atexit
import io
import sys
import string
import heapq

import random
import bisect

def primes(n):
    if n<=2:
        return []
    sieve=[True]*(n+1)
    for x in range(3,int(n**0.5)+1,2):
        for y in range(3,(n//x)+1,2):
            sieve[(x*y)]=False
         
    return [2]+[i for i in range(3,n,2) if sieve[i]]

def write(*args, **kwargs):
    sep = kwargs.get('sep', ' ')
    end = kwargs.get('end', '\n')
    stdout.write(sep.join(str(a) for a in args) + end)

def read():
    return stdin.readline().rstrip()
def primes_rwh(n):
    """ Returns  a list of primes < n """
    sieve = [True] * n
    for i in range(3,int(n**0.5)+1,2):
        if sieve[i]:
            sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,n,2) if sieve[i]]
def prime_factors(n):
    i = 2
    factors = []
    d = defaultdict(lambda:0)
    for i in primes_rwh(int(n**0.5+1)):
        while  n % i == 0:
                n //= i
                factors.append(i)
                d[i]+=1
    if n > 1:
        factors.append(n)
        d[n]+=1
    return factors,d


    
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
    
def lcm(x, y):
   lcm = (x*y)//math.gcd(x,y)
   return lcm    
    
    
# total= int(read())

# import random

# class ListDict(object):
#     def __init__(self):
#         self.item_to_position = {}
#         self.items = []

#     def add_item(self, item):
#         if item in self.item_to_position:
#             return
#         self.items.append(item)
#         self.item_to_position[item] = len(self.items)-1

#     def remove_item(self, item):
#         if item in self.item_to_position:
#             position = self.item_to_position.pop(item)
#             last_item = self.items.pop()
#             if position != len(self.items):
#                 self.items[position] = last_item
#                 self.item_to_position[last_item] = position

#     def choose_random_item(self):
#         return random.choice(self.items)


# for _ in range(total):
#     n,k =  [int(p) for p in read().split()]
    
    
#     e = [set() for i in range(n)]
#     for _ in range(k):
#         i,j =  [int(p)-1 for p in read().split()]
#         e[i].add(j)
#         e[j].add(i)
    
#     mx = [0]    
#     sx = [0]    
#     x =  []
#     for _ in range(300):
#         s = ListDict()
#         for i in range(n):
#             s.add_item(i)
#         r = 0
#         cnt = 0
#         ret = []
#         while s.items:
#             tr = s.choose_random_item()
#             r+=1
#             cnt +=1
#             s.remove_item(tr) 
#             ret.append(tr+1)
#             for j in e[tr]:
#                 s.remove_item(j)
#                 r+=1
                       
#         if cnt > mx[0]:
#             mx[0]= cnt
#             x = ret
          
#     write(mx[0])
#     write(*sorted(x))        
def prime_factors_s(n):
    i = 2
    factors =set()
    d = defaultdict(lambda:0)
    for i in primes_rwh(int(n**0.5+1)):
        while  n % i == 0:
                n //= i
                factors.add(i)
    if n > 1:
        factors.add(n)
    return factors
    
from bisect import    bisect_right 


def pollard_rho(n):
    """returns a random factor of n"""
    if n & 1 == 0:
        return 2
    if n % 3 == 0:
        return 3
 
    s = ((n - 1) & (1 - n)).bit_length() - 1
    d = n >> s
    for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
        p = pow(a, d, n)
        if p == 1 or p == n - 1 or a % n == 0:
            continue
        for _ in range(s):
            prev = p
            p = (p * p) % n
            if p == 1:
                return math.gcd(prev - 1, n)
            if p == n - 1:
                break
        else:
            for i in range(2, n):
                x, y = i, (i * i + 1) % n
                f = math.gcd(abs(x - y), n)
                while f == 1:
                    x, y = (x * x + 1) % n, (y * y + 1) % n
                    y = (y * y + 1) % n
                    f = math.gcd(abs(x - y), n)
                if f != n:
                    return f
    return n    

def memodict(f):
    """memoization decorator for a function taking a single argument"""
    class memodict(dict):
        def __missing__(self, key):
            ret = self[key] = f(key)
            return ret
 
    return memodict().__getitem__

@memodict
def prime_factors_r(n):
    """returns a Counter of the prime factorization of n"""
    if n <= 1:
        return Counter()
    f = pollard_rho(n)
    return Counter([n]) if f == n else prime_factors_r(f) + prime_factors_r(n // f)

def multiply(a, b):
     
    # Creating an auxiliary matrix
    # to store elements of the
    # multiplication matrix
    mul = [[0 for x in range(2)]
              for y in range(2)];
    for i in range(2):
        for j in range(2):
            for k in range(2):
                mul[i][j] += a[i][k] * b[k][j];
            mul[i][j] %= (10**9+7 )   
    return mul
 

def power(F, n):
    # print(n)
    # Multiply it with initial values i.e
    # with F(0) = 0, F(1) = 1, F(2) = 1
    if (n == 1):
        return F
 
    F_ = power(F, int(n // 2));
 
    F_ = multiply(F_, F_);
 
    if (n % 2 != 0):
        F_ = multiply(F_, F);
 
    # Multiply it with initial values i.e
    # with F(0) = 0, F(1) = 1, F(2) = 1
    return F_ ;


from bisect import bisect_left as lower_bound
from bisect import bisect_right as upper_bound


class FenwickTree:
    def __init__(self, x):
        bit = self.bit = list(x)
        size = self.size = len(bit)
        for i in range(size):
            j = i | (i + 1)
            if j < size:
                bit[j] += bit[i]

    def update(self, idx, x):
        """updates bit[idx] += x"""
        while idx < self.size:
            self.bit[idx] += x
            idx |= idx + 1

    def __call__(self, end):
        """calc sum(bit[:end])"""
        x = 0
        while end:
            x += self.bit[end - 1]
            end &= end - 1
        return x

    def find_kth(self, k):
        """Find largest idx such that sum(bit[:idx]) <= k"""
        idx = -1
        for d in reversed(range(self.size.bit_length())):
            right_idx = idx + (1 << d)
            if right_idx < self.size and self.bit[right_idx] <= k:
                idx = right_idx
                k -= self.bit[idx]
        return idx + 1, k


class SortedList:
    block_size = 700

    def __init__(self, iterable=()):
        self.macro = []
        self.micros = [[]]
        self.micro_size = [0]
        self.fenwick = FenwickTree([0])
        self.size = 0
        for item in iterable:
            self.insert(item)

    def insert(self, x):
        i = lower_bound(self.macro, x)
        j = upper_bound(self.micros[i], x)
        self.micros[i].insert(j, x)
        self.size += 1
        self.micro_size[i] += 1
        self.fenwick.update(i, 1)
        if len(self.micros[i]) >= self.block_size:
            self.micros[i:i + 1] = self.micros[i][:self.block_size >> 1], self.micros[i][self.block_size >> 1:]
            self.micro_size[i:i + 1] = self.block_size >> 1, self.block_size >> 1
            self.fenwick = FenwickTree(self.micro_size)
            self.macro.insert(i, self.micros[i + 1][0])

    def pop(self, k=-1):
        i, j = self._find_kth(k)
        self.size -= 1
        self.micro_size[i] -= 1
        self.fenwick.update(i, -1)
        return self.micros[i].pop(j)

    def __getitem__(self, k):
        i, j = self._find_kth(k)
        return self.micros[i][j]

    def count(self, x):
        return self.upper_bound(x) - self.lower_bound(x)

    def __contains__(self, x):
        return self.count(x) > 0

    def lower_bound(self, x):
        i = lower_bound(self.macro, x)
        return self.fenwick(i) + lower_bound(self.micros[i], x)

    def upper_bound(self, x):
        i = upper_bound(self.macro, x)
        return self.fenwick(i) + upper_bound(self.micros[i], x)

    def _find_kth(self, k):
        return self.fenwick.find_kth(k + self.size if k < 0 else k)

    def __len__(self):
        return self.size

    def __iter__(self):
        return (x for micro in self.micros for x in micro)

    def __repr__(self):
        return str(list(self))
def calc_primes(n):
    return [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
            73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
            179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
            283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
            419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
            547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
            661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
            811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
            947, 953, 967, 971, 977, 983, 991, 997]

def factorize(n, primes):
    factorization = set()
    for d in primes:
        if d * d > n:
            break
        while n % d == 0:
            factorization.add(d)
            n //= d
    if n > 1:
        factorization.add(n)
    return list(factorization)


n = int(read())
l = [*map(int , read().split(' '))]
d = [*map(int , read().split(' '))]

# n = 6
# l = [2, 2, 1, 1, 3, 3]
# d = [4, 3, 5, 5, 2, 1]

cl = Counter(l)


x = [i*2**32 + j for i,j in zip(l,d)]

cur  = [0]*201

s = 0
ms = 10**18

x = sorted(x)
j = 0

z = []
cc = 0
for i in range(n):
    z.append(cc)
    cc+= x[n-1-i]%2**32

z.append(cc)
z = z[::-1]

for i in range(1,n):    
    if (x[i] >> 32) != (x[i-1] >> 32):
        # print(i)
        while (x[j]>>32) != (x[i-1] >> 32):
            cur[(x[j] % 2**32)] +=1
            j+=1
        total = i 
        to_r = total - 2 * cl[x[i-1]//2**32] + 1
        to_r = max(to_r,0)
        co = z[i]       
        for t in range(201):
            tt= min(cur[t], to_r)
            to_r -=tt
            co+=t * tt
            if to_r ==0:
                break
        ms= min(co,ms)

i=n
while (x[j]>>32) != (x[i-1] >> 32):
    cur[(x[j] % 2**32)] +=1
    j+=1
total = i 
to_r = total - 2 * cl[x[i-1]//2**32] + 1
to_r = max(to_r,0)
co = z[i]       
for t in range(201):
    tt= min(cur[t], to_r)
    to_r -=tt
    co+=t * tt
    if to_r ==0:
        break
ms= min(co,ms)
    
    
    
    
    
    
print(ms)        


        

# if n ==25:
#     for i in range(8,25):
#         print(*w[i][i+1:])

# 25 3
# 22 4 4
# 55 61 59 55 62 7 23 10 27 55 40 11 65 43 38 37 35 62 16 26 66 52 2 59
# 30 55 5 6 31 65 18 50 32 34 55 28 55 17 5 37 14 60 3 3 66 46 4
# 32 5 52 7 42 42 3 22 60 50 64 19 23 48 19 10 7 8 26 60 19 50
# 9 8 96 56 90 8 13 96 78 36 44 71 92 57 70 75 31 77 62 78 23
# 24 59 23 23 92 85 61 23 6 93 93 88 59 23 8 63 45 75 79 16
# 77 97 41 23 11 84 57 97 81 61 90 24 65 7 38 32 24 68 66
# 50 43 31 40 70 97 79 62 26 21 60 79 42 69 83 93 63 75
# 94 93 83 65 82 70 88 65 92 34 87 80 77 14 76 85 97
# 97 49 42 91 81 8 3 34 77 76 40 7 95 20 23 95
# 14 71 50 50 21 97 4 79 34 91 52 29 13 65 53
# 19 5 20 76 75 67 75 62 72 38 28 60 66 55
# 10 31 24 70 82 46 88 53 65 80 39 63 9
# 49 26 65 48 63 76 10 76 38 78 38 15
# 86 57 30 36 46 94 74 79 48 58 92
# 22 41 15 26 58 36 27 66 40 19
# 29 32 91 37 82 72 77 45 58
# 91 37 35 22 91 78 40 24
# 68 21 54 81 93 89 2
# 50 15 3 44 36 31
# 40 87 18 73 22
# 50 41 60 72
# 18 14 75
# 93 4
# 40


#%%
# n,k = 10,5
# d = [5,4,3,2,1]

# w = [[0, 29, 49, 33, 12, 55, 15, 32, 62, 37], [29, 0, 61, 26, 15, 58, 15, 22, 8, 58], [49, 61, 0, 37, 16, 9, 39, 20, 14, 58], [33, 26, 37, 0, 10, 15, 40, 3, 19, 55], [12, 15, 16, 10, 0, 53, 13, 37, 44, 52], [55, 58, 9, 15, 53, 0, 23, 59, 58, 4], [15, 15, 39, 40, 13, 23, 0, 69, 80, 29], [32, 22, 20, 3, 37, 59, 69, 0, 89, 28], [62, 8, 14, 19, 44, 58, 80, 89, 0, 48], [37, 58, 58, 55, 52, 4, 29, 28, 48, 0]]



# n,k = 5, 2
# d = [1, 4]
# w = [[0, 48, 20, 68, 57], [48, 0, 63, 68, 19], [20, 63, 0, 7, 31], [68, 68, 7, 0, 31], [57, 19, 31, 31, 0]]


# n,k = 7,5
# d =[3 ,1, 3, 1, 2]
# w=[[0, 8, 34, 17, 53, 24, 57], [8, 0, 7, 32, 48, 85, 41], [34, 7, 0, 74, 77, 76, 65], [17, 32, 74, 0, 28, 95, 63], [53, 48, 77, 28, 0, 82, 40], [24, 85, 76, 95, 82, 0, 69], [57, 41, 65, 63, 40, 69, 0]]
# n,k = 6,5
# d = [1,2,2,2,2]
# w=  [[0, 10, 99, 99, 99, 11], [10, 0, 10, 99, 99, 11], [99, 10, 0, 10, 99, 11], [99, 99, 10, 0, 10, 11], [99, 99, 99, 10, 0, 11], [11, 11, 11, 11, 11, 0]]

# n,k = 5,1
# d = [3]
# w = [[0, 67, 62, 64, 5], [67, 0, 45, 84, 10], [62, 45, 0, 60, 64], [64, 84, 60, 0, 29], [5, 10, 64, 29, 0]]


# r = n-2
# p = []
# q = []

# e = [set() for i in range(n)]


# for i in range(n):
#     if i != r:
#         p.append(i)
#         q.append(r)
#         e[i].add(r)
#         e[r].add(i)

# # for i in range(n-1):
# #     e[n-1].add(i)
# #     e[i].add(n-1)


# deg = [1]*n
# deg[r] = n-1

# while len(d) < n:
#     d +=[1000]
# curr = 0
# curr_cnt = 0

# def obj(p,q):
#     return sum(w[i][j] for i,j in zip(p,q))

# c_eval = obj(p,q)

# # print(d)
# # 1/0

# z = [0] * 25
# def mod(p,q):
    
#     # p,q = [1, 1, 2, 3], [0, 4, 4, 4]
    
#     # deg = [1, 2, 1, 1, 3]
#     i = random.randint(0,10**12) % (n-1)
#     # i=3
    
#     z[i]+=1
    
#     # deg[p[i]]-=1
#     # deg[q[i]]-=1
    
#     pa = [*range(n)]
    
#     def find(x):
#         while pa[x] != pa[pa[x]]:
#             pa[x] = find(pa[x])
#         return pa[x]    
#     def merge(x,y):
#         if find(x) != find(y):
#             pa[find(x)] = pa[find(y)]
            
            
            
#     for j in range(n-1):
#         if j!=i:
#             merge(p[j],q[j])
#             deg[p[j]] +=1
#             deg[q[j]] +=1
            
#     while True:
#         i0 =random.randint(0,10**12) % n
#         i1 = random.randint(0,10**12) % n
        
#         if deg[i0] < d[i0] and deg[i1] < d[i1] and find(i1)!= find(i0):
#             break
#     deg[i0] +=1
#     deg[i1] +=1
#     p[i] = i0
#     q[i] = i1    
#     # print(deg)
    
#     return p,q
    

# print(deg)

# # p = [1,24,21,0,15,20,8,4,7,1,0,22,2,9,3,5,1,2,4,12,19,20,17,9]
# # q = [24,11,18,23,8,1,14,2,21,21,6,24,6,2,5,19,4,19,13,10,12,8,24,16]
# print(obj(p,q))
# # 1/0

# iterations = 1700000


# initial_temp = 1000000

# p_best,q_best = p,q
# best_eval = obj(p,q)
# curr_eval = best_eval
# t = initial_temp
# cnt =1 
# for i in range(iterations ):
#     # print(i)
#     cnt+=1    
    
#     deg = [0]*(n)
    
#     pc,qc = mod(p,q) 
#     #print('---')
#     #print(x,y,xc,yc)
#     c_eval = obj(pc,qc)
#     best_eval = min(best_eval,c_eval )
#     # print(pc,qc,c_eval,curr_eval)
#     # print(pc,qc,c_eval)
#     diff = c_eval - curr_eval
#     # calculate temperature for current epoch
#     t = initial_temp /cnt
#     # calculate metropolis acceptance criterion
#     if diff < 0:
#         p,q = pc,qc
        
#         curr_eval = c_eval
#         print(i,deg,curr_eval)
#         # print(z)
#     else :
#         metropolis = math.exp((-diff) / t)
#     #  print(diff,metropolis)
#         # check if we should keep the new point
#         if random.random() < metropolis:
#             # store the new current point
#             p,q = pc,qc
#             curr_eval = c_eval
#             best_eval = min(best_eval,c_eval )
#             print(i,t,deg,p,q,curr_eval,c_eval, diff, metropolis)
#             # print(z)
# print(p,q,deg)            
# print(best_eval)   
# print(w)

# def helper(s):
#             t = []
#             if s == "":
#                 return []
#             for i in range(1,len(s)+1):
#                 if s[:i]==s[:i][::-1]:
#                     t += [s[:i]] + helper(s[i:])
#             return t 

# p  = [0, 0, 5, 9, 6, 1, 9, 6, 2, 2]
# c = Counter(p[1:])
# mod(p, c)