// #2分段
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int n, w[maxn];
char s[maxn];
int val[maxn][maxn];
void calc_val()
{
for(int i=1; i<n; ++i) if(s[i] != s[i+1]) val[i][i+1] = min(w[i], w[i+1]);
for(int len = 4; len <= n; ++ len)
for(int i=1; i+len-1 <= n; ++i)
if(s[i] != s[i+len-1])
val[i][i+len-1] = val[i+1][i+len-2] + min(w[i], w[i+len-1]);
else
val[i][i+len-1] = val[i+1][i+len-2];
}
int f[maxn];
int main()
{
scanf("%d", &n);
scanf("%s", s + 1);
for(int i=1;i<=n;++i) scanf("%d", &w[i]);
calc_val();
memset(f, 63, sizeof f);
f[0] = 0;
for(int i=2; i<=n; i+=2)
for(int j=0; j<=i-2; j+=2)
f[i] = min(f[i], f[j] + val[j+1][i]);
cout << f[n];
return 0;
}