#include <bits/stdc++.h>
using namespace std;
int l[2][155], ans[155][155], dp[155][155][155], over[155][155];
char s[155];
int max(int x, int y) { return x > y ? x : y; }
void check(int &x, int y) {
  if (x == -1 || x < y) x = y;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &l[0][i]);
  for (int i = 1; i <= n; i++) {
    if (l[0][i] == -1)
      l[1][i] = 0;
    else
      l[1][i] = l[0][i];
  }
  scanf("%s", s);
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if ((i - j) % 2 == 1) continue;
      if (l[0][j] == -1) continue;
      if (l[0][i - j] != -1) l[0][i] = max(l[0][i], l[0][j] + l[0][i - j]);
      l[1][i] = max(l[1][i], l[0][j] + l[1][i - j]);
    }
  }
  memset(ans, 0, sizeof(ans));
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) {
    ans[i][i] = l[1][1];
    dp[i][i][1] = 0;
    if (l[0][1] != -1) dp[i][i][0] = l[0][1];
  }
  for (int i = 0; i < n - 1; i++) {
    if (l[0][1] != -1) {
      dp[i][i + 1][1] = l[0][1];
      dp[i][i + 1][0] = 2 * l[0][1];
    }
    if (s[i] == s[i + 1]) {
      ans[i][i + 1] = max(2 * l[1][1], l[1][2]);
      dp[i][i + 1][2] = 0;
      if (l[0][2] != -1) check(dp[i][i + 1][0], l[0][2]);
    } else
      ans[i][i + 1] = 2 * l[1][1];
  }
  for (int o = 3; o <= n; o++)
    for (int i = 0; i <= n - o; i++) {
      int j = i + o - 1;
      if (s[i] == s[j]) {
        for (int t = 0; t <= o - 2; t++) {
          if (dp[i + 1][j - 1][t] == -1) continue;
          check(dp[i][j][t + 2], dp[i + 1][j - 1][t]);
          if (dp[i][j][t + 2] != -1) {
            check(ans[i][j], dp[i][j][t + 2] + l[1][t + 2]);
            if (l[0][t + 2] != -1)
              check(dp[i][j][0], dp[i][j][t + 2] + l[0][t + 2]);
          }
        }
      }
      for (int k = i; k < j; k++) {
        check(ans[i][j], ans[i][k] + ans[k + 1][j]);
        if (dp[i][k][0] != -1) {
          for (int c = 1; c <= j - k; c++)
            if (dp[k + 1][j][c] != -1)
              check(dp[i][j][c], dp[i][k][0] + dp[k + 1][j][c]);
        }
        if (dp[k + 1][j][0] != -1) {
          for (int c = 1; c <= k - i + 1; c++)
            if (dp[i][k][c] != -1)
              check(dp[i][j][c], dp[i][k][c] + dp[k + 1][j][0]);
        }
      }
    }
  printf("%d\n", ans[0][n - 1]);
  return 0;
}
