#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
const int N = 155, INF = 1e8;
int n;
int a[N];
char s[N];
int dp[N][N][N];
void ckmax(int &x, int y) { x = x > y ? x : y; }
int f[N];
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    if (a[i] == -1) a[i] = -INF;
  }
  scanf("%s", s + 1);
  s[0] = '$', s[n + 1] = '%';
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i <= n; i++)
    for (int k = 0; k <= n; k++) dp[i + 1][i][k] = a[k];
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      for (int k = 0; k <= n; k++) dp[i][j][k] = -INF;
  for (int d = 0; d <= n - 1; d++)
    for (int i = 1; i <= n - d; i++) {
      int j = i + d;
      for (int k = 0; k <= n; k++) {
        if (k > 0) ckmax(dp[i][j][k], dp[i][j][0] + a[k]);
        if (k & 1) {
          for (int R = j; R >= i; R--)
            if (s[i - 1] == s[R])
              ckmax(dp[i][j][k], dp[i][R - 1][k + 1] + dp[R + 1][j][0]);
        } else {
          for (int L = i; L <= j; L++)
            ckmax(dp[i][j][k], dp[L + 1][j][k + 1] + dp[i][L - 1][0]);
        }
      }
    }
  for (int i = 1; i <= n; i++) {
    ckmax(f[i], f[i - 1]);
    for (int j = i; j <= n; j++) ckmax(f[j], f[i - 1] + dp[i][j][0]);
  }
  cout << f[n] << endl;
  return 0;
}
