#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxn = 160;
int dpbest[maxn][maxn] = {};
int dpall[maxn][maxn] = {};
int dprem[maxn][maxn][maxn] = {};
int a[maxn] = {};
const int cinf = 1000000000;
string s;
int getrem(int l, int r, int len);
int getall(int l, int r);
int getbest(int l, int r) {
  if (dpbest[l][r] == -1) {
    dpbest[l][r] = max(0, getall(l, r));
    for (int i = l + 1; i <= r; ++i) {
      dpbest[l][r] = max(dpbest[l][r], getbest(l, i - 1) + getbest(i, r));
    }
  }
  return dpbest[l][r];
}
int getall(int l, int r) {
  if (dpall[l][r] == -1) {
    dpall[l][r] = -cinf;
    for (int len = 1; len <= r - l + 1; ++len) {
      if (a[len] != -1) {
        dpall[l][r] = max(dpall[l][r], getrem(l, r, len) + a[len]);
      }
    }
  }
  return dpall[l][r];
}
int getrem(int l, int r, int len) {
  if (l > r) return 0;
  if (len == 0) return getall(l, r);
  if (dprem[l][r][len] == -1) {
    dprem[l][r][len] = -cinf;
    for (int i = l + 1; i <= r; ++i) {
      if (i - 1 - l + 1 >= len)
        dprem[l][r][len] =
            max(dprem[l][r][len], getrem(l, i - 1, len) + getall(i, r));
      if (r - i + 1 >= len)
        dprem[l][r][len] =
            max(dprem[l][r][len], getrem(i, r, len) + getall(l, i - 1));
    }
    if (s[l] == s[r]) {
      int t = -cinf;
      if (l == r) {
        if (len >= 1) t = getrem(l + 1, r - 1, len - 1);
      } else {
        if (len >= 2) t = getrem(l + 1, r - 1, len - 2);
      }
      dprem[l][r][len] = max(dprem[l][r][len], t);
    }
  }
  return dprem[l][r][len];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i + 1]);
  cin >> s;
  memset(dpbest, -1, sizeof(dpbest));
  memset(dpall, -1, sizeof(dpall));
  memset(dprem, -1, sizeof(dprem));
  int ans = getbest(0, n - 1);
  printf("%d", ans);
  return 0;
}
