Under construction

Still being built. Things may change

Alchemy

Time limit2sMemory limit1024 MB

Summary
After each rod is painted, the task counts unit squares of an n by m grid with exactly t painted sides, for every t from 0 to 4.
Level

Medium6 of 10

Topics
Math, Sorting, Implementation
Solved
No attempts yet

Problem

For many years, alchemists tried to perform transmutation with the Philosopher's Stone. The alchemist Vlachur came very close. Vlachur has a rectangular metal grid made of (n+1)+(m+1)(n+1)+(m+1) iron rods, sized nn by mm. The horizontal rods are numbered from 00 to nn from bottom to top, and the vertical rods are numbered from 00 to mm from left to right.

To carry out the transmutation, Vlachur performs the following operation: he takes one rod and paints all of it with magic paint. To see how close he is to his goal, he needs to know how many unit-area squares of his grid have exactly tt (0≤t≤40 \le t \le 4) painted sides. Help him!

Input

The first line contains three integers nn, mm, and qq (1≤n,m≤1091 \le n, m \le 10^9, 1≤q≤1051 \le q \le 10^5), the grid size and the number of operations. Each of the next qq lines describes an operation.

If the first character of the line is h, the same line contains an integer xx (0≤x≤n0 \le x \le n), and the operation paints horizontal rod xx. Similarly, a line starting with v followed by an integer yy (0≤y≤m0 \le y \le m) paints vertical rod yy.

A line consisting of a single ? means you must output five numbers: for every tt from 00 to 44, print ata_t, the number of sub-rectangles of the grid that have exactly tt painted sides.

Output

For each ? operation, print five numbers: the required counts a0,a1,a2,a3,a4a_0, a_1, a_2, a_3, a_4.

Examples1

  1. Example 1

    Input
    3 3 4
    h 1
    v 1
    h 2
    ?
    
    Expected output
    0 2 5 2 0