#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define in insert
#define ump unordered_map
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
const ll M = 998244353;
const ll INF = LLONG_MAX;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
using namespace std;
const int N = 2e5+10;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    vector<ll> ind(n);
    for(ll i=0;i<n;i++) cin>>ind[i];
    ump<ll,vector<ll>> mp;
    for(ll i=0;i<n;i++) {
        ll x;cin>>x;mp[ind[i]].pb(x);
    }
    for(auto &element: mp) {
        sort(element.second.begin(),element.second.end());
    }
    ll ct=0;
    for(auto &element: mp) {
        for(ll i=0;i<element.second.size()-1;i++) {
            // cout<<element.second[i]<<" ";
            ct+=element.second[i];
        }
    }
    cout<<ct<<endl;
}