#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2, md) % md
                      : power(a * a % md, b / 2, md) % md));
}
const int xn = 150 + 10;
const int xm = -20 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const long long INF = 1e18 + 10;
const int mod = 998244353;
const int base = 257;
int n, a[xn], f[xn][xn][xn], dp[xn][xn];
string S;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  cin >> S, S = '.' + S;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < xn; ++j) f[i][0][j] = -inf;
    for (int j = 0; j < xn; ++j) f[i][1][j] = -inf;
    f[i][1][1] = 0;
    if (a[1] != -1) {
      f[i][1][0] = a[1];
      dp[i][1] = a[1];
    }
  }
  for (int t = 2; t <= n; ++t) {
    for (int l = 1; l + t - 1 <= n; ++l) {
      int r = l + t - 1;
      for (int i = 0; i < xn; ++i) f[l][t][i] = -inf;
      if (S[l] == S[r])
        for (int i = 2; i <= t; ++i) f[l][t][i] = f[l + 1][t - 2][i - 2];
      for (int j = 1; j < t; ++j) {
        for (int i = 0; i <= t; ++i) {
          f[l][t][i] = max(f[l][t][i], f[l][j][i] + f[l + j][t - j][0]);
          f[l][t][i] = max(f[l][t][i], f[l][j][0] + f[l + j][t - j][i]);
        }
        dp[l][t] = max(dp[l][t], dp[l][j] + dp[l + j][t - j]);
      }
      for (int i = 1; i <= t; ++i)
        if (a[i] != -1) f[l][t][0] = max(f[l][t][0], f[l][t][i] + a[i]);
      dp[l][t] = max(dp[l][t], f[l][t][0]);
    }
  }
  cout << dp[1][n] << '\n';
  return 0;
}
