#include <bits/stdc++.h>
using namespace std;
string str;
int dp[159][159][159], val[159], dp1[159][159];
int memoize(int l, int r, int len) {
  if (l > r) return val[len];
  if (dp[l][r][len] != -1) return dp[l][r][len];
  int ans = -1 * 1000000000;
  if (str[l] == str[r]) {
    ans = max(ans, memoize(l + 1, r - 1, len + 1 + (l != r)));
    ans = max(ans, memoize(l + 1, r - 1, 0) + val[len + 1 + (l != r)]);
  }
  for (int i = int(l); i <= int(r - 1); i++) {
    ans = max(ans, memoize(l, i, 0) + memoize(i + 1, r, len));
    ans = max(ans, memoize(l, i, len) + memoize(i + 1, r, 0));
  }
  return dp[l][r][len] = ans;
}
int memoize1(int l, int r) {
  if (l > r) return 0;
  if (dp1[l][r] != -1) return dp1[l][r];
  int ans = 0;
  ans = max(ans, memoize1(l + 1, r));
  ans = max(ans, memoize1(l, r - 1));
  ans = max(ans, memoize(l, r, 0));
  for (int i = int(l); i <= int(r - 1); i++)
    ans = max(ans, memoize1(l, i) + memoize1(i + 1, r));
  return dp1[l][r] = ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  memset(dp1, -1, sizeof(dp1));
  int n;
  scanf("%d", &n);
  for (int i = int(1); i <= int(n); i++) {
    scanf("%d", &val[i]);
    if (val[i] < 0) val[i] = -1 * 1000000000;
  }
  cin >> str;
  int ans = memoize1(0, n - 1);
  cout << ans << endl;
  return 0;
}
