#ASAPOROB. 圧縮

圧縮

Score : 14001400 points

Problem Statement

Takahashi found an integer sequence (A1,A2,...,AN)(A_1,A_2,...,A_N) with NN terms. Since it was too heavy to carry, he decided to compress it into a single integer.

The compression takes place in N1N-1 steps, each of which shorten the length of the sequence by 11. Let SS be a string describing the steps, and the sequence on which the ii-th step is performed be (a1,a2,...,aK)(a_1,a_2,...,a_K), then the ii-th step will be as follows:

  • When the ii-th character in SS is M, let bi=max(ai,ai+1)b_i = max(a_i,a_{i+1}) (1iK1)(1 \leq i \leq K-1), and replace the current sequence by (b1,b2,...,bK1)(b_1,b_2,...,b_{K-1}).
  • When the ii-th character in SS is m, let bi=min(ai,ai+1)b_i = min(a_i,a_{i+1}) (1iK1)(1 \leq i \leq K-1), and replace the current sequence by (b1,b2,...,bK1)(b_1,b_2,...,b_{K-1}).

Takahashi decided the steps SS, but he is too tired to carry out the compression. On behalf of him, find the single integer obtained from the compression.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1AiN1 \leq A_i \leq N
  • SS consists of N1N-1 characters.
  • Each character in SS is either M or m.

Partial Scores

  • In the test set worth 400400 points, there exists i(1i<N1)i (1 \leq i < N-1) such that the first ii characters in SS are M, and the remaining characters are m, that is, SS is in the form M...Mm...m.
  • In the test set worth 800800 points, the odd-number-th characters in SS are M, and the even-number-th characters are m, that is, SS is in the form MmMmMm....

Input

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

NN

A1A_1 A2A_2ANA_N

SS

Output

Print the single integer obtained from the compression.

4
1 2 3 4
MmM
3

The initial sequence (1,2,3,4)( 1 , 2 , 3 , 4 ) is compressed as follows:

  • After the first step, the sequence is (2,3,4)( 2 , 3 , 4 ).
  • After the second step, the sequence is (2,3)( 2 , 3 ).
  • After the third step, the sequence is (3)( 3 ).

Thus, the single integer obtained from the compression is 33.

5
3 4 2 2 1
MMmm
2
10
1 8 7 6 8 5 2 2 6 1
MmmmmMMMm
5
20
12 7 16 8 7 19 8 19 20 11 7 13 20 3 4 11 19 11 15 5
mMMmmmMMMMMMmMmmmMM
11