#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 40;
int L;
long long A[160];
char S[160];
long long mem[160][160][160];
long long find(int l, int r, int d) {
  if (l == r) return A[d];
  if (mem[l][r][d] != -1) return mem[l][r][d];
  long long res = -INF;
  if (d > 0) {
    long long tmp = A[d] + find(l, r, 0);
    res = max(res, tmp);
  }
  {
    long long tmp = A[d + 1] + find(l + 1, r, 0);
    res = max(res, tmp);
  }
  for (int i = l + 1; i < r; i++) {
    if (S[l] != S[i]) continue;
    res = max(res, find(l + 1, i, d + 2) + find(i + 1, r, 0));
  }
  for (int i = l + 1; i < r; i++) res = max(res, find(l, i, 0) + find(i, r, d));
  return mem[l][r][d] = res;
}
int main() {
  while (cin >> L) {
    A[0] = 0;
    for (int i = 1; i <= L; i++) {
      cin >> A[i];
      if (A[i] == -1) A[i] = -INF;
    }
    cin >> S;
    memset(mem, -1, sizeof(mem));
    long long dp[160] = {};
    for (int r = 1; r <= L; ++r) {
      dp[r] = dp[r - 1];
      for (int l = 0; l < r; ++l) dp[r] = max(dp[r], dp[l] + find(l, r, 0));
    }
    cout << dp[L] << endl;
  }
  return 0;
}
