#include <bits/stdc++.h>
using namespace std;
int n, score[155];
string s;
int best[155][155], full[155][155], keep[155][155][155];
int findFull(int u, int v);
int findKeep(int u, int v, int len) {
  if (len < 0) return -1;
  if (u > v) return (!len) ? 0 : -1;
  if (u == v) {
    if (len == 0 && score[1] >= 0) return score[1];
    if (len == 1) return 0;
    return -1;
  }
  if (!len) return findFull(u, v);
  if (keep[u][v][len] != -2) return keep[u][v][len];
  keep[u][v][len] = -1;
  for (int i = u; i < v; i++)
    if (findFull(u, i) >= 0 && findKeep(i + 1, v, len) >= 0)
      keep[u][v][len] =
          max(keep[u][v][len], findFull(u, i) + findKeep(i + 1, v, len));
  for (int i = u; i < v; i++)
    if (findKeep(u, i, len) >= 0 && findFull(i + 1, v) >= 0)
      keep[u][v][len] =
          max(keep[u][v][len], findKeep(u, i, len) + findFull(i + 1, v));
  if (s[u] == s[v])
    keep[u][v][len] = max(keep[u][v][len], findKeep(u + 1, v - 1, len - 2));
  return keep[u][v][len];
}
int findFull(int u, int v) {
  if (full[u][v] != -2) return full[u][v];
  full[u][v] = -1;
  for (int i = 1; i <= v - u + 1; i++)
    if (score[i] >= 0 && findKeep(u, v, i) >= 0)
      full[u][v] = max(full[u][v], score[i] + findKeep(u, v, i));
  return full[u][v];
}
int findBest(int u, int v) {
  if (best[u][v] != -2) return best[u][v];
  best[u][v] = max(0, findFull(u, v));
  for (int i = u; i < v; i++)
    best[u][v] = max(best[u][v], findBest(u, i) + findBest(i + 1, v));
  return best[u][v];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &score[i]);
  cin >> s;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) {
      best[i][j] = full[i][j] = -2;
      for (int k = 0; k <= n; k++) keep[i][j][k] = -2;
    }
  printf("%d\n", findBest(0, n - 1));
}
