#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... s) {
  int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
void debug(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
const int N = 155;
const int INF = 1e9;
int mem[N][N][N];
int dp[N];
int a[N];
string s;
int go(int l, int r, int len) {
  if (l > r) {
    return a[len] >= 0 ? a[len] : -INF;
  }
  int& ret = mem[l][r][len];
  if (~ret) {
    return ret;
  }
  ret = -INF;
  if (len > 0 and a[len] >= 0) {
    ret = max(ret, a[len] + go(l, r, 0));
  }
  if (s[l] == s[r]) {
    ret = max(ret, go(l + 1, r - 1, len + 1 + (l != r)));
  }
  for (int i = l; i < r; ++i) {
    ret = max(ret, go(l, i, len) + go(i + 1, r, 0));
    ret = max(ret, go(l, i, 0) + go(i + 1, r, len));
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i + 1];
  }
  cin >> s;
  memset(mem, -1, sizeof(mem));
  for (int i = 0; i < n; ++i) {
    dp[i] = max(0, go(0, i, 0));
    for (int j = 0; j < i; ++j) {
      dp[i] = max(dp[i], dp[j] + max(0, go(j + 1, i, 0)));
    }
  }
  cout << dp[n - 1] << "\n";
  return 0;
}
