#include<bits/stdc++.h>
#define int long long
#define INF INT_MAX
using namespace std;
const int maxn=2e5+5;
int n,ans;
int a[maxn];
int M[maxn][5],X[maxn][5];
string s;
int mex(int x, int y, int z) {
for (int i=0; i<3; i++) {
if (x!=i && y!=i && z!=i) return i;
}
return 3;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i];
cin>>s;
s=' '+s;
for(int i=1; i<=n; i++) {
for(int j=0; j<=4; j++) M[i][j]=M[i-1][j];
if(s[i-1]=='M') M[i][a[i-1]]++;
}
for(int i=n; i>=1; i--) {
for(int j=0; j<=4; j++) X[i-1][j]=X[i][j];
if(s[i-1]=='X') X[i-1][a[i-1]]++;
}
for(int i=1; i<=n; i++) {
if(s[i-1]!='E') continue;
for(int j=1; j<=3; j++) {
for(int k=1; k<=3; k++) {
ans+=M[i-1][j-1]*X[i][k-1]*mex(j-1,a[i-1],k-1);
}
}
}
cout<<ans<<endl;
return 0;
}