#include <bits/stdc++.h>
using namespace std;
long long int powm(long long int a, int b, int n) {
  long long int rm = 1;
  while (b) {
    if (b % 2) {
      rm = (rm * a) % n;
    }
    a = (a * a) % n;
    b /= 2;
  }
  return rm;
}
int bestresult[160][160], fulldest[160][160], pali[160][160][160], n, a[160];
string s;
bool isPali(int l, int r) {
  while (r >= l) {
    if (s[l] != s[r]) return false;
    r--, l++;
  }
  return true;
}
void go(int l, int r) {
  int len = r - l + 1;
  bool isPal = isPali(l, r);
  int to1, from2;
  for (int i = l; i < r; ++i) {
    to1 = i, from2 = i + 1;
    for (int j = 0; j <= i - l + 1; ++j) {
      pali[l][r][j] = max(pali[l][r][j], pali[l][to1][j] + pali[i + 1][r][0]);
    }
    for (int j = 0; j <= r - i; ++j) {
      pali[l][r][j] = max(pali[l][r][j], pali[l][i][0] + pali[i + 1][r][j]);
    }
  }
  if (s[l] == s[r]) {
    int l2 = l + 1, r2 = r - 1;
    if (r - l == 1) {
      if (a[2] > -1) pali[l][r][0] = max(pali[l][r][0], a[2]);
      pali[l][r][2] = 0;
    } else {
      for (int j = 0; j <= r2 - l2 + 1; ++j) {
        pali[l][r][j + 2] = max(pali[l][r][j + 2], pali[l2][r2][j]);
        if (a[j + 2] > -1) {
          pali[l][r][0] = max(pali[l][r][0], a[j + 2] + pali[l2][r2][j]);
        }
      }
    }
  }
  for (int i = l; i < r; ++i) {
    bestresult[l][r] =
        max(bestresult[l][r], bestresult[l][i] + bestresult[i + 1][r]);
  }
  if (s[l] == s[r]) {
    for (int j = 0; j <= len - 2 && len > 2; ++j) {
      bestresult[l][r] = max(bestresult[l][r], pali[l + 1][r - 1][j] +
                                                   max(0, max(a[j], a[j + 2])));
    }
  }
  bestresult[l][r] = max(bestresult[l][r], pali[l][r][0]);
}
int main() {
  string locals;
  cin >> n;
  for (int i = int(1); i <= (int)n; i++) cin >> a[i];
  cin >> locals;
  s = '#' + locals;
  for (int i = 0; i < 153; ++i) {
    for (int j = 0; j < 153; ++j) {
      bestresult[i][j] = 0;
      for (int k = 0; k < 153; ++k) {
        pali[i][j][k] = -5e7;
      }
    }
  }
  if (a[1] > -1) {
    for (int i = int(1); i <= (int)n; i++) {
      bestresult[i][i] = a[1];
      pali[i][i][0] = a[1];
    }
  }
  for (int i = int(1); i <= (int)n; i++) pali[i][i][1] = 0;
  for (int len = 2; len <= n; ++len) {
    for (int l = 1; l <= n - len + 1; ++l) {
      int r = l + len - 1;
      go(l, r);
    }
  }
  cout << max(0, bestresult[1][n]) << endl;
  return 0;
}
