On an matrix, initially empty, you perform operations. Each operation can be of the following two kinds:
- Horizontal: All cells in rows are set to value
- Vertical: All cells in columns are set to value
After executing all operations, report how many times do the least and most frequent elements occur in the matrix.
Input
The first line contains the size of the matrix , and the number of operations .
Each of the next lines describe one operation.
The operation is described by 4 values , where is a character that describes the kind of the operation (either H
for horizontal or V
for vertical) and describe the operation.
Output
The output consists of a single line that contains the frequency of the element that appears least often and the frequency of the element that appears most often in the matrix after carrying out the operations.
Constraints
-
H
,V
Subtasks
- For 20 points: , ,
- For another 20 points: ,
- For another 20 points: ,
- For another 20 points:
- For another 20 points: No further restrictions
Note: The tests for this task are scored individually!
Example 1
stdin
5 4
H 1 4 2
H 3 5 1
V 2 2 1
H 3 4 3
stdout
7 10
Example 2
stdin
6 5
V 5 5 3
H 4 5 4
V 1 6 3
V 1 2 2
V 4 4 2
stdout
18 18
Example 3
stdin
6 5
H 3 4 2
V 4 5 1
V 4 6 2
H 5 6 2
H 5 6 4
stdout
12 18
Example 4
stdin
8 8
H 4 8 3
H 2 3 3
V 5 7 3
V 4 5 2
H 1 6 2
V 7 8 2
V 5 6 2
H 2 4 4
stdout
6 34
Explanation
In the first example, after applying all the operations, the matrix looks as follows:
The least frequent element is with a frequency of , and the most frequent element is with a frequency of .
In the third example, after applying all the operations, the matrix looks as follows:
The least frequent element is with a frequency of and the most frequent element is with a frequency of .