#include <bits/stdc++.h>
using namespace std;
int a[100008], n;
char S[10008];
int f[152][152][152], g[152];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%s", &S[1]);
  for (int i = 0; i <= n + 1; i++)
    for (int j = 0; j <= n + 1; j++)
      for (int k = 0; k <= n + 1; k++) f[i][j][k] = -214748364;
  for (int i = 1; i <= n; i++) {
    f[i][i][1] = 0;
    f[i][i - 1][0] = 0;
    if (a[1] != -1) f[i][i][0] = a[1];
  }
  for (int i = n; i >= 1; i--)
    for (int j = i + 1; j <= n; j++)
      for (int k = 0; k <= j - i + 1; k++) {
        int &s = f[i][j][k];
        if (S[i] == S[j] && k >= 2)
          s = (s > f[i + 1][j - 1][k - 2] ? s : f[i + 1][j - 1][k - 2]);
        for (int l = i; l <= j - 1; l++)
          s = (s > f[i][l][0] + f[l + 1][j][k] ? s
                                               : f[i][l][0] + f[l + 1][j][k]),
          s = (s > f[i][l][k] + f[l + 1][j][0] ? s
                                               : f[i][l][k] + f[l + 1][j][0]);
        if (a[k] != -1)
          f[i][j][0] = (f[i][j][0] > s + a[k] ? f[i][j][0] : s + a[k]);
      }
  for (int i = 1; i <= n; i++) {
    g[i] = g[i - 1];
    for (int j = 1; j <= i; j++)
      g[i] = (g[i] > f[j][i][0] + g[j - 1] ? g[i] : f[j][i][0] + g[j - 1]);
  }
  printf("%d\n", g[n]);
  return 0;
}
