// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1 << 28;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    int mi0 = INF, mi1 = INF;
    vector<int> a(N), w(N);
    for(int i=0; i<N; i++) cin >> a[i];
    for(int i=0; i<N; i++) {
        cin >> w[i];
        if(a[i] == 0) mi0 = min(mi0, w[i]);
        if(a[i] == 1) mi1 = min(mi1, w[i]);
    }

    if(mi0 == INF or mi1 == INF) cout << 0 << endl;
    else cout << mi0 + mi1 << endl;
    return 0;
}

