You are given an grid of complex numbers, all initially equal to
, the imaginary unit. A series of
updates will be made to the grid, in one of the following formats:
R j
- multiply every number in rowby
.
C j
- multiply every number in columnby
.
I
- increment every number in the grid by.
After all updates, determine the sum of the numbers in the grid.
Constraints
Subtask 1 [30%]
There are no increment (type I
) updates.
Subtask 2 [70%]
No additional constraints.
Input Specification
The first line contains two space-separated integers, and
, the sidelength of the grid and the number of updates, respectively.
The next lines each contain an update in one of the following formats:
R j
- multiply every number in rowby
.
C j
- multiply every number in columnby
.
I
- increment every number in the grid by.
Output Specification
The sum of the numbers in the grid after all updates can be expressed in the form
, where
and
are integers. Output one line containing two space-separated integers,
and
.
Note: These numbers may not fit within a 32-bit integer type.
Sample Input
5 4
R 3
I
C 1
R 4
Sample Output
-19 25
Explanation for Sample
Here is the state of the grid after each update:
Initially, every number in the grid is equal to .
The first update, R 3
, multiplies every number in row by
.
The second update, I
, increments every number in the grid by .
The third update, C 1
, multiplies every number in column by
.
The fourth update, R 4
, multiplies every number in row by
.
Finally, the sum of all the numbers in the grid is . Thus,
and
, and the correct output is
-19 25
.
Comments