#include <bits/stdc++.h>
using namespace std;
int n, g[160], f[160][160][160], a[160];
char ch[160];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  scanf("%s", ch + 1);
  memset(f, -63, sizeof(f));
  for (int i = 1; i <= n; ++i) f[i + 1][i][0] = 0, f[i][i][1] = 0;
  for (int j = 1; j <= n; ++j)
    for (int i = j; i >= 1; --i)
      for (int k = 0; k <= j - i + 1; ++k) {
        if (k >= 2 && ch[i] == ch[j])
          f[i][j][k] = max(f[i][j][k], f[i + 1][j - 1][k - 2]);
        for (int l = i; l < j; ++l) {
          f[i][j][k] = max(f[i][j][k], f[i][l][k] + f[l + 1][j][0]);
          f[i][j][k] = max(f[i][j][k], f[i][l][0] + f[l + 1][j][k]);
        }
        if (a[k] != -1) f[i][j][0] = max(f[i][j][0], f[i][j][k] + a[k]);
      }
  for (int i = 1; i <= n; ++i) {
    g[i] = g[i - 1];
    for (int j = 1; j <= i; ++j) g[i] = max(g[i], g[j - 1] + f[j][i][0]);
  }
  printf("%d\n", g[n]);
  return 0;
}
