#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
const int MAXN = 100100;
const int INF = 0x3f3f3f3f;
const long long INF_64 = (1LL << 62);
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<char> s(n + 1);
  for (int i = n; i > 0; i--) cin >> a[i];
  for (int i = n; i > 0; i--) cin >> s[i];
  int dp[MAXN][2];
  for (int i = 0; i < MAXN; i++) dp[i][0] = dp[i][1] = -INF;
  dp[0][0] = 0;
  for (int i = 0; i < n; i++)
    for (int less = 0; less < 2; less++) {
      if (dp[i][less] == -INF) continue;
      for (int nxt = 0; nxt < 2; nxt++) {
        if (less == 0 && nxt > s[i + 1] - '0') continue;
        if (nxt < s[i + 1] - '0' || less == 1)
          dp[i + 1][1] = max(dp[i + 1][1], dp[i][less] + nxt * a[i + 1]);
        else
          dp[i + 1][0] = max(dp[i + 1][0], dp[i][less] + nxt * a[i + 1]);
      }
    }
  printf("%d", max(dp[n][0], dp[n][1]));
}
