Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm  ×  h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.

In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments.

After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process.

Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?


-----Input-----

The first line contains three integers w, h, n (2 ≤ w, h ≤ 200 000, 1 ≤ n ≤ 200 000).

Next n lines contain the descriptions of the cuts. Each description has the form H y or V x. In the first case Leonid makes the horizontal cut at the distance y millimeters (1 ≤ y ≤ h - 1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance x (1 ≤ x ≤ w - 1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts.


-----Output-----

After each cut print on a single line the area of the maximum available glass fragment in mm^2.


-----Examples-----
Input
4 3 4
H 2
V 2
V 3
V 1

Output
8
4
4
2

Input
7 6 5
H 4
V 3
V 5
H 2
V 1

Output
28
16
12
6
4



-----Note-----

Picture for the first sample test:  [Image]  Picture for the second sample test:  $\square$

Difficulty: interview

Starter code:

Solutions:
def main():
    w, h, n = list(map(int, input().split()))
    res, vrt, hor = [], [], []
    vh = (vrt, hor)
    for i in range(n):
        s = input()
        x = int(s[2:])
        flag = s[0] == 'V'
        vh[flag].append(i)
        res.append([x, flag])
    dim = []
    for tmp, m in zip(vh, (h, w)):
        tmp.sort(key=lambda e: res[e][0])
        u = [None, [0]]
        dim.append(u)
        j = z = 0
        for i in tmp:
            x = res[i][0]
            if z < x - j:
                z = x - j
            j = x
            v = [u, res[i]]
            u.append(v)
            u = v
            res[i].append(u)
        v = [u, [m], None]
        u.append(v)
        dim.append(v)
        if z < m - j:
            z = m - j
        dim.append(z)
    l, r, wmax, u, d, hmax = dim
    whmax = [wmax, hmax]
    for i in range(n - 1, -1, -1):
        x, flag, link = res[i]
        u = whmax[flag]
        res[i] = u * whmax[not flag]
        link[0][2] = link[2]
        link[2][0] = link[0]
        v = link[2][1][0] - link[0][1][0]
        if u < v:
            whmax[flag] = v
    print('\n'.join(map(str, res)))


def __starting_point():
    main()

__starting_point()

def main():
    from sys import stdin
    w, h, n = list(map(int, stdin.readline().split()))
    res, vrt, hor = [], [], []
    vh = (vrt, hor)
    for i, s in enumerate(stdin.read().splitlines()):
        x = int(s[2:])
        flag = s[0] == 'V'
        vh[flag].append(i)
        res.append([x, flag])
    dim = []
    for tmp, m in zip(vh, (h, w)):
        tmp.sort(key=lambda e: res[e][0])
        u = [None, [0]]
        dim.append(u)
        j = z = 0
        for i in tmp:
            x = res[i][0]
            if z < x - j:
                z = x - j
            j = x
            v = [u, res[i]]
            u.append(v)
            u = v
            res[i].append(u)
        v = [u, [m], None]
        u.append(v)
        dim.append(v)
        if z < m - j:
            z = m - j
        dim.append(z)
    l, r, wmax, u, d, hmax = dim
    whmax = [wmax, hmax]
    for i in range(n - 1, -1, -1):
        x, flag, link = res[i]
        u = whmax[flag]
        res[i] = u * whmax[not flag]
        link[0][2] = link[2]
        link[2][0] = link[0]
        v = link[2][1][0] - link[0][1][0]
        if u < v:
            whmax[flag] = v
    print('\n'.join(map(str, res)))


def __starting_point():
    main()

__starting_point()

def main():
    from sys import stdin
    w, h, n = list(map(int, stdin.readline().split()))
    res, vrt, hor = [], [], []
    vh = (vrt, hor)
    for i, s in enumerate(stdin.read().splitlines()):
        x = int(s[2:])
        flag = s[0] == 'V'
        vh[flag].append(i)
        res.append([x, flag])
    dim = []
    for tmp, m in zip(vh, (h, w)):
        tmp.sort(key=lambda e: res[e][0])
        u = [None, [0]]
        dim.append(u)
        j = z = 0
        for i in tmp:
            x = res[i][0]
            if z < x - j:
                z = x - j
            j = x
            v = [u, res[i]]
            u.append(v)
            u = v
            res[i].append(u)
        v = [u, [m], None]
        u.append(v)
        dim.append(v)
        if z < m - j:
            z = m - j
        dim.append(z)
    l, r, wmax, u, d, hmax = dim
    s = str(wmax * hmax)
    for i in range(n - 1, -1, -1):
        x, flag, link = res[i]
        u = hmax if flag else wmax
        res[i] = s
        link[0][2] = link[2]
        link[2][0] = link[0]
        v = link[2][1][0] - link[0][1][0]
        if u < v:
            if flag:
                hmax = v
            else:
                wmax = v
            s = str(wmax * hmax)
    print('\n'.join(res))


def __starting_point():
    main()

__starting_point()

w, h, n = map(int, input().split())

x = [0, w]
y = [0, h]
rev = []

for _ in range(n):
    s, d = input().split()
    if s == 'H':
        y.append(int(d))
    else:
        x.append(int(d))
    rev.append((s, int(d)))

x.sort()
y.sort()

_max = 0
if len(x) > 1:
    for idx in range(len(x) - 1):
        _max = max(_max, x[idx + 1] - x[idx])
else:
    _max = w
max_x = _max

_max = 0
if len(y) > 1:
    for idx in range(len(y) - 1):
        _max = max(_max, y[idx + 1] - y[idx])
else:
    _max = w
max_y = _max

enum_x = {num : idx for idx, num in enumerate(x)}
enum_y = {num : idx for idx, num in enumerate(y)}

old_x = x
old_y = y

x = [[0, 0, 0]] * len(old_x)
y = [[0, 0, 0]] * len(old_y)

for idx in range(1, len(x) - 1):
    x[idx] = [old_x[idx], idx-1, idx+1]
for idx in range(1, len(y) - 1):
    y[idx] = [old_y[idx], idx-1, idx+1]

x[-1] = [w, 0, 0]
y[-1] = [h, 0, 0]

rev.reverse()
ans = [max_x * max_y]
for item in rev:
    if item[0] == 'H':
        elem = y[enum_y[item[1]]]
        max_y = max(max_y, y[elem[2]][0] - y[elem[1]][0])
        y[elem[1]][2] = elem[2]
        y[elem[2]][1] = elem[1]
    else:
        elem = x[enum_x[item[1]]]
        max_x = max(max_x, x[elem[2]][0] - x[elem[1]][0])
        x[elem[1]][2] = elem[2]
        x[elem[2]][1] = elem[1]
    ans.append(max_x * max_y)
ans.pop()
print('\n'.join(map(str, reversed(ans))))

def main():
    from sys import stdin
    w, h, n = list(map(int, stdin.readline().split()))
    res, vrt, hor = [], [], []
    vh = (vrt, hor)
    for i, s in enumerate(stdin.read().splitlines()):
        x = int(s[2:])
        flag = s[0] == 'V'
        vh[flag].append(i)
        res.append([x, flag])
    dim = []
    for tmp, m in zip(vh, (h, w)):
        tmp.sort(key=lambda e: res[e][0])
        u = [None, [0]]
        dim.append(u)
        j = z = 0
        for i in tmp:
            x = res[i][0]
            if z < x - j:
                z = x - j
            j = x
            v = [u, res[i]]
            u.append(v)
            u = v
            res[i].append(u)
        v = [u, [m], None]
        u.append(v)
        dim.append(v)
        if z < m - j:
            z = m - j
        dim.append(z)
    l, r, wmax, u, d, hmax = dim
    whmax = [wmax, hmax]
    for i in range(n - 1, -1, -1):
        x, flag, link = res[i]
        u = whmax[flag]
        res[i] = u * whmax[not flag]
        link[0][2] = link[2]
        link[2][0] = link[0]
        v = link[2][1][0] - link[0][1][0]
        if u < v:
            whmax[flag] = v
    print('\n'.join(map(str, res)))


def __starting_point():
    main()




# Made By Mostafa_Khaled

__starting_point()

# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 1/7/20

reverse thinking of merging instead of split

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List


class Node:
    val = None

    def __init__(self, val):
        self.val = val
        self.left = Node
        self.right = None


def solve(W, H, N, A):
    xs = [0] + [v for t, v in A if t == 0] + [W]
    ys = [0] + [v for t, v in A if t == 1] + [H]
    xs.sort()
    ys.sort()

    xlist = Node(0)
    h = xlist
    xnodes = {0: h}
    maxw = max([xs[i+1] - xs[i] for i in range(len(xs)-1)] or [0])
    maxh = max([ys[i+1] - ys[i] for i in range(len(ys)-1)] or [0])
    for v in xs[1:]:
        n = Node(v)
        xnodes[v] = n
        h.right = n
        n.left = h
        h = n
        
    ylist =  Node(0)
    h = ylist
    ynodes = {0: h}
    for v in ys[1:]:
        n = Node(v)
        ynodes[v] = n
        h.right = n
        n.left = h
        h = n
    
    ans = []
    maxarea = maxh * maxw
    for t, v in reversed(A):
        ans.append(maxarea)
        if t == 0:
            node = xnodes[v]
            w = node.right.val - node.left.val
            maxw = max(maxw, w)
        else:
            node = ynodes[v]
            h = node.right.val - node.left.val
            maxh = max(maxh, h)
        node.left.right = node.right
        node.right.left = node.left
        maxarea = maxh * maxw
    
    return ans[::-1]
    
    
def solve2(W, H, N, A):
    ws = [(-W, 0, W)]
    hs = [(-H, 0, H)]
    iw, ih = set(), set()
    ans = []
    
    xs, ys = [0, W], [0, H]
    for t, v in A:
        if t == 0:
            bisect.insort_left(xs, v)
            i = bisect.bisect_left(xs, v)
            l, m, r = xs[i-1], xs[i], xs[i+1]
            iw.add((l-r, l, r))
            heapq.heappush(ws, (l - m, l, m))
            heapq.heappush(ws, (m - r, m, r))
            while ws[0] in iw:
                heapq.heappop(ws)
        else:
            bisect.insort(ys, v)
            i = bisect.bisect_left(ys, v)
            l, m, r = ys[i-1], ys[i], ys[i+1]
            ih.add((l-r, l, r))
            heapq.heappush(hs, (l - m, l, m))
            heapq.heappush(hs, (m - r, m, r))
            while hs[0] in ih:
                heapq.heappop(hs)
        w, h = ws[0], hs[0]
        ans.append(w[0] * h[0])
        
    return ans


W, H, N = map(int,input().split())
A = []
for i in range(N):
    a, b = input().split()
    c = 0 if a == 'V' else 1
    A.append((c, int(b)))

print('\n'.join(map(str, solve(W, H, N, A))))

w,h,n=map(int,input().split())
l=[-1]*(w+1)
r=[-1]*(w+1)
t=[-1]*(h+1)
b=[-1]*(h+1)

l[0]=0
b[0]=0
t[h]=h
r[w]=w


V=[0]*(n)
H=[0]*(n)
for i in range(n):
    line,index=input().split()
    index=int(index)
    if line=="V":
        r[index]=w
        V[i]=index
    else:
        t[index]=h
        H[i]=index
        
left=0
mxw=0
for i in range(1,w+1):
    if r[i]!=-1:
        l[i]=left
        r[left]=i
        mxw=max(mxw,i-left)
        left=i
        
bottom=0
mxh=0
for i in range(1,h+1):
    if t[i]!=-1:
        b[i]=bottom
        t[bottom]=i
        mxh=max(mxh,i-bottom)
        bottom=i
        
ans=[0]*(n)
ans[n-1]=mxh*mxw


for i in range(n-1,0,-1):
    if V[i]!=0:
        mxw=max(mxw,r[V[i]]-l[V[i]])
        r[l[V[i]]]=r[V[i]]
        l[r[V[i]]]=l[V[i]]
        
    else:
        mxh=max(mxh,t[H[i]]-b[H[i]])
        b[t[H[i]]]=b[H[i]]
        t[b[H[i]]]=t[H[i]]
    
    ans[i-1]=mxh*mxw

for i in range(n):
    print(ans[i])