#include <bits/stdc++.h>
using namespace std;
int ts, kk = 1;
template <class T>
inline T _sq(T a) {
  return a * a;
}
template <class T, class X>
inline T _pow(T a, X y) {
  T z = 1;
  for (int i = 1; i <= y; i++) {
    z *= a;
  }
  return z;
}
template <class T>
inline T _gcd(T a, T b) {
  a = _abs(a);
  b = _abs(b);
  if (!b) return a;
  return _gcd(b, a % b);
}
template <class T>
inline T _lcm(T a, T b) {
  a = _abs(a);
  b = _abs(b);
  return (a / _gcd(a, b)) * b;
}
template <class T>
inline T _extended(T a, T b, T &x, T &y) {
  a = _abs(a);
  b = _abs(b);
  T g, x1, y1;
  if (!b) {
    x = 1;
    y = 0;
    g = a;
    return g;
  }
  g = _extended(b, a % b, x1, y1);
  x = y1;
  y = x1 - (a / b) * y1;
  return g;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
template <class T, class X>
inline T togglebit(T a, X i) {
  T t = 1;
  return (a ^ (t << i));
}
template <class T, class X, class Y>
inline T _bigmod(T n, X m, Y mod) {
  unsigned long long ret = 1, a = n % mod;
  while (m) {
    if (m & 1) ret = (ret * a) % mod;
    m >>= 1;
    a = (a * a) % mod;
  }
  ret %= mod;
  return (T)ret;
}
template <class T, class Y>
inline T _modinv(T n, Y mod) {
  return _bigmod(n, mod - 2, mod);
}
string str;
long long arr[(100000 + 10)], ans, n, sz;
long long store[(100000 + 10)][2];
string m;
long long dp(int, bool);
int main() {
  cin >> n;
  for (int i = 0; i <= n - 1; i++) {
    cin >> arr[i];
  }
  cin >> m;
  sz = m.size() - 1;
  memset(store, -1, sizeof store);
  ans = dp(sz, false);
  cout << ans << endl;
  return 0;
}
long long dp(int pos, bool chk) {
  if (pos == -1) return 0;
  long long &ret = store[pos][chk];
  if (ret != -1) return ret;
  ret = 0;
  if (chk)
    ret = dp(pos - 1, chk) + arr[pos];
  else {
    long long r1 = 0, r2 = 0;
    r1 = dp(pos - 1, false) + arr[pos] * (m[pos] - '0');
    if (m[pos] == '1') {
      r2 = dp(pos - 1, true);
    }
    ret = max(r1, r2);
  }
  return ret;
}
