#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long ll;

class Node {
public:
	ll cost;
	int pos;
	Node(ll c, int p) : cost(c), pos(p) {}
	Node() {}
	friend bool operator < (const Node &A, const Node &B) {
		return (A.cost < B.cost);
	}
	friend bool operator > (const Node &A, const Node &B) {
		return (A.cost > B.cost);
	}
};

ll solve(int x);

const ll INF = 1e18;
const int MAX = 5005;
ll c[MAX];
char a[MAX], b[MAX];
char s[MAX];
vector<Node> vec0, vec1, vectmp;
ll all;

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		// 初始化
		vec0.clear();
		vec1.clear();
		all = 0;
		// 输入
		for (int i = 1; i <= n; i ++) {
			scanf("%lld", &c[i]);
		}
		scanf("%s", a+1);
		scanf("%s", b+1);
		// 预处理
		int cnt101 = 0;
		for (int i = 1; i <= n; i ++) {
			if (a[i] == '0' && b[i] == '1') {
				vec0.push_back(Node(c[i], i));
			}
			if (a[i] == '1') {
				vec1.push_back(Node(c[i], i));
				all += c[i];
				if (b[i] == '1') cnt101 ++;
			}
		}
		// 排序
		sort(vec0.begin(), vec0.end());
		sort(vec1.begin(), vec1.end(), greater<Node>());
		// 求解
		ll res = INF;
		for (int x = 0; x <= cnt101; x ++) {
			res = min(res, solve(x));
		}
		// 输出
		printf("%lld\n", res);
	}
	return 0;
}
// 解决
ll solve(int x) {
	// 初始化
	vectmp.clear();
	ll res = 0;
	ll sum = all;
	// 1 => 0
	for (int i = 0; i < (int)vec1.size(); i ++) {
		Node &p = vec1[i];
		if (b[p.pos] == '1') {
			if (x > 0) {
				x --;
				vectmp.push_back(p);
			} else {
				continue;
			}
		}
		sum -= p.cost;
		res += sum;
	}
	reverse(vectmp.begin(), vectmp.end());
	// 0 => 1
	int i = 0, j = 0;
	while (i < (int)vec0.size() && j < (int)vectmp.size()) {
		Node &p1 = vec0[i], &p2 = vectmp[j];
		if (p1 < p2) {
			sum += p1.cost;
			res += sum;
			i ++;
		} else {
			sum += p2.cost;
			res += sum;
			j ++;
		}
	}
	while (i < (int)vec0.size()) {
		Node &p1 = vec0[i];
		sum += p1.cost;
		res += sum;
		i ++;
	}
	while (j < (int)vectmp.size()) {
		Node &p2 = vectmp[j];
		sum += p2.cost;
		res += sum;
		j ++;
	}
	// 返回
	return res;
}