Task
Little Newton likes gravity and plays with a magical shape made out of squares, suspended in the air.
Initially, this shape is made of only one such square. On this magical shape two things happen (in this order):
- Grow phase: Around each square in this shape some new squares will appear. The grow phase can be of two types:
- Type
+The new squares will appear around the squares in only 4 directions (north, south, east and west). - Type
*The new squares will appear in 8 directions (north, south, east, west, north-east, north-west, south-east and south-west).
- Type
- Gravity phase: In this phase, Little Newton places a plate under the shape and lets all the squares fall onto it. Note: The plate is removed immediately after this operation!
As an example, the effects of each of the 2 types of grow phases, followed by a gravity phase, are pictured below.

Little Newton has an array of types of grow phases and wants to do operations of the following types:
- : If then set it to ; otherwise if set it to .
- : Suppose Little Newton starts with a shape made out of only one square and applies, for , in order, a grow phase of type followed by a gravity phase. How many squares will the shape have in the end?
Help Little Newton answer all of these queries.
Input data
The first line of the input contains the number . The second line contains symbols from among , not separated by spaces, representing the initial values of . The third line of the input contains the number . Then, each of the following lines will contain one of the following: either two integers representing an operation, or three integers representing a operation.
Output data
You should output the answer for each operation, each on a new line.
Constraints and clarifications
- .
- .
- for .
- , and for each operation.
| # | Points | Constraints |
|---|---|---|
| 1 | 5 | for each and the operations are only of type 2. |
| 2 | 10 | and . |
| 3 | 20 | and . |
| 4 | 30 | for each and the operations are only of type 2. |
| 5 | 35 | No further restrictions. |
Example
stdin
4
+*++
9
2 2 4
1 3
1 4
2 2 4
1 1
1 2
1 3
1 4
2 2 4
stdout
39
49
31
Explanation
First query. In this query, the sequence of operations is *++. The shape thus has the following configurations.

Hence the answer is .
Second query. In the second query, the sequence of operations is ***. The shape thus has the following configurations.

Therefore, the answer is .
Third query. In the last query, the sequence of operations is +++. The shape thus has the following configurations.

Thus, the answer is .