After he beat Tanaka in last year’s cook-off contest (yes, the most important contest in all of Info(1)Cup Kingdom), Lulu decided to quit cooking and go treasure hunting. But since Tanaka is a very ambitious person, he wants to get his revenge and beat Lulu this time. The hunt takes place inside of a maze which can be represented as a matrix of size . Each cell can be either a wall (represented by the character #
) or a treasure cell (represented by the character $
). Each treasure cell can contain at most one treasure. Initially, all treasure cells contain a treasure.
We say that the cell is reachable from if one can get from to by moving only down or to the right through treasure cells. Note that a treasure cell is reachable from itself.
The maze has a very interesting property. The cell is reachable from any treasure cell and any treasure cell is reachable from . Let be the number of treasure cells which contain a treasure and can be reached from . We define if is a wall. Tanaka thinks that he could get ahead of his opponent by finding , the sum of for all and , i.e.
But then the real treasure hunt begins! At each moment, one of two things can happen:
- The cell gets an update. If the cell previously had a treasure in it, then the treasure disappears. Otherwise, a treasure appears in the cell .
- Tanaka wants to know for a given cell .
Tanaka doesn’t have enough time to do all this on his own, so he needs your programming skills. Help Tanaka beat Lulu by writing a program which calculates the value , then answers all of his queries right.
Input data
The first line of input contains the integers and , the number of rows and columns in the matrix and the number of operations you need to process. The next lines contain characters, representing the maze. Each of the next lines contains an operation, which will be represented as follows:
! x y
, which means the cell gets an update.? x y
, which means you have to output the value .
It is guaranteed that is a treasure cell in both cases.
Output data
The first line of output must contain the value , the sum of for all cells in the initial state. Each of the next lines must contain the answers to Tanaka’s queries, in order.
Restrictions
- It is guaranteed that both and are treasure cells
- 50% of the points for each subtask are awarded for finding , and the other 50% for answering the queries. Please note that you still have to output the value , even if it is not correct, in order to get the points for the queries.
Subtask 1 (5 points)
- or
Subtask 2 (7 points)
- All cells are treasure cells
Subtask 3 (8 points)
- The cell is a wall for all and
Subtask 4 (12 points)
Subtask 5 (18 points)
Subtask 6 (27 points)
Subtask 7 (23 points)
- No further restrictions
Examples
stdin
5 5 5
$$$$$
$$$#$
$#$$$
$$$#$
$$$$$
! 5 4
? 2 2
! 4 5
? 5 5
? 3 4
stdout
159
9
1
3
Explanations
First example In the initial state, the maze looks like this:
The values for the whole maze are:
For the first query, the maze looks like this:
The red cell is the starting cell and the blue cells are those reachable from it. Cells that contain a treasure are marked with a $
sign, and cells without are empty. The number of such cells which contain a treasure is .
For the second query, the maze looks like this:
The only cell reachable from is .
For the third query, the maze looks like this:
The red cell is the starting cell and the blue cells are those reachable from it. The number of such cells which contain a treasure is .