#include <bits/stdc++.h>
using namespace std;
const int MAXN = 155;
int a[MAXN];
int cache[MAXN][MAXN][2];
int cache2[MAXN][MAXN][MAXN];
string str;
int rec(int, int, int);
int inner_rec(int st, int ed, int cnt) {
  if (cache2[st][ed][cnt] >= -2) return cache2[st][ed][cnt];
  int tmp, tmp2, res;
  res = -2;
  if (a[cnt] >= 0) {
    tmp = rec(st, ed, 1);
    if (tmp >= 0) res = max(res, tmp + a[cnt]);
  }
  if (a[cnt + 1] >= 0) {
    for (int i = st; i < ed; i++) {
      tmp = rec(st, i, 1);
      tmp2 = rec(i + 1, ed, 1);
      if (tmp < 0 || tmp2 < 0) continue;
      res = max(res, tmp + tmp2 + a[cnt + 1]);
    }
  }
  for (int i = st + 1; i < ed; i++) {
    tmp = rec(st, i, 1);
    tmp2 = inner_rec(i, ed, cnt);
    if (tmp >= 0 && tmp2 >= 0) res = max(res, tmp + tmp2);
  }
  for (int j = ed - 1; j > st; j--)
    if (str[st] == str[j]) {
      tmp = rec(j + 1, ed, 1);
      tmp2 = inner_rec(st + 1, j, cnt + 2);
      if (tmp >= 0 && tmp2 >= 0) res = max(res, tmp + tmp2);
    }
  return cache2[st][ed][cnt] = res;
}
int rec(int st, int ed, int all) {
  if (st >= ed) return 0;
  if (cache[st][ed][all] >= -2) return cache[st][ed][all];
  if (all) return cache[st][ed][all] = inner_rec(st, ed, 0);
  int res = 0;
  for (int i = st; i < ed; i++)
    for (int j = i + 1; j <= ed; j++) {
      int tmp = rec(i, j, 1);
      if (tmp >= 0) res = max(res, rec(st, i, 0) + tmp + rec(j, ed, 0));
    }
  return cache[st][ed][all] = res;
}
int main() {
  int l;
  cin >> l;
  for (int i = 0; i < l; i++) cin >> a[i + 1];
  a[0] = -1;
  cin >> str;
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < MAXN; j++) cache[i][j][0] = cache[i][j][1] = -10;
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < MAXN; j++)
      for (int k = 0; k < MAXN; k++) cache2[i][j][k] = -10;
  int ans = rec(0, l, 0);
  cout << ans << endl;
  return 0;
}
