#include <bits/stdc++.h>
using namespace std;
long long dp[160][160][160];
long long ans[160][160];
long long a[160];
char s[160];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 160; i++) a[i] = -0x3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", a + i);
    if (a[i] == -1) a[i] = -0x3f3f3f3f;
  }
  scanf("%s", s + 1);
  for (int i = 0; i < 160; i++)
    for (int j = 0; j < 160; j++)
      for (int k = 0; k < 160; k++) dp[i][j][k] = -0x3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    dp[i][i][1] = 0;
    dp[i][i][0] = a[1];
  }
  for (int i = 1; i < n; i++) {
    int j = i + 1;
    if (s[i] == s[j]) dp[i][j][2] = 0;
    dp[i][j][1] = max(dp[i][i][1] + dp[j][j][0], dp[i][i][0] + dp[j][j][1]);
    dp[i][j][0] = max(dp[i][j][2] + a[2], dp[i][j][1] + a[1]);
  }
  for (int len = 3; len <= n; len++)
    for (int i = 1; i <= n; i++) {
      int j = i + len - 1;
      if (j > n) continue;
      for (int k = 0; k <= len; k++) {
        for (int t = i; t < j; t++) {
          dp[i][j][k] = max(dp[i][j][k], dp[i][t][0] + dp[t + 1][j][k]);
          dp[i][j][k] = max(dp[i][j][k], dp[i][t][k] + dp[t + 1][j][0]);
        }
        if (k >= 2 and s[i] == s[j])
          dp[i][j][k] = max(dp[i][j][k], dp[i + 1][j - 1][k - 2]);
      }
      for (int k = 0; k <= len; k++)
        if (s[i] == s[j])
          dp[i][j][0] = max(dp[i][j][0], dp[i + 1][j - 1][k] + a[k + 2]);
    }
  for (int i = 1; i <= n; i++) ans[i][i] = max(0ll, a[1]);
  for (int i = 1; i < n; i++) {
    int j = i + 1;
    ans[i][j] = ans[i][i] + ans[j][j];
    if (s[i] == s[j]) ans[i][j] = max(ans[i][j], a[2]);
  }
  for (int len = 3; len <= n; len++)
    for (int i = 1; i <= n; i++) {
      int j = i + len - 1;
      if (j > n) continue;
      for (int k = i; k < j; k++)
        ans[i][j] = max(ans[i][j], ans[i][k] + ans[k + 1][j]);
      for (int k = 0; k <= len; k++)
        ans[i][j] = max(ans[i][j], dp[i][j][k] + a[k]);
    }
  cout << ans[1][n] << endl;
}
