Mirko has found a matrix with
For example, for
Such matrix wasn't interesting enough to him, so he chose a row or a column
Naturally, now he wants to know the sum of all the values from the matrix. Since this sum
can be very large, Mirko will be satisfied with the value modulo
Input Specification
The first line of input contains the numbers
Each of the following
- Either the multiplication of the
row with , in the form of "R X Y", whereR
represents row multiplication, is a positive integer , and is a non-negative integer . - Or the multiplication of the
column with , in the form of "S X Y", whereS
represents column multiplication, is a positive integer , and is a non-negative integer .
Output Specification
You must output the sum of the final values from the matrix modulo
Scoring
In test cases worth a total of 50 points, it will hold
Sample Input 1
3 4 4
R 2 4
S 4 1
R 3 2
R 2 0
Sample Output 1
94
Explanation for Sample Output 1
After multiplying the second row with
The sum of the elements from the final matrix is
Sample Input 2
3 1 1
S 1 4
Sample Output 2
24
Sample Input 3
2 4 4
S 2 0
S 2 3
R 1 5
S 1 3
Sample Output 3
80
Comments