#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)1e5;
const int MAX_C = (int)1e9;
int n;
string s;
int r[MAX_N];
int c[MAX_N];
int v[MAX_N + 1];
void read() {
cin >> n;
assert(1 <= n && n <= MAX_N);
cin >> s;
assert((int)s.size() == n);
for (int i = 0; i < n; ++i) {
assert(s[i] == '0' || s[i] == '1');
}
for (int i = 0; i < n; ++i) {
cin >> r[i]; --r[i];
assert(i <= r[i] && r[i] < n);
}
for (int i = 0; i < n; ++i) {
cin >> c[i];
assert(1 <= c[i] && c[i] <= MAX_C);
}
}
int main() {
// freopen("in5.txt", "r", stdin);
//freopen("out5.txt", "w", stdout);
read();
int state = 0;
long long sol = 0;
for (int i = 0; i < n; ++i) {
state ^= v[i];
if (state ^ (s[i] - '0')) {
state ^= 1;
sol += c[i];
v[r[i] + 1] ^= 1;
}
}
cout << sol << "\n";
}