#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200;
const long long mod = 1e9 + 7;
const long long inf = 1e12;
long long n, c[maxn], dp[maxn][maxn][maxn], dp2[maxn][maxn];
string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> c[i];
    if (c[i] == -1) c[i] = -inf;
  }
  if (n == 1) {
    cout << max(0ll, c[1]);
    return 0;
  }
  cin >> s;
  for (long long k = 0; k <= n; k++) {
    for (long long l = 0; l < n; l++) {
      dp[k][l][l] = c[k + k];
      dp[k][l][l + 1] = max(c[k + k + 1], c[1] + c[k + k]);
    }
  }
  for (long long t = 2; t <= n; t++) {
    for (long long l = 0; l + t <= n; l++) {
      long long r = l + t;
      for (long long k = 0; k <= min(l, n - r); k++) {
        dp[k][l][r] = -inf;
        for (long long i = l + 1; i < r; i++) {
          dp[k][l][r] = max(dp[k][l][r], dp[0][l][i] + dp[k][i][r]);
          dp[k][l][r] = max(dp[k][l][r], dp[k][l][i] + dp[0][i][r]);
        }
        if (k) dp[k][l][r] = max(dp[k][l][r], dp[0][l][r] + c[k + k]);
        if (s[l] == s[r - 1]) {
          dp[k][l][r] = max(dp[k][l][r], dp[k + 1][l + 1][r - 1]);
        }
      }
      for (long long i = l + 1; i < r; i++) {
        dp2[l][r] = max(dp2[l][r], dp2[l][i] + dp2[i][r]);
      }
      dp2[l][r] = max(dp2[l][r], dp[0][l][r]);
    }
  }
  cout << dp2[0][n];
  return 0;
}
