#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int gcd(int a, int b){
return b == 0 ? a : gcd(b, a%b);
}
int main(void){
int n,k,i,j,tmp,petla=0;
//string cykl;
vector<int> kasa, kasa_temp;
int blocked=0;
scanf("%d",&n);
bool is_blocked[n];
kasa.resize(n);
kasa_temp.resize(n);
for(i=0;i<n;i++) { scanf("%d",&kasa[i]); kasa_temp[i]=kasa[i]; is_blocked[i]=false;}
scanf("%d",&k);
char cykl[k+2];
for(i=0;i<=k;i++) scanf("%c",&cykl[i]);
for(i=1;i<=k;i++) cykl[i-1]=cykl[i]; //printf("%c",cykl[i]);
tmp=((n*k)/gcd(n,k));
while(blocked<n){
petla++;
for(i=0;(i<tmp+n)/*&&(!is_blocked[i%n])*/;i++){
if(!is_blocked[i%n]){
if(i<tmp){
if(cykl[i%k]=='P') {
kasa_temp[i%n]--;
//printf("|%d|",i%n);
if(kasa_temp[i%n]<=0) goto stop;
}
else kasa_temp[i%n]++;
//printf("%d. [%d losowal %c] %d %d = %d\n", i, i%n, cykl[i%k], kasa[i%n]+1,-1,kasa[i%n]);
}
else{
if(kasa_temp[i%n]>=kasa[i%n]){
is_blocked[i%n]=true;
blocked++;
}
kasa=kasa_temp;
}
}
}
}
printf("%d",-1);
return 0;
stop:
printf("%d",((petla-1)*tmp)+i+1);
return 0;
}