#include <bits/stdc++.h>
using namespace std;
int N, A[201];
char C[200];
bool P[200][200];
int FF[200][200][100][2];
int Rec(int q, int w, int e, int r) {
  if (FF[q][w][e][r] == -1) {
    if (q == w) {
      if (A[2 * e] == -1)
        FF[q][w][e][r] = -2;
      else
        FF[q][w][e][r] = A[2 * e];
      return FF[q][w][e][r];
    }
    int ans = -2, i, j, k;
    if ((e != 0) && (A[2 * e] != -1) && (Rec(q, w, 0, r) != -2))
      ans = max(ans, A[2 * e] + Rec(q, w, 0, r));
    if (r == 1) ans = max(ans, Rec(q + 1, w, e, 1));
    if (r == 1) ans = max(ans, Rec(q, w - 1, e, 1));
    for (i = q; i < w; i++)
      if ((A[i - q + 1] != -1) && (P[q][i + 1]) && (Rec(i + 1, w, e, r) != -2))
        ans = max(ans, Rec(i + 1, w, e, r) + A[i - q + 1]);
    for (i = q; i < w; i++)
      if ((A[w - i] != -1) && (P[i][w]) && (Rec(q, i, e, r) != -2))
        ans = max(ans, Rec(q, i, e, r) + A[w - i]);
    for (i = q + 1; i < w; i++)
      if ((Rec(q, i, 0, r) != -2) && (Rec(i, w, e, r) != -2))
        ans = max(ans, Rec(q, i, 0, r) + Rec(i, w, e, r));
    for (i = q + 1; i < w; i++)
      if ((Rec(q, i, e, r) != -2) && (Rec(i, w, 0, r) != -2))
        ans = max(ans, Rec(q, i, e, r) + Rec(i, w, 0, r));
    for (i = q + 1; i < w; i++)
      if (C[i] == C[q]) {
        j = Rec(q + 1, i, e + 1, 0);
        if (e == 0)
          k = Rec(i + 1, w, 0, r);
        else
          k = Rec(i + 1, w, 0, 0);
        if ((j != -2) && (k != -2)) ans = max(ans, j + k);
      }
    if (A[2 * e + 1] != -1)
      for (i = q; i < w; i++) {
        j = Rec(q, i, 0, 0);
        k = Rec(i + 1, w, 0, 0);
        if ((j != -2) && (k != -2)) ans = max(ans, j + k + A[2 * e + 1]);
      }
    FF[q][w][e][r] = ans;
  }
  return FF[q][w][e][r];
}
int main() {
  int i, j, k;
  scanf("%d", &N);
  for (i = 0; i < N; i++) scanf("%d", &A[i + 1]);
  A[0] = 0;
  char ch;
  for (i = 0; i < N; i++) {
    do {
      scanf("%c", &ch);
    } while ((ch < 'a') || (ch > 'z'));
    C[i] = ch;
  }
  for (k = 0; k < N; k++) {
    for (i = 0; i < N; i++)
      if (i + k <= N) {
        if (k < 2)
          P[i][i + k] = true;
        else if ((C[i] == C[i + k - 1]) && (P[i + 1][i + k - 1]))
          P[i][i + k] = true;
        else
          P[i][i + k] = false;
      }
  }
  memset(FF, 0xFF, sizeof(FF));
  printf("%d\n", Rec(0, N, 0, 1));
  return 0;
}
