#include <bits/stdc++.h>
using namespace std;
const int N = 155, INF = 1e9 + 10;
int dp[N][N][N / 2], ans[N][N], a[N];
string s;
void smax(int &a, int b) {
  if (a < b) a = b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == -1) a[i] = -INF;
  }
  cin >> s;
  memset(dp, -63, sizeof dp);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n / 2; j++)
      dp[i][i][j] = max(a[2 * j + 1], a[2 * j] + a[1]);
    ans[i][i] = max(dp[i][i][0], 0);
  }
  for (int i = 1; i < n; i++)
    for (int j = 0; j <= n / 2; j++) dp[i][i - 1][j] = a[2 * j];
  for (int len = 1; len < n; len++)
    for (int l = 0; l < n; l++) {
      int r = l + len;
      if (r >= n) continue;
      for (int d = 0; d <= n / 2; d++) {
        if (s[l] == s[r]) dp[l][r][d] = dp[l + 1][r - 1][d + 1];
        smax(dp[l][r][d], a[2 * d] + dp[l][r][0]);
        for (int it = l; it < r; it++)
          smax(dp[l][r][d], max(dp[l][it][d] + dp[it + 1][r][0],
                                dp[l][it][0] + dp[it + 1][r][d]));
      }
      ans[l][r] = max(dp[l][r][0], 0);
      for (int it = l; it < r; it++)
        smax(ans[l][r], ans[l][it] + ans[it + 1][r]);
    }
  cout << ans[0][n - 1] << "\n";
}
