Automobile
Time limit1sMemory limit64 MB
Starting from a matrix where each cell holds its row-major index, apply K row and column multiplications and report the total sum modulo 1e9+7.
- Level
Medium4 of 10
- Topics
- Math, Implementation, Hash map, Prefix sum
- Solved
- No attempts yet
Problem
Mirko found a matrix with rows and columns on the back seat of his car. The first row holds , the second row holds , and the same rule continues, so the -th row holds .
For and the matrix is this one.
The matrix was not interesting enough for Mirko, so times he picked a row or a column and multiplied every value in it by a non-negative integer. He wants the sum of all values in the final matrix. That sum can be very large, so print it modulo .
Input
The first line contains (), () and (), separated by spaces. Each of the next lines describes one operation, given in the order the operations were performed.
- "R X Y" multiplies every value in row by . is an integer with , and is an integer with .
- "S X Y" multiplies every value in column by . is an integer with , and is an integer with .
Output
Print the sum of all values in the final matrix modulo on the first line.
Note
Look at the first example. After the second row is multiplied by 4, the fourth column by 1, the third row by 2, and the second row by 0 again, the matrix is this one.
The sum of all values is .