Runic Echo Row
A row of runes is kept on a table. Each rune has a color and a positive weight .
For any nonempty consecutive segment of the current row, split that segment into maximal contiguous blocks whose runes all have the same color. If a block contains runes with weights , define its block weight as
The echo score of the segment is
where the sum is over all maximal same-color blocks inside the segment.
You must process updates to the row and answer echo score queries.
Input
The first line contains two integers and (, ), the initial number of runes and the number of operations.
Output
For each operation of type , print one line containing a single integer: the echo score of the requested segment at that moment.
If there are no operations of type , print nothing.
Samples
Sample 1
Input
5 7 1 2 1 3 2 4 2 1 1 5 4 1 5 3 2 4 4 1 5 1 3 2 2 4 2 5 2 4 4 1 5
Output
75 93 58 77
For the first query, the blocks in positions through have total weights , , and , so the printed value is . The later printed values correspond to the row after the reversal, insertion, and deletion operations shown in the input.