Turntable Channels
A studio has reversible turntables in a row and sound channels numbered .
Turntable has a current permutation of the channels and a manual price . When a signal enters turntable on channel , exactly one of the following happens:
- The signal follows the turntable for free and leaves on channel .
- The engineer pays and chooses any output channel with .
A request through interval sends the signal through turntables in that order. The total payment is the sum of prices paid at turntables where the engineer manually chooses the output.
You must process operations of three kinds:
- Invert every turntable in an interval. For each affected turntable , its current permutation is replaced by the inverse permutation , while does not change.
Input
The first line contains three integers , , and (, ), the number of turntables, the number of channels, and the number of operations.
Output
For each operation whose first token is A, print one line containing the minimum possible total payment for that request. Print the answers in the same order as the corresponding operations appear in the input. If there are no operations whose first token is A, print nothing.
Samples
Sample 1
Input
2 3 5 5 2 3 1 4 3 1 2 A 1 2 1 1 I 2 2 A 1 2 1 1 S 1 2 1 3 2 A 1 2 2 2
Output
0 4 2
The first request can follow channel for total payment . After inverting the second turntable, paying at the second turntable can finish on channel . After the replacement, paying at the first turntable can make the final channel equal to .