#include <bits/stdc++.h>
using namespace std;
const int maxn = 200;
int dp[maxn][maxn][maxn];
char s[maxn];
int a[maxn], b[maxn];
;
int ma[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  scanf("%s", s);
  memset(dp, -1, sizeof(dp));
  a[0] = -1;
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      for (int j = 0; j < n; j++) {
        dp[j][j][1] = 0;
        if (a[i] != -1) {
          dp[j][j][0] = a[i];
        }
      }
    } else if (i == 2) {
      for (int j = 0; j + i - 1 < n; j++) {
        int r = j + i - 1;
        if (s[j] == s[r]) {
          dp[j][r][2] = 0;
          if (a[2] != -1) dp[j][r][0] = a[2];
        }
        if (dp[j][j][0] != -1 && dp[r][r][0] != -1) {
          if (dp[j][r][0] < dp[j][j][0] + dp[r][r][0]) {
            dp[j][r][0] = dp[j][j][0] + dp[r][r][0];
          }
          if (dp[j][r][1] < dp[j][j][0] + dp[r][r][1])
            dp[j][r][1] = dp[j][j][0] + dp[r][r][1];
        }
      }
    } else {
      for (int j = 0; j + i - 1 < n; j++) {
        int r = j + i - 1;
        if (s[j] == s[r]) {
          for (int k = 0; k <= i; k++)
            if (dp[j + 1][r - 1][k] != -1) {
              if (dp[j][r][k + 2] < dp[j + 1][r - 1][k])
                dp[j][r][k + 2] = dp[j + 1][r - 1][k];
              if (a[k + 2] != -1)
                if (dp[j][r][0] < dp[j][r][k + 2] + a[k + 2]) {
                  dp[j][r][0] = dp[j][r][k + 2] + a[k + 2];
                }
            }
        }
        for (int k = j + 1; k <= r; k++)
          if (dp[j][k - 1][0] != -1) {
            for (int l = 0; l <= r - k + 1; l++)
              if (dp[k][r][l] != -1) {
                if (dp[j][r][l] < dp[j][k - 1][0] + dp[k][r][l]) {
                  dp[j][r][l] = dp[j][k - 1][0] + dp[k][r][l];
                  if (a[l] != -1)
                    if (dp[j][r][0] < dp[j][r][l] + a[l])
                      dp[j][r][0] = dp[j][r][l] + a[l];
                }
              }
          }
        for (int k = r - 1; k >= j; k--)
          if (dp[k + 1][r][0] != -1) {
            for (int l = 0; l <= k - j + 1; l++)
              if (dp[j][k][l] != -1) {
                if (dp[j][r][l] < dp[k + 1][r][0] + dp[j][k][l]) {
                  dp[j][r][l] = dp[k + 1][r][0] + dp[j][k][l];
                  if (a[l] != -1)
                    if (dp[j][r][0] < dp[j][r][l] + a[l])
                      dp[j][r][0] = dp[j][r][l] + a[l];
                }
              }
          }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i != 0) ma[i] = ma[i - 1];
    if (dp[0][i][0] != -1 && ma[i] < dp[0][i][0]) ma[i] = dp[0][i][0];
    for (int j = 1; j <= i; j++) {
      if (dp[j][i][0] != -1 && ma[i] < dp[j][i][0] + ma[j - 1])
        ma[i] = dp[j][i][0] + ma[j - 1];
    }
  }
  printf("%d\n", ma[n - 1]);
  return 0;
}
