#include <bits/stdc++.h>
using namespace std;
const int N = 155, inf = 1000000000;
int n;
string s;
int a[N], memo[N][N][N], best[N];
int Dp(int l, int r, int len) {
  if (l == 1 && r == 2 && len == 0) int x = 0;
  if (memo[l][r][len] != -1) return memo[l][r][len];
  if (l > r || len < 0) return len == 0 ? 0 : -inf;
  if (l == r) {
    if (len > 1) return -inf;
    return len == 0 ? a[1] : 0;
  }
  int &ret = memo[l][r][len];
  ret = -inf;
  if (len == 0) {
    for (int i = 1; i <= r - l + 1; i++) ret = max(ret, Dp(l, r, i) + a[i]);
    return ret;
  }
  for (int i = l + 1; i <= r; i++) {
    ret = max(ret, Dp(l, i - 1, 0) + Dp(i, r, len));
    ret = max(ret, Dp(l, i - 1, len) + Dp(i, r, 0));
  }
  if (s[l] == s[r]) ret = max(ret, Dp(l + 1, r - 1, len - 2));
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) a[i] = -inf;
  }
  cin >> s;
  memset(memo, -1, sizeof(memo));
  int tmp = Dp(36, 49, 0);
  for (int i = 1; i <= n; i++) {
    best[i] = best[i - 1];
    for (int j = 0; j < i; j++)
      best[i] = max(best[i], best[j] + Dp(j, i - 1, 0));
  }
  printf("%d\n", best[n]);
  return 0;
}
