#abc308e. [abc308_e]MEX

[abc308_e]MEX

Problem Statement

You are given a length-NN sequence A=(A1,A2,dots,AN)A=(A_1,A_2,\\dots,A_N) consisting of 00, 11, and 22, and a length-NN string S=S1S2dotsSNS=S_1S_2\\dots S_N consisting of M, E, and X.

Find the sum of textmex(Ai,Aj,Ak)\\text{mex}(A_i,A_j,A_k) over all tuples of integers (i,j,k)(i,j,k) such that 1leqi<j<kleqN1 \\leq i < j < k \\leq N and SiSjSk=S_iS_jS_k= MEX. Here, textmex(Ai,Aj,Ak)\\text{mex}(A_i,A_j,A_k) denotes the minimum non-negative integer that equals neither Ai,AjA_i,A_j, nor AkA_k.

Constraints

  • 3leqNleq2times1053\\leq N \\leq 2\\times 10^5
  • NN is an integer.
  • Aiinlbrace0,1,2rbraceA_i \\in \\lbrace 0,1,2\\rbrace
  • SS is a string of length NN consisting of M, E, and X.

Input

The input is given from Standard Input in the following format:

NN A1A_1 A2A_2 dots\\dots ANA_N SS

Output

Print the answer as an integer.


Sample Input 1

4
1 1 0 2
MEEX

Sample Output 1

3

The tuples (i,j,k)(1leqi<j<kleqN)(i,j,k)\\ (1 \\leq i < j < k \\leq N) such that SiSjSkS_iS_jS_k = MEX are the following two: (i,j,k)=(1,2,4),(1,3,4)(i,j,k)=(1,2,4),(1,3,4). Since textmex(A1,A2,A4)=textmex(1,1,2)=0\\text{mex}(A_1,A_2,A_4)=\\text{mex}(1,1,2)=0 and textmex(A1,A3,A4)=textmex(1,0,2)=3\\text{mex}(A_1,A_3,A_4)=\\text{mex}(1,0,2)=3, the answer is 0+3=30+3=3.


Sample Input 2

3
0 0 0
XXX

Sample Output 2

0

Sample Input 3

15
1 1 2 0 0 2 0 2 0 0 0 0 0 2 2
EXMMXXXEMEXEXMM

Sample Output 3

13