St Andrews Online Judge

Count Larger and Smaller

By Kay Akashi

Time: 2000 ms
Memory: 256000 kB

The code judging system is only available during contests. Check out the github repo for test cases and solutions.

Please log in.

Problem Statement

You are given an array aa consisting of nn integers a1a_{1}, …, ana_{n}. Then in each of mm lines you are given an integer xx and an operation: "LARGER" or "SMALLER". If the operation is "LARGER", your task is to output the number of elements in aa that are STRICTLY larger than xx. If the operation is "SMALLER", your task is to output the number of elements in aa that are STRICTLY smaller than xx.

Constraints

Subtask 1 (20%)

1n,m<1001 \leq n, m \lt 100. Neither element in aa nor xx is smaller than 300-300 and larger than 300300.

Subtask 2 (80%)

100n,m105100 \leq n, m \leq 10^{5}. Neither element in aa nor xx is smaller than 105-10^{5} and larger than 10510^{5}.

Input

The first line of input contains one integer, nn. The second line contains nn integers that compose an array aa. The theird line of input contains one integer, mm. Following are mm lines each of which contains an integer xx and an operation which is either "LARGER" or "SMALLER".

Output

Output the answers in mm lines.

Examples

Input

5
18 19 -130 6 100
4
18 LARGER
-1000 SMALLER
-300 LARGER
0 SMALLER

Output

2
0
5
1