#include <bits/stdc++.h>
using namespace std;
const int L = 160;
const int inf = 0x3f3f3f3f;
int a[L];
char s[L];
int dp[L][L][L], n, g[L];
int dfs(int l, int r, int len) {
  if (dp[l][r][len] != -1) return dp[l][r][len];
  if (r < l) {
    if (len == 0) return 0;
    return -inf;
  }
  dp[l][r][len] = -inf;
  for (int i = l + 1; i <= r; i++) {
    dp[l][r][len] = max(dp[l][r][len], dfs(l, i - 1, 0) + dfs(i, r, len));
    dp[l][r][len] = max(dp[l][r][len], dfs(l, i - 1, len) + dfs(i, r, 0));
  }
  if (s[l] == s[r]) {
    int tmp = len;
    if (l != r)
      tmp += 2;
    else
      tmp += 1;
    dp[l][r][len] = max(dp[l][r][len], dfs(l + 1, r - 1, 0) + a[tmp]);
    dp[l][r][len] = max(dp[l][r][len], dfs(l + 1, r - 1, len + 2));
  }
  return dp[l][r][len];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == -1) a[i] = -inf;
  }
  cin >> s;
  memset(dp, -1, sizeof(dp));
  g[0] = 0;
  for (int i = 1; i <= n; i++) {
    g[i] = g[i - 1];
    for (int j = 0; j < i; j++) g[i] = max(g[i], g[j] + dfs(j, i - 1, 0));
  }
  cout << g[n] << endl;
  return 0;
}
