#include <bits/stdc++.h>
using namespace std;
const int INF = 10000000;
char c[200];
int a[200], n, dp[200][200][200][2];
bool vis[200][200][200][2];
int f(int i, int j, int l, bool t) {
  if (i > j) return a[l];
  int &ret = dp[i][j][l][t];
  if (vis[i][j][l][t]) return ret;
  ret = -INF;
  vis[i][j][l][t] = true;
  if (t) {
    ret = max(ret, a[l] + f(i, j, 0, t));
    if (c[i] == c[j]) ret = max(ret, f(i + 1, j - 1, l + 2 - (i == j), 1));
  } else {
    ret = max(f(i + 1, j, l, 0), f(i, j - 1, l, 0));
    ret = max(ret, f(i, j, l, 1));
  }
  for (int k = i; k < j; ++k)
    ret = max(ret, max(f(i, k, 0, t) + f(k + 1, j, l, t),
                       f(i, k, l, t) + f(k + 1, j, 0, t)));
  return ret;
}
int main() {
  n = ({
    int __t;
    scanf("%d", &__t);
    __t;
  });
  for (int i = 0; i < n; ++i)
    a[i + 1] = ({
      int __t;
      scanf("%d", &__t);
      __t;
    }),
          a[i + 1] = ((a[i + 1]) < 0 ? (-INF) : (a[i + 1]));
  scanf("%s", c);
  printf("%d\n", f(0, n - 1, 0, 0));
}
