C. Where the Lantern Lights are Dimming
time limit per test
3 с
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
3 3
0 0
0 0
0 0
W 0 2
W 1 1
C 3
Output
6
Input
5 5
1 5
0 0
-1 2
1 0
0 -2
C 1
W 0 4
C -2
W 1 3
C 3
Output
9