#include <bits/stdc++.h>

using namespace std;

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#define all(x) x.begin() , x.end();
#define F first 
#define S second 
#define boost ios_base::sync_with_stdio(false);
#define ull unsigned long long 
#define ll long long 
#define open freopen("lepus.in","r",stdin);freopen("lepus.out","w",stdout)

const ll mod = (ll)1e9+7;  
const ll MOD = 998244353;       
const ll inf = (ll)1e18+7;               
const ll MX = LLONG_MAX;    //-> =+
const ll MN = LLONG_MIN;    //-> =-
const ll N = (ll)1e5+5;  
const int minf = -1e9 + 9;
const int INF = 1e9 + 9 ;

map<int , int>mp;
set<int>st;
//pair<int , int >p[N];

int main(){
	int n ;
	cin >> n ;
	int col[n] , kr[n];
	for(int i = 1; i <= n;i++){
		cin >> col[i] ;
	}
	for(int i = 1;i <= n;i++){
		cin >> kr[i];
		mp[col[i]] = kr[i];
	}
	sort(col + 1 , col + n + 1);
	if(n == 1)cout << kr[1] << '\n';
	else cout << mp[col[1]] + mp[col[n]] << '\n';
	mp.clear();
}




