#include <bits/stdc++.h>
using namespace std;
const int N = 155;
const long long inf = 1LL << 55;
string s;
long long n, a[N], dp[N][N][N], ans[N][N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == -1) a[i] = -inf;
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 0; k <= n; k++) dp[i][j][k] = -inf;
  for (int i = 0; i <= n; i++) dp[i][i][0] = dp[i][i + 1][1] = 0;
  cin >> s;
  for (int i = n; i >= 0; i--)
    for (int j = i + 1; j <= n; j++) {
      for (int k = 1; k <= j - i; k++) {
        if (s[i] == s[j - 1] && k > 1) dp[i][j][k] = dp[i + 1][j - 1][k - 2];
        for (int m = i + 1; m < j; m++)
          dp[i][j][k] = max(dp[i][j][k], max(dp[i][m][0] + dp[m][j][k],
                                             dp[i][m][k] + dp[m][j][0]));
        dp[i][j][0] = max(dp[i][j][0], dp[i][j][k] + a[k]);
      }
      ans[i][j] = max(dp[i][j][0], ans[i][j]);
      for (int m = i; m < j; m++)
        ans[i][j] = max(ans[i][j], ans[i][m] + ans[m][j]);
    }
  cout << ans[0][n] << '\n';
  return 0;
}
