COCI '17 Contest 4 #3 Automobil
View as PDFMirko has found a matrix with  rows and 
 columns at the back seat of his car. The first
row of the matrix consists of numbers 
, the second row of numbers
 and so on until the 
 row which consists of numbers
, respectively.
For example, for  and 
:
Such matrix wasn't interesting enough to him, so he chose a row or a column  times and
multiplied its values with a non-negative integer.
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 . Help Mirko answer
this question.
Input Specification
The first line of input contains the numbers  
, 
 
and 
 
 from the task.
Each of the following  lines describes:
- Either the multiplication of the 
row with
, in the form of "R X Y", where
Rrepresents 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", where
Srepresents 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 fourth column with 
, the third row with 
, and again the
second row with 
, the final matrix looks like this:
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