#include<bits/stdc++.h>
using namespace std;
long long n,kms,kj=0;
struct p{
long long c;
char a,b;
}c[5005];
bool cmp(p x,p y){
return x.c>y.c;
}
set<long long,greater<long long> >s;
set<long long>k;
signed main(){
freopen("key.in","r",stdin);
freopen("key.out","w",stdout);
cin>>n;
for(long long i=1;i<=n;i++)cin>>c[i].c;
for(long long i=1;i<=n;i++)cin>>c[i].a;
for(long long i=1;i<=n;i++)cin>>c[i].b;
sort(c+1,c+n+1,cmp);
for(long long i=1;i<=n;i++){
if(c[i].a!=c[i].b){
if(c[i].a=='0')k.insert(c[i].c);
else s.insert(c[i].c),kj+=c[i].c;
}
}
for(long long i=1;i<=n;i++){
if(c[i].a==c[i].b&&c[i].a=='1'){
kms+=c[i].c;
}
}
long long sum=1e18,ans=0;
long long kk=(kj),ll=(kms);
for(auto j:s){
kk-=j;
ans+=kk;
ans+=ll;
}
for(auto j:k){
kk+=j;
ans+=ll;
ans+=kk;
}
sum=min(sum,ans);
for(long long i=1;i<=n;i++){
if(c[i].a==c[i].b&&c[i].b=='1'){
ans=0;
long long kk=(kj+=c[i].c),ll=(kms-=c[i].c);
s.insert(c[i].c);
for(auto j:s){
kk-=j;
ans+=kk;
ans+=ll;
}
k.insert(c[i].c);
for(auto j:k){
kk+=j;
ans+=ll;
ans+=kk;
}
sum=min(sum,ans);
}
}
cout<<sum;
}
set能去重,此贴结