There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.
Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).
Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:
 - If a_i = 1, he painted the region satisfying x < x_i within the rectangle.
 - If a_i = 2, he painted the region satisfying x > x_i within the rectangle.
 - If a_i = 3, he painted the region satisfying y < y_i within the rectangle.
 - If a_i = 4, he painted the region satisfying y > y_i within the rectangle.
Find the area of the white region within the rectangle after he finished painting.

-----Constraints-----
 - 1 ≦ W, H ≦ 100
 - 1 ≦ N ≦ 100
 - 0 ≦ x_i ≦ W (1 ≦ i ≦ N)
 - 0 ≦ y_i ≦ H (1 ≦ i ≦ N)
 - W, H (21:32, added), x_i and y_i are integers.
 - a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

-----Input-----
The input is given from Standard Input in the following format:
W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

-----Output-----
Print the area of the white region within the rectangle after Snuke finished painting.

-----Sample Input-----
5 4 2
2 1 1
3 3 4

-----Sample Output-----
9

The figure below shows the rectangle before Snuke starts painting.
First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:
Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:
Now, the area of the white region within the rectangle is 9.
[{"code": "def main():\n    w, h, n = list(map(int, input().split()))\n\n    x_min = 0\n    x_max = w\n    y_min = 0\n    y_max = h\n\n    for _ in range(n):\n        x, y, a = list(map(int, input().split()))\n        if a == 1:\n            x_min = max(x_min, x)\n        elif a == 2:\n            x_max = min(x_max, x)\n        elif a == 3:\n            y_min = max(y_min, y)\n        else:\n            y_max = min(y_max, y)\n\n    print((\n        (x_max - x_min) * (y_max - y_min)\n        if x_min < x_max and y_min < y_max else 0\n    ))\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 1.71, "memory": 14224.0, "status": "done"}, {"code": "W,H,N=map(int,input().split())\nA,B,C,D=[0],[W],[0],[H]\n\nfor i in range(N):\n    x,y,a=map(int,input().split())\n    if a==1:\n        A.append(x)\n    elif a==2:\n        B.append(x)\n    elif a==3:\n        C.append(y)\n    elif a==4:\n        D.append(y)\n\nW=min(B)-max(A)\nH=min(D)-max(C)\n\nif W<0 or H<0:\n    ans=0\nelse:\n    ans=H*W\nprint(ans)", "passed": true, "time": 0.15, "memory": 14152.0, "status": "done"}, {"code": "w,h,n=list(map(int,input().split()))\nxmin=0\nxmax=w\nymin=0\nymax=h\nfor i in range(n):\n    x,y,a=list(map(int,input().split()))\n    if a==1:\n        xmin=max(x,xmin)\n    elif a==2:\n        xmax=min(x,xmax)\n    elif a==3:\n        ymin=max(y,ymin)\n    else:\n        ymax=min(y,ymax)\nprint((max(0,xmax-xmin)*max(0,ymax-ymin)))\n\n", "passed": true, "time": 0.15, "memory": 14304.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nx1 = [0]\nx2 = [w]\ny1 = [0]\ny2 = [h]\n\nfor i in range(n):\n  x, y, a = map(int, input().split())\n  if a == 1:\n    x1.append(x)\n  elif a == 2:\n    x2.append(x)\n  elif a == 3:\n    y1.append(y)\n  elif a == 4:\n    y2.append(y)\n\nleft = max(x1)\nright = min(x2)\nbottom = max(y1)\ntop = min(y2)\n\nans =max(0, right - left)*max(0, top - bottom)\nprint(ans)", "passed": true, "time": 0.24, "memory": 14384.0, "status": "done"}, {"code": "# coding = SJIS\n\nw, h, n = map(int, input().split())\npoints = []\narea = [0, w, 0, h]\n\nfor i in range(n):\n    x, y, a = map(int, input().split())\n    points.append([x, y, a])\n\nfor i in range(n):\n    if points[i][2] == 1:\n        area[0] = max(area[0], points[i][0])\n    if points[i][2] == 2:\n        area[1] = min(area[1], points[i][0])\n    if points[i][2] == 3:\n        area[2] = max(area[2], points[i][1])\n    if points[i][2] == 4:\n        area[3] = min(area[3], points[i][1])\n\nans = max(0, (area[1] - area[0])) * max(0, (area[3] - area[2]))\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "W,H,N=map(int,input().split())\nl,r,b,t=0,W,0,H\nfor _ in range(N):\n    x,y,a=map(int,input().split())\n    if a==1:\n        l=max(l,x)\n    elif a==2:\n        r=min(r,x)\n    elif a==3:\n        b=max(b,y)\n    else:\n        t=min(t,y)\nif l<r and b<t:\n    print((r-l)*(t-b))\nelse:\n    print(0)", "passed": true, "time": 0.21, "memory": 14292.0, "status": "done"}, {"code": "w,h,n=map(int,input().split())\ns=0\nb=w\nt=0\nc=h\n\nfor i in range(n):\n  x,y,a=map(int,input().split())\n  if a==1:\n    s=max(s,x)\n  elif a==2:\n    b=min(b,x)\n  elif a==3:\n    t=max(t,y)\n  else:\n    c=min(c,y)\nif b>s and c>t:\n   print((b-s)*(c-t))\nelse:\n  print(0)", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "W,H,N = map(int,input().split())\na = []\nfor i in range(N):\n    b = list(map(int,input().split()))\n    a.append(b)\nxs = 0\nxe = W\nys = 0\nye = H\nfor i in range(N):\n    if a[i][2] == 1 and xs < a[i][0]:\n        xs = a[i][0]\n    elif a[i][2] == 2 and xe > a [i][0]:\n        xe = a[i][0]\n    elif a[i][2] == 3 and ys < a[i][1]:\n        ys = a[i][1]\n    elif a[i][2] == 4 and ye > a[i][1]:\n        ye = a[i][1]\nif xs < xe:\n    w = xe - xs\nelse:\n    w = 0\nif ys < ye:\n    h = ye - ys\nelse:\n    h = 0\nprint(w*h)", "passed": true, "time": 0.23, "memory": 14248.0, "status": "done"}, {"code": "w,h,n = map(int, input().split())\nx1 = [0] #1 left border of white area\nx2 = [w] #2\ny1 = [0] #3\ny2 = [h] #4\nfor i in range(n):\n  x,y,a = map (int, input().split())\n  if a == 1:\n    x1.append(x)\n  elif a == 2:\n    x2.append(x)\n  elif a == 3:\n    y1.append(y)\n  elif a ==4:\n    y2.append(y)\n\nleft = max(x1)\nright = min(x2)\nbottom = max(y1)\ntop = min(y2)\n\n\nans =max(0, right - left)*max(0, top - bottom)\n\nprint(ans)", "passed": true, "time": 0.19, "memory": 14364.0, "status": "done"}, {"code": "W, H, N  = map(int,input().split()) \nl = 0; r = W; u = H; d = 0 \n\nfor i in range(N):\n    x, y, a = map(int,input().split()) \n    if a == 1:\n        l = max(l,x) \n    elif a == 2:\n        r = min(r,x) \n    elif a == 3:\n        d = max(d,y) \n    else:\n        u = min(u,y) \n\nprint(max(0,(r-l))*max(u-d, 0)) ", "passed": true, "time": 0.2, "memory": 14124.0, "status": "done"}, {"code": "w, h, n = map(int,input().split())\nL = [list(map(int,input().split())) for i in range(n)]\nx1 = 0\nx2 = w\ny1 = 0\ny2 = h\nfor i in range(n):\n    if L[i][2] == 1:\n        x1 = max(L[i][0], x1)\n    if L[i][2] == 2:\n        x2 = min(L[i][0], x2)\n    if L[i][2] == 3:\n        y1 = max(L[i][1], y1)\n    if L[i][2] == 4:\n        y2 = min(L[i][1], y2)\n        \nans = 0\nif x2>=x1 and y2>=y1:\n    ans = (x2-x1)*(y2-y1)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14272.0, "status": "done"}, {"code": "w, h, n = list(map(int, input().split()))\nx_pos = [0, w]\ny_pos = [0, h]\nfor _ in range(n):\n    x, y, a = list(map(int, input().split()))\n    if a == 1:\n        x_pos[0] = max(x_pos[0], x)\n    elif a == 2:\n        x_pos[1] = min(x_pos[1], x)\n    elif a == 3:\n        y_pos[0] = max(y_pos[0], y)\n    else:\n        y_pos[1] = min(y_pos[1], y)\nans = max(0, (x_pos[1] - x_pos[0])) * max(0, (y_pos[1] - y_pos[0]))\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14232.0, "status": "done"}, {"code": "W, H, N = list(map(int, input().split()))\nbl_x, tr_x, bl_y, tr_y = 0, W, 0, H\nfor i in range(N):\n\tx, y, a = list(map(int, input().split()))\n\tif a == 1:\n\t\tbl_x = max(bl_x, x)\n\telif a == 2:\n\t\ttr_x = min(tr_x, x)\n\telif a == 3:\n\t\tbl_y = max(bl_y, y)\n\telif a == 4:\n\t\ttr_y = min(tr_y, y)\nprint((max(tr_x - bl_x, 0) * max(tr_y - bl_y, 0)))\n", "passed": true, "time": 0.15, "memory": 14108.0, "status": "done"}, {"code": "W, H, N = list(map(int, input().split()))\nX_Y_A = [list(map(int, input().split())) for _ in range(N)]\noX = 0\noY = 0\nfor x, y, a in X_Y_A:\n    if a == 1:\n        oX = max(x, oX)\n    elif a == 2:\n        W = min(x, W)\n    elif a == 3:\n        oY = max(y, oY)\n    else:\n        H = min(y, H)\n# print(W, oX, H, oY)\nprint((max(0, W-oX)*max(0, H-oY)))\n", "passed": true, "time": 0.15, "memory": 14320.0, "status": "done"}, {"code": "import math\nfrom math import gcd,pi,sqrt\nINF = float(\"inf\")\n\nimport sys\nsys.setrecursionlimit(10**6)\nimport itertools\nfrom collections import Counter,deque\ndef i_input(): return int(input())\ndef i_map(): return list(map(int, input().split()))\ndef i_list(): return list(i_map())\ndef i_row(N): return [i_input() for _ in range(N)]\ndef i_row_list(N): return [i_list() for _ in range(N)]\ndef s_input(): return input()\ndef s_map(): return input().split()\ndef s_list(): return list(s_map())\ndef s_row(N): return [s_input for _ in range(N)]\ndef s_row_str(N): return [s_list() for _ in range(N)]\ndef s_row_list(N): return [list(s_input()) for _ in range(N)]\n\n\ndef main():\n    w,h,n = i_map()\n\n    up = h\n    right = w\n    down = 0\n    left = 0\n\n    for i in range(n):\n        x,y,a = i_map()\n        if a == 1:\n            left = max(left,x)\n        elif a == 2:\n            right = min(right, x)\n        elif a == 3:\n            down = max(down, y)\n        else:\n            up = min(up, y)\n    print((max((up-down),0)*max((right-left),0)))\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14144.0, "status": "done"}, {"code": "import sys\nimput=sys.stdin.read\nw,h,n=map(int,input().split())\nt=[list(map(int,input().split())) for i in range(n)]\nsu=[]\nst=[]\nsv=[]\nsw=[]\nsux=svy=0\nstx=w\nswy=h\nfor j in range(n):\n    if t[j][2]==1:\n        su.append(t[j][0])\n        sux=max(su)\n    elif t[j][2]==2:\n        st.append(t[j][0])\n        stx=min(st)\n    elif t[j][2]==3:\n        sv.append(t[j][1])\n        svy=max(sv)\n    else:\n        sw.append(t[j][1])\n        swy=min(sw)\nif sux-stx>=0 or svy-swy>=0:\n    print(0)\nelse:\n    print((stx-sux)*(swy-svy))", "passed": true, "time": 0.15, "memory": 14164.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nxya = [list(map(int, input().split())) for _ in range(n)]\nx, y, a = zip(*xya)\nxl, xr, yb, yt = 0, w, 0, h\nfor i in range(n):\n    if   a[i] == 1: xl = max(xl, x[i])\n    elif a[i] == 2: xr = min(xr, x[i])\n    elif a[i] == 3: yb = max(yb, y[i])\n    else:           yt = min(yt, y[i])\nprint((xr-xl)*(yt-yb)*(xr>xl and yt>yb))", "passed": true, "time": 0.23, "memory": 14388.0, "status": "done"}, {"code": "lst = input().split()\n\nW = int(lst[0])\nH = int(lst[1])\nN = int(lst[2])\n\nfield = [([0] * W)] * H\n\nL = []\n\nfor i in range(N):\n   L = input().split()\n   if L[2] == '1':\n      for j in range(H):\n         for k in range(int(L[0])):\n            field[j][k] = 1\n   elif L[2] == '2':\n      for j in range(H):\n         for k in range(int(L[0]), W):\n            field[j][k] = 1\n   elif L[2] == '3':\n      for j in range(int(L[1])):\n         field[j] = [1] * W\n   elif L[2] == '4':\n      for j in range(int(L[1]), H):\n         field[j] = [1] * W\n\nans = 0\n\nfor s in field:\n   ans += s.count(0)\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14208.0, "status": "done"}, {"code": "import bisect,collections,copy,itertools,math,string\nimport sys\ndef I(): return int(sys.stdin.readline().rstrip())\ndef LI(): return list(map(int,sys.stdin.readline().rstrip().split()))\ndef S(): return sys.stdin.readline().rstrip()\ndef LS(): return list(sys.stdin.readline().rstrip().split())\ndef main():\n    w,h,n = LI()\n    board = [[1]*h for _ in range(w)]\n\n    for _ in range(n):\n        x,y,a = LI()\n        if a == 1:\n            for i in range(x):\n                board[i] = [0 for _ in range(h)]\n        elif a == 2:\n            for i in range(x,w):\n                board[i] = [0 for _ in range(h)]\n        elif a == 3:\n            for i in range(w):\n                for j in range(y):\n                    board[i][j] = 0\n        elif a == 4:\n            for i in range(w):\n                for j in range(y,h):\n                    board[i][j] = 0\n\n    ans = 0\n    for line in board:\n        ans += sum(line)\n\n    print(ans)\n\n    # print(*board,sep=\"\\n\")\nmain()            \n", "passed": true, "time": 0.15, "memory": 14204.0, "status": "done"}, {"code": "w,h,n=[int(i) for i in input().split()]\n#\u4e8c\u6b21\u5143\u914d\u5217\u306e\u4f5c\u6210\nlist_2d=[[0]*w for i in range(h)]\n\n\ndef nurie(x,y,a):\n   if a==1:\n       for i in range(h):\n           for j in range(x):\n               list_2d[i][j]=1\n   elif a==2:\n       for i in range(h):\n           for j in range(x,w):\n               list_2d[i][j]=1\n               \n\n   elif a==3:\n       for i in range(y):\n           for j in range(w):\n               list_2d[i][j]=1\n              \n   else:\n       for i in range(y,h):\n           for j in range(w):\n               list_2d[i][j]=1\n   return list_2d\n               \nfor i in range(n):\n   x,y,a=[int(i) for i in input().split()]\n   nurie(x,y,a)\n   \nsum=0\nfor i in range(h):\n   sum+=list_2d[i].count(0)\n   \nprint(sum)", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "w,h,n = map(int,input().split())\nx1 = 0\nx2 = w\ny1 = 0\ny2 = h\nfor i in range(n):\n  x,y,a = map(int,input().split())\n  if a == 1:\n    x1 = max(x1,x)\n  elif a == 2:\n    x2 = min(x2,x)\n  elif a == 3:\n    y1 = max(y1,y)\n  else:\n    y2 = min(y2,y)\nif x1 >= x2 or y1 >= y2:\n  print(0)\nelse:\n  print(w*h-h*(x1+w-x2)-(x2-x1)*(y1+h-y2))", "passed": true, "time": 0.14, "memory": 14108.0, "status": "done"}, {"code": "W,H,N = map(int,input().split())\nX=Y=0\n\n\nfor i in range(N):\n    x,y,a = map(int,input().split())\n    \n    if a==1:\n        X = max(X,x)\n       \n    elif a==2:\n        W = min(W,x)\n        \n    elif a==3:\n        Y = max(Y,y)\n    else:\n        H = min(H,y)\nprint(max(W-X,0)*max(H-Y,0))", "passed": true, "time": 0.14, "memory": 14136.0, "status": "done"}, {"code": "w, h, n = list(map(int, input().split()))\nr_w = w\nl_w = 0\nu_h = h\nd_h = 0\n\nfor i in range(n):\n    x, y, a = list(map(int, input().split()))\n    if a == 1:\n        l_w = max(l_w, x)\n    elif a == 2:\n        r_w = min(r_w, x)\n    elif a == 3:\n        d_h = max(d_h, y)\n    elif a == 4:\n        u_h = min(u_h, y)\n\nres = max(0, r_w - l_w) * max(0, u_h - d_h)\nprint(res)\n", "passed": true, "time": 0.15, "memory": 14116.0, "status": "done"}, {"code": "w,h,n = map(int,input().split())\ndata = list(input().split() for i in range(n))\nx_1 = 0\nx_2 = w\ny_1 = 0\ny_2 = h\nfor i in range(n):\n    if int(data[i][2]) == 1:\n        if int(data[i][0]) > x_1:\n            x_1 = int(data[i][0])\n    elif int(data[i][2]) == 2:\n        if int(data[i][0]) < x_2:\n            x_2 = int(data[i][0])\n    elif int(data[i][2]) == 3:\n        if int(data[i][1]) > y_1:\n            y_1 = int(data[i][1])\n    else:\n        if int(data[i][1]) < y_2:\n            y_2 = int(data[i][1])\nif x_2 - x_1 <= 0 or y_2 - y_1 <= 0:\n    print(0)\nelse:\n    print((x_2 - x_1) * (y_2 - y_1))", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "W,H,N=list(map(int,input().split()))\n\nans=[0,W,0,H]\n\nfor i in range(N):\n    x,y,a=list(map(int,input().split()))\n    if a==1:\n        if ans[0]<x:\n            ans[0]=x\n    elif a==2:\n        if ans[1]>x:\n            ans[1]=x\n    elif a==3:\n        if ans[2]<y:\n            ans[2]=y\n    else:\n        if ans[3]>y:\n            ans[3]=y\n\nS=(ans[1]-ans[0])*(ans[3]-ans[2])  \n\nif (ans[1]-ans[0])<0:\n    print((0))\nelif (ans[3]-ans[2])<0:\n    print((0))\nelse:\n    print(S)\n", "passed": true, "time": 0.14, "memory": 14112.0, "status": "done"}, {"code": "W, H, N  = map(int,input().split()) \nl = 0; r = W; u = H; d = 0 \n\nfor i in range(N):\n    x, y, a = map(int,input().split()) \n    if a == 1:\n        l = max(l,x) \n    elif a == 2:\n        r = min(r,x) \n    elif a == 3:\n        d = max(d,y) \n    else:\n        u = min(u,y) \n\nprint(max(0,(r-l))*max(u-d, 0)) ", "passed": true, "time": 0.14, "memory": 14224.0, "status": "done"}, {"code": "W, H, N = map(int, input().split())\nx, y, a = [0] * N, [0] * N, [0] * N\nfor i in range(N):\n    x[i], y[i], a[i] = map(int, input().split())\n    \nxmin = 0\nxmax = W\nymin = 0\nymax = H\n\nfor i in range(N):\n    if a[i] == 1:\n        xmin = max(x[i], xmin)\n    elif a[i] == 2:\n        xmax = min(x[i], xmax)\n    elif a[i] == 3:\n        ymin = max(y[i], ymin)\n    else:\n        ymax = min(y[i], ymax)\n\nheight = ymax - ymin\nwidth = xmax - xmin\n\nif height <= 0 or width <= 0:\n    print(0)\nelse:\n    print(height * width)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "W,H,N= list(map(int,input().split()))\nBlack = [[True for _ in range(W)] for i in range(H)]\nfor i in range(N):\n    x,y,a = list(map(int,input().split()))\n    for j in range(H):\n        for k in range(W):\n            if a == 1:\n                if k < x:\n                    Black[j][k] = False\n            elif a == 2:\n                if k >= x:\n                    Black[j][k] = False\n            elif a == 3:\n                if j < y:\n                    Black[j][k] = False\n            elif a == 4:\n                if j >= y:\n                    Black[j][k] = False\n                    #print(Black)\n\nc = 0\n#print(Black)\nfor i in range(H):\n    c += Black[i].count(True)\nprint(c)\n\n\n\n", "passed": true, "time": 0.14, "memory": 14164.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\n\nlist = [0, w, 0, h]\n\nfor i in range(n):\n    x, y, a = map(int, input().split())\n    if a == 1 and list[0] <= x:\n        list[0] = x\n    elif a == 2 and list[1] >= x:\n        list[1] = x\n    elif a == 3 and list[2] <= y:\n        list[2] = y\n    elif a == 4 and list[3] >= y:\n        list[3] = y\n    else:\n        pass\n\nif list[0] > list[1] or list[2] > list[3]:\n    print(0)\nelse:\n    print((list[0] - list[1]) * (list[2] - list[3]))", "passed": true, "time": 0.14, "memory": 14112.0, "status": "done"}, {"code": "w, h, n = list(map(int, input().split()))\nsw = 0\nsh = 0\nfor _ in range(n):\n    x, y, a = list(map(int, input().split()))\n    if a == 1:\n        sw = max(sw, x)\n    elif a == 2:\n        w = min(w, x)\n    elif a == 3:\n        sh = max(sh, y)\n    elif a == 4:\n        h = min(h, y)\nif sw < w and sh < h:\n    print(((w-sw) * (h-sh)))\nelse:\n    print((0))\n", "passed": true, "time": 0.14, "memory": 14160.0, "status": "done"}, {"code": "W, H, N = map(int, input().split())\narray = [list(map(int, input().split())) for i in range(N)]\n\nxmin = 0\nxmax = W\nymin = 0\nymax = H\nfor i in range(N):\n\n    if array[i][2] == 1:\n        xmin = max(xmin, array[i][0])\n    elif array[i][2] == 2:\n        xmax = min(xmax, array[i][0])\n    elif array[i][2] == 3:\n        ymin = max(ymin, array[i][1])\n    elif array[i][2] == 4:\n        ymax = min(ymax, array[i][1])\narea = (xmax-xmin)*(ymax-ymin)\nif area <= 0 or xmax < xmin or ymax < ymin:\n    print(0)\nelse:\n    print(area)", "passed": true, "time": 0.61, "memory": 14296.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\n\ndef main():\n    W, H, N = list(map(int, input().split()))\n    X = Y = 0\n    for i in range(N):\n        x, y, a = list(map(int, input().split()))\n        if a == 1:\n            X = max(X, x)\n        elif a == 2:\n            W = min(W, x)\n        elif a == 3:\n            Y = max(Y, y)\n        else:\n            H = min(H, y)\n    print((max(W - X, 0) * max(H - Y, 0)))\n\n\nmain()\n", "passed": true, "time": 0.18, "memory": 14100.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nr, l, u, d = w, 0, h, 0\nfor _ in range(n):\n    x, y, a = map(int, input().split())\n    if a == 1:\n        l = max(l, x)\n    elif a == 2:\n        r = min(r, x)\n    elif a == 3:\n        d = max(d, y)\n    else:\n        u = min(u, y)\nprint(max(0, r-l) * max(0, u-d))", "passed": true, "time": 0.15, "memory": 14252.0, "status": "done"}, {"code": "w,h,n=map(int,input().split())\nb=w\nc=h\nd=0\ne=0\nfor i in range(n):\n  x,y,a=map(int,input().split())\n  if a==1:\n    d=max(x,d)\n  elif a==2:\n    b=min(x,b)\n  elif a==3:\n    e=max(y,e)\n  elif a==4:\n    c=min(y,c)\nif b<d or c<e:\n  print(0)\nelse:\n  print((b-d)*(c-e))", "passed": true, "time": 0.14, "memory": 14312.0, "status": "done"}, {"code": "\nurl = \"https://atcoder.jp//contests/abc047/tasks/abc047_b\"\n\ndef main():\n    w, h, n = list(map(int, input().split()))\n    xya = [list(map(int, input().split())) for _ in range(n)]\n    x, y = [0, w], [0, h]\n    for low in xya:\n        if low[2] == 1 and x[0] < low[0]:\n            x[0] = low[0]\n        elif low[2] == 2 and x[1] > low[0]:\n            x[1] = low[0]\n        elif low[2] == 3 and y[0] < low[1]:\n            y[0] = low[1]\n        elif low[2] == 4 and y[1] > low[1]:\n            y[1] = low[1]\n    xs = x[1] - x[0]\n    ys = y[1] - y[0]\n    if xs < 0 or ys < 0:\n        print((0))\n    else:\n        ans = xs * ys\n        print(ans)\n\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.24, "memory": 14272.0, "status": "done"}, {"code": "w, h, n = list(map(int, input().split()))\n\nsx = [0, w]\nsy = [0, h]\n\nfor i in range(n):\n    x, y, a = list(map(int, input().split()))\n    if a == 1:\n        sx[0] = max(sx[0], x)\n    if a == 2:\n        sx[1] = min(sx[1], x)\n    if a == 3:\n        sy[0] = max(sy[0], y)\n    if a == 4:\n        sy[1] = min(sy[1], y)\n\nprint((max(0, max(0, (sx[1] - sx[0])) * max(0, (sy[1] - sy[0])))))\n", "passed": true, "time": 0.17, "memory": 14128.0, "status": "done"}, {"code": "W, H, N = [int(x) for x in input().split()]\n\nx_min = 0\nx_max = W\ny_min = 0\ny_max = H\n\nfor i in range(N):\n    x, y, a = [int(x) for x in input().split()]\n    if a == 1:\n        x_min = max(x_min, x)\n    elif a == 2:\n        x_max = min(x_max, x)\n    elif a == 3:\n        y_min = max(y_min, y)\n    else: # a == 4\n        y_max = min(y_max, y)\n\narea = max(0, x_max - x_min) * max(0, y_max - y_min)\n\nprint(area)", "passed": true, "time": 0.17, "memory": 14268.0, "status": "done"}, {"code": "whn = list(map(int, input().split()))\nw, h, n = whn[0], whn[1], whn[2]\nxyas = [list(map(int, input().split())) for _ in range(n)]\nc = [[1 for _ in range(h)] for _ in range(w)]\n# \u5857\u308a\u3064\u3076\u3055\u308c\u305f\u90e8\u5206\u30921\u306b\u3057\u3066\u3044\u304f\nfor xya in xyas:\n    x, y, a = xya[0], xya[1], xya[2]\n    if a == 1:\n        for i in range(x):\n            c[i] = [0 for _ in range(h)]\n    elif a == 2:\n        for i in range(x, w):\n            c[i] = [0 for _ in range(h)]\n    elif a == 3:\n        for i in range(w):\n            for j in range(y):\n                c[i][j] = 0\n    elif a == 4:\n        for i in range(w):\n            for j in range(y, h):\n                c[i][j] = 0\n\nprint((sum([sum(c2) for c2 in c])))\n", "passed": true, "time": 0.24, "memory": 14248.0, "status": "done"}, {"code": "W,H,N=list(map(int,input().split()))\n\n# \u5de6\u4e0b\u306e\u5ea7\u6a19\nX=Y=0\n\nfor i in range(N):\n  # \u5165\u529b\n  x,y,a=list(map(int,input().split()))\n\n  if a==1:\n    X=max(X,x)\n  elif a==2:\n    W=min(W,x)\n  elif a==3:\n    Y=max(Y,y)\n  else:\n    H=min(H,y)\n\n# \u51fa\u529b\nprint((max(W-X,0)*max(H-Y,0)))\n        \n", "passed": true, "time": 0.15, "memory": 14116.0, "status": "done"}, {"code": "w,h,n = map(int,input().split())\nchk = [0]*101\nwx = [1]*w\nwy = [1]*h\nfor _ in range(n):\n    x,y,a = map(int,input().split())\n    if a == 1:\n        wx[:x] = chk[:x]\n    elif a==2:\n        wx[x:] = chk[x+1:w-1]\n    elif a==3:\n        wy[:y] = chk[:y]\n    else:\n        wy[y:] = chk[y+1:h-1]\nws = wx.count(1)*wy.count(1)\n\nprint(ws)", "passed": true, "time": 0.14, "memory": 14068.0, "status": "done"}, {"code": "w,h,n = map(int,input().split())\nb,c,d,e = 0,w,0,h\nfor i in range(n):\n    x,y,a = map(int,input().split())\n    if a == 1:\n        b = max(b,x)\n    elif a == 2:\n        c = min(c,x)\n    elif a == 3:\n        d = max(d,y)\n    else:\n        e = min(e,y)\nprint(max(c-b,0)*max(e-d,0))", "passed": true, "time": 0.15, "memory": 14280.0, "status": "done"}, {"code": "w,h,n = list(map(int,input().split()))\nxl = []\nyl = []\nal = []\nfor _ in range(n):\n  x,y,a = list(map(int,input().split()))\n  xl.append(x)\n  yl.append(y)\n  al.append(a)\n\nsx = 0\ngx = w\nsy = 0\ngy = h\n\nfor i in range(len(al)):\n  if al[i] == 1 and sx < xl[i]:\n      sx = xl[i]\n      if sx > gx:\n        print((0))\n        return\n  elif al[i] == 2 and gx > xl[i]:\n      gx = xl[i]\n      if sx > gx:\n        print((0))\n        return\n  elif al[i] == 3 and sy < yl[i]:\n      sy = yl[i]\n      if sy > gy:\n        print((0))\n        return\n  elif al[i] == 4 and gy > yl[i]:\n      gy = yl[i]\n      if sy > gy:\n        print((0))\n        return\n  if i == len(al)-1:\n    print(((gx-sx)*(gy-sy)))\n    \n", "passed": true, "time": 0.15, "memory": 14196.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\np = [0]\nq = [w]\nr = [0]\ns = [h]\nfor i in range(n):\n    x, y, a = map(int, input().split())\n    if a == 1:\n        p.append(x)\n    elif a == 2:\n        q.append(x)\n    elif a == 3:\n        r.append(y)\n    else:\n        s.append(y)\nif max(p) <= min(q) and max(r) <= min(s):\n    print((min(q) - max(p))*(min(s) - max(r)))\nelse:\n    print(0)", "passed": true, "time": 0.23, "memory": 14268.0, "status": "done"}, {"code": "w,h,n=list(map(int,input().split()))\ni,j=0,0\nfor _ in range(n):\n    x,y,a=list(map(int,input().split()))\n    if a==1:\n        i=max(i,x)\n    elif a==2:\n        w=min(w,x)\n    elif a==3:\n        j=max(j,y)\n    else:\n        h=min(h,y)\nprint(((w-i)*(h-j) if w>i and h>j else 0))\n", "passed": true, "time": 0.14, "memory": 14116.0, "status": "done"}, {"code": "w, h, n = list(map(int, input().split()))\nplots = [list(map(int, input().split())) for _ in range(n)]\n\nw_min, w_max, h_min, h_max = 0, w, 0, h\n\nfor i in range(n):\n    if plots[i][2] == 1:\n        w_min = max(w_min, plots[i][0])\n    elif plots[i][2] == 2:\n        w_max = min(w_max, plots[i][0])\n    elif plots[i][2] == 3:\n        h_min = max(h_min, plots[i][1])\n    else:\n        h_max = min(h_max, plots[i][1])\n\nprint((max(0, (w_max - w_min)) * max(0, (h_max - h_min))))\n", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "w , h , n=map(int, input().split())\nW = [1]*w\nH = [1]*h\n\nfor i in range(n):\n    x,y,a=map(int, input().split())\n    if a == 1:\n        for i in range(x):\n            W[i] = 0\n    if a == 2 :\n        for i in range(x,w):\n            W[i] = 0\n    if a == 3:\n        for i in range(y):\n            H[i] = 0\n    if a == 4:\n        for i in range(y,h):\n            H[i] = 0\nprint(sum(W)*sum(H))", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "w,h,\uff4e = list(map(int, input().split()))\nans = [[0]*(w) for i in range(h)]\nfor i in range(n):\n  x,y,a = list(map(int, input().split()))\n  if a == 1:\n    for i in range(x):\n      for j in range(h):\n        ans[j][i] = 1\n  elif a == 2:\n    for i in range(x,w):\n      for j in range(h):\n        ans[j][i] = 1\n  elif a == 3:\n    for i in range(w):\n      for j in range(y):\n        ans[j][i] = 1\n  elif a == 4:\n    for i in range(w):\n      for j in range(y,h):\n        ans[j][i] = 1\n\ncnt = 0\nfor i in ans:\n  cnt += sum(i)\nprint((h*w - cnt))\n", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "num_line = input().split(\" \")\nx_num = int(num_line[0])\ny_num = int(num_line[1])\nnum = int(num_line[2])\n\ntangle = [[1]*x_num for i in range(y_num)]\n\n#print(tangle)\n\nfor i in range(num):\n    line = input().split(\" \")\n    x_tem = int(line[0])\n    y_tem = int(line[1])\n    index = int(line[2])\n    \n    if(index == 1):\n        for j in range(y_num):\n            for k in range(x_tem):\n                tangle[j][k] = 0\n        #print(tangle)            \n        \n    elif(index == 2):\n        for j in range(y_num):\n            for k in range(x_num - x_tem):\n                tangle[j][k + x_tem] = 0\n        #print(tangle)\n        \n    elif(index == 3):\n        for j in range(y_tem):\n            for k in range(x_num):\n                tangle[j][k] = 0\n        #print(tangle)\n        \n    else:\n        for j in range(y_num - y_tem):\n            for k in range(x_num):\n                tangle[j + y_tem][k] = 0\n        #print(tangle)\n        \nresult = 0\nfor i in range(y_num):\n    for j in range(x_num):\n        result += tangle[i][j]\n        \nprint(result)", "passed": true, "time": 0.14, "memory": 14132.0, "status": "done"}, {"code": "w, h, n = list(map(int, input().split()))\nans = [[0 for _ in range(w)] for _ in range(h)]\nfor i in range(n):\n    x, y, a = list(map(int, input().split()))\n    if a == 1:\n        for j in range(h):\n            ans[j][:x] = [1 for _ in range(x)]\n    if a == 2:\n        for j in range(h):\n            ans[j][x:] = [1 for _ in range(w-x)]\n    if a == 3:\n        for j in range(h-y,h):\n            ans[j] = [1 for _ in range(w)]\n    if a == 4:\n        for j in range(h-y):\n            ans[j] = [1 for _ in range(w)]\ncnt = 0\nfor k in ans:\n    cnt += k.count(0)\nprint(cnt)\n", "passed": true, "time": 0.15, "memory": 14188.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nl = [[0]*w for _ in range(h)]\ncount = 0\nfor _ in range(n):\n    x, y, a = map(int, input().split())\n    if a == 1:\n        for i in range(h):\n            for j in range(x):\n                if l[i][j] == 0:\n                    l[i][j] = 1\n                    count += 1\n    if a == 2:\n        for i in range(h):\n            for j in range(x,w):\n                if l[i][j] == 0:\n                    l[i][j] = 1\n                    count += 1\n    if a == 3:\n        for i in range(y):\n            for j in range(w):\n                if l[i][j] == 0:\n                    l[i][j] = 1\n                    count += 1\n    if a == 4:\n        for i in range(y,h):\n            for j in range(w):\n                if l[i][j] == 0:\n                    l[i][j] = 1\n                    count += 1\n\nprint(w*h - count)           ", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}, {"code": "w,h,n=list(map(int,input().split()))\nox,oy=0,0\nfor i in range(n):\n    x,y,a=list(map(int,input().split()))\n    if a==1:\n        if ox<x:\n            ox=x\n    elif a==2:\n        if w>x:\n            w=x\n    elif a==3:\n        if oy<y:\n            oy=y\n    else:\n        if h>y:\n            h=y\nprint((max(w-ox,0)*max(h-oy,0)))\n", "passed": true, "time": 0.15, "memory": 14120.0, "status": "done"}, {"code": "class Combination:\n    def __init__(self, n, mod):\n        self.n = n\n        self.mod = mod\n        self.fac = [1 for i in range(self.n + 1)]\n        self.finv = [1 for i in range(self.n + 1)]\n        for i in range(2, self.n+1):\n            self.fac[i] = (self.fac[i - 1] * i) % self.mod\n            self.finv[i] = (self.finv[i - 1] * pow(i, -1, self.mod)) % self.mod\n\n    def comb(self, n, m):\n        return self.fac[n] * (self.finv[n - m] * self.finv[m] % self.mod) % self.mod\n        \ndef iparse():\n    return list(map(int, input().split()))\n\n\ndef __starting_point():\n    w, h, n = iparse()\n    xmax = w\n    xmin = 0\n    ymin = 0\n    ymax = h\n    for i in range(n):\n        x, y, a = iparse()\n        \n        if a == 1:\n            xmin = max(xmin,x)\n        if a == 2:\n            xmax = min(xmax,x)\n        if a == 3:\n            ymin = max(ymin,y)\n        if a == 4:\n            ymax = min(ymax,y)\n        \n    print((max(xmax-xmin,0)*(max(0,ymax-ymin))))\n__starting_point()", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "w,h,n=map(int,input().split())\na=[[int(i)for i in input().split()]for j in range(n)]\nS=[[0,w],[0,h]]\nfor i in a:\n    if i[2]==1:\n        S[0][0]=max(i[0],S[0][0])\n\n    if i[2]==2:\n        S[0][1]=min(i[0],S[0][1])\n\n    if i[2]==3:\n        S[1][0]=max(i[1],S[1][0])\n\n    if i[2]==4:\n        S[1][1]=min(i[1],S[1][1])\n\nans=max(0,(S[0][1]-S[0][0]))*max(0,(S[1][1]-S[1][0]))\nprint(ans)", "passed": true, "time": 0.89, "memory": 14332.0, "status": "done"}, {"code": "W, H, N = [int(x) for x in input().split()]\nx_min, x_max, y_min, y_max = 0, W, 0, H\nnum_lists = [[int(x) for x in input().split()] for _ in range(N)]\n\nfor num_list in num_lists:\n    if num_list[2] == 1 and num_list[0] > x_min:\n        x_min = num_list[0]\n    if num_list[2] == 2 and num_list[0] < x_max:\n        x_max = num_list[0]\n    if num_list[2] == 3 and num_list[1] > y_min:\n        y_min = num_list[1]\n    if num_list[2] == 4 and num_list[1] < y_max:\n        y_max = num_list[1]\n\nif x_min > x_max or y_min > y_max:\n    print(0)\nelse:\n    print((x_max-x_min)*(y_max-y_min))", "passed": true, "time": 0.16, "memory": 14372.0, "status": "done"}, {"code": "from typing import List\n\n\ndef answer(w: int, h: int, n: int, xyas: List[List[int]]) -> int:\n    bottom_left_corner_of_white = {'x': 0, 'y': 0}\n    top_right_corner_of_white = {'x': w, 'y': h}\n\n    for xya in xyas:\n        x, y, a = xya\n        if a == 1:\n            if bottom_left_corner_of_white['x'] < x:\n                bottom_left_corner_of_white['x'] = x\n        if a == 2:\n            if x < top_right_corner_of_white['x']:\n                top_right_corner_of_white['x'] = x\n        if a == 3:\n            if bottom_left_corner_of_white['y'] < y:\n                bottom_left_corner_of_white['y'] = y\n        if a == 4:\n            if y < top_right_corner_of_white['y']:\n                top_right_corner_of_white['y'] = y\n\n    width_of_white = max(0, top_right_corner_of_white['x'] - bottom_left_corner_of_white['x'])\n    height_of_white = max(0, top_right_corner_of_white['y'] - bottom_left_corner_of_white['y'])\n\n    return width_of_white * height_of_white\n\n\ndef main():\n    w, h, n = map(int, input().split())\n    xyas = [list(map(int, input().split())) for _ in range(n)]\n    print(answer(w, h, n, xyas))\n\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.17, "memory": 15272.0, "status": "done"}, {"code": "w, h, n = list(map(int, input().split()))\n\ns_w = [0, w]\ns_h = [0, h]\nfor _ in range(n):\n    x, y, a = list(map(int, input().split()))\n    if a == 1 and x > s_w[0]:\n        s_w[0] = x\n    elif a == 2 and x < s_w[1]:\n        s_w[1] = x\n    elif a == 3 and y > s_h[0]:\n        s_h[0] = y\n    elif a == 4 and y < s_h[1]:\n        s_h[1] = y\n\nans_w = s_w[1] - s_w[0]\nans_h = s_h[1] - s_h[0]\nprint((ans_w * (ans_w > 0)) * (ans_h * (ans_h > 0)))", "passed": true, "time": 0.24, "memory": 14128.0, "status": "done"}, {"code": "import sys\nimport math\n\n\ninint = lambda: int(sys.stdin.readline())\ninintm = lambda: map(int, sys.stdin.readline().split())\ninintl = lambda: list(inintm())\ninstrm = lambda: map(str, sys.stdin.readline().split())\ninstrl = lambda: list(instrm())\n\n\nw, h, n = inintm()\n\nll = [0,0]\nrh = [w,h]\n\nfor i in range(n):\n    x, y, a = inintm()\n    if a == 1:\n        ll[0] = max(ll[0], x)\n    elif a == 2:\n        rh[0] = min(rh[0], x)\n    elif a == 3:\n        ll[1] = max(ll[1], y)\n    else:\n        rh[1] = min(rh[1], y)\n\nif rh[0]-ll[0] < 0 or rh[1]-ll[1] < 0:\n    print(0)\nelse:\n    print((rh[0]-ll[0])*(rh[1]-ll[1]))", "passed": true, "time": 0.96, "memory": 14124.0, "status": "done"}, {"code": "w,h,n = map(int, input().split())\nl,r,d,u = (0,w,0,h)\nfor i in range(n):\n  x,y,a = map(int, input().split())\n  if a == 1:\n    l = max(l,x)\n  elif a == 2:\n    r = min(r,x)\n  elif a == 3:\n    d = max(d,y)\n  else:\n    u = min(u,y)\nprint((r-l)*(u-d) if r>l and u>d else 0)", "passed": true, "time": 0.15, "memory": 14116.0, "status": "done"}, {"code": "import sys\n\ninput = sys.stdin.readline\n\ndef main():\n    W, H, N = list(map(int, input().split()))\n    X = [0, W]\n    Y = [0, H]\n    for i in range(N):\n        x, y, a = list(map(int, input().split()))\n        if a == 1:\n            X[0] = max(x, X[0])\n        elif a == 2:\n            X[1] = min(x, X[1])\n        elif a == 3:\n            Y[0] = max(y, Y[0])\n        else:\n            Y[1] = min(y, Y[1])\n    if X[1] <= X[0] or Y[1] <= Y[0]:\n        ans = 0\n    else:\n        ans = (X[1] - X[0]) * (Y[1] - Y[0])\n    print(ans)\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14208.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nright, left, lower, upper = 0, w, 0, h\nfor _ in range(n):\n    x, y, a = map(int, input().split())\n    if a == 1:\n        right = max(right, x)\n    if a == 2:\n        left = min(left, x)\n    if a == 3:\n        lower = max(lower, y)\n    if a == 4:\n        upper = min(upper, y)\n\na = left - right\nb = upper - lower\n\nif a <= 0 or b <= 0:\n    print(0)\nelse:\n    print(a*b)", "passed": true, "time": 0.89, "memory": 14136.0, "status": "done"}, {"code": "W,H,N = (int(T) for T in input().split())\nXYA = [[0],[W],[0],[H]]\nfor TN in range(0,N):\n    X,Y,A = (int(T) for T in input().split())\n    if A in [1,2]:\n        XYA[A-1].append(X)\n    else:\n        XYA[A-1].append(Y)\nCW = min(XYA[1])-max(XYA[0])\nCH = min(XYA[3])-max(XYA[2])\nif CW>=0 and CH>=0:\n    print(CW*CH)\nelse:\n    print(0)", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "#\n# abc047 b\n#\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n    def assertIO(self, input, output):\n        stdout, stdin = sys.stdout, sys.stdin\n        sys.stdout, sys.stdin = StringIO(), StringIO(input)\n        resolve()\n        sys.stdout.seek(0)\n        out = sys.stdout.read()[:-1]\n        sys.stdout, sys.stdin = stdout, stdin\n        self.assertEqual(out, output)\n\n    def test_\u5165\u529b\u4f8b_1(self):\n        input = \"\"\"5 4 2\n2 1 1\n3 3 4\"\"\"\n        output = \"\"\"9\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_2(self):\n        input = \"\"\"5 4 3\n2 1 1\n3 3 4\n1 4 2\"\"\"\n        output = \"\"\"0\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_3(self):\n        input = \"\"\"10 10 5\n1 6 1\n4 1 3\n6 9 4\n9 4 2\n3 1 3\"\"\"\n        output = \"\"\"64\"\"\"\n        self.assertIO(input, output)\n\n\ndef resolve():\n    W, H, N = list(map(int, input().split()))\n    a = []\n    ox = 0\n    oy = 0\n    for _ in range(N):\n        a.append(list(map(int, input().split())))\n    for i in range(N):\n        if a[i][2] == 1:\n            ox = max(a[i][0], ox)\n        elif a[i][2] == 2:\n            W = min(a[i][0], W)\n        elif a[i][2] == 3:\n            oy = max(a[i][1], oy)\n        elif a[i][2] == 4:\n            H = min(a[i][1], H)\n    print((max(W-ox, 0)*max(H-oy, 0)))\n\n\ndef __starting_point():\n    # unittest.main()\n    resolve()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14480.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nx_pos = [0, w]\ny_pos = [0, h]\nfor _ in range(n):\n    x, y, a = map(int, input().split())\n    if a == 1:\n        x_pos[0] = max(x_pos[0], x)\n    elif a == 2:\n        x_pos[1] = min(x_pos[1], x)\n    elif a == 3:\n        y_pos[0] = max(y_pos[0], y)\n    else:\n        y_pos[1] = min(y_pos[1], y)\nif x_pos[1] - x_pos[0] < 0 or y_pos[1] - y_pos[0] < 0:\n    ans = 0\nelse:\n    ans = (x_pos[1] - x_pos[0] ) * (y_pos[1] - y_pos[0])\nprint(ans)", "passed": true, "time": 0.15, "memory": 14216.0, "status": "done"}, {"code": "W,H,N=map(int, input().split())\nX=[0,W]\nY=[0,H]\n\nfor i in range(N):\n    x,y,a = map(int, input().split())\n    if a==1:\n        X[0]=max(x, X[0])\n    elif a==2:\n        X[1]=min(x, X[1])\n    elif a==3:\n        Y[0]=max(y, Y[0])\n    else:\n        Y[1]=min(y, Y[1])\n\nif X[1]-X[0]<=0 or Y[1]-Y[0]<=0:\n    area=0\nelse:\n    area = max(0,(X[1]-X[0])*(Y[1]-Y[0]))\nprint(area)", "passed": true, "time": 0.14, "memory": 14112.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nb = [0, 0]\nc = [w, h]\nfor _ in range(n):\n    x, y, a = map(int, input().split())\n    if a == 1:\n        if b[0] < x:\n            b[0] = x\n    elif a == 2:\n        if c[0] > x:\n            c[0] = x\n    elif a == 3:\n        if b[1] < y:\n            b[1] = y\n    else:\n        if c[1] > y:\n            c[1] = y\nd = max(0, (c[0] - b[0])) * max(0, (c[1] - b[1]))\nprint(d)", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "W, H, N = map(int, input().split())\nu, U, v, V = 0, W, 0, H\nfor _ in range(N):\n    x, y, a = map(int,input().split())\n    if a == 1:\n        u = max(u,x)\n    if a == 2:\n        U = min(U,x)\n    if a == 3:\n        v = max(v,y)\n    if a == 4:\n        V = min(V,y)\nf = lambda x:x if x > 0 else 0\nprint(f(U-u)*f(V-v))", "passed": true, "time": 0.15, "memory": 14204.0, "status": "done"}, {"code": "W,H,N = map(int,input().split())\n\na1,a2,a3,a4 = -1,101,-1,101\nfor i in range(N):\n  x,y,a = map(int,input().split())\n  if a == 1:\n    a1 = max(a1,x)\n  elif a == 2:\n    a2 = min(a2,x-1)\n  elif a == 3:\n    a3 = max(a3,y)\n  else:\n    a4 = min(a4,y-1)\n    \nmass = [[0 for _ in range(W)] for _ in range(H)]\nfor i in range(H):\n  for j in range(W):\n    if i < a3 or a4 < i:\n      mass[i][j] += 1\n    if j < a1 or a2 < j:\n      mass[i][j] += 1\n      \ncnt = 0\nfor k in mass:\n  cnt += k.count(0)\n  \nprint(cnt)", "passed": true, "time": 0.17, "memory": 14280.0, "status": "done"}, {"code": "W,H,N=map(int,input().split())\nvalues=[[0],[W],[0],[H]]\nfor i in range(N):\n  x,y,a=(map(int,input().split()))\n  if a<=2:\n    values[a-1].append(x)\n  elif a>=3:\n    values[a-1].append(y)\nprint(max(0,min(values[1])-max(values[0]))*max(0,min(values[3])-max(values[2])))", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "w, h, n = map(int,input().split())\n\nxl, xr = 0, w\nyl, yu = 0, h\nfor i in range(n):\n    x, y, a = map(int,input().split())\n    if a == 1:\n        xl = max(xl, x)\n    elif a == 2:\n        xr = min(xr, x)\n    elif a == 3:\n        yl = max(yl, y)\n    else:\n        yu = min(yu, y)\n        \nprint((xr-xl)*(yu-yl)) if xl < xr and yl < yu else print(0)", "passed": true, "time": 0.14, "memory": 14128.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\n\nx = [0] * n\ny = [0] * n\na = [0] * n\n\nfor i in range(n):\n    x[i], y[i], a[i] = map(int, input().split())\n\nw_l = 0\nh_l = 0\nfor i in range(n):\n    if a[i] == 1:\n        if w_l < x[i]:\n            w_l = x[i]\n    elif a[i] == 2:\n        if w > x[i]:\n            w = x[i]\n    elif a[i] == 3:\n        if h_l < y[i]:\n            h_l = y[i]\n    elif a[i] == 4:\n        if h > y[i]:\n            h = y[i]\nW = w - w_l\nH = h - h_l\nif W < 0 or H < 0:\n    ans = 0\nelse:\n    ans = W * H\nprint(ans)", "passed": true, "time": 0.14, "memory": 14152.0, "status": "done"}, {"code": "H,W,N=map(int,input().split())\nsita,hidari=0,0\nue,migi=W,H\nfor i in range(N):\n  x,y,a=map(int,input().split())\n  if a==1:\n    hidari=max(x,hidari)\n  elif a==2:\n    migi=min(migi,x)\n  elif a==3:\n    sita=max(sita,y)\n  else:\n    ue=min(ue,y)\nprint(max(0,(migi-hidari))*max(0,(ue-sita)))", "passed": true, "time": 0.15, "memory": 14256.0, "status": "done"}, {"code": "W, H, N = map(int, input().split())\nxya = [list(map(int, input().split())) for i in range(N)]\nX=Y=0\nfor i in range(N):\n    if xya[i][2] == 1:\n        X = max(X,xya[i][0])\n    if xya[i][2] == 2:\n        W = min(W,xya[i][0])\n    if xya[i][2] == 3:\n        Y = max(Y,xya[i][1])\n    if xya[i][2] == 4:\n        H = min(H,xya[i][1])\nprint(max(W-X,0)*max(H-Y,0))", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "def main():\n    W,H,N = list(map(int,input().split()))\n    X = 0 #a=1\u521d\u671f\u5024\n    Y = 0 #a=3\u521d\u671f\u5024\n    for _ in range(N):\n        x,y,a = list(map(int,input().split()))\n        if a == 1:\n            X = max(X,x)\n        elif a == 2:\n            W = min(W,x)\n        elif a == 3:\n            Y = max(Y,y)\n        elif a == 4:\n            H = min(H,y)\n    #S\u3092\u6c42\u3081\u308b\n    S = max((W-X),0) * max((H-Y),0)\n    print(S)\ndef __starting_point():\n    main()\n\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14100.0, "status": "done"}, {"code": "w,h,n = map(int, input().split())\ns = [[1 for i in range(w)] for j in range(h)]\nb = [[1,2,3,4,5],[6,7,8,9,10]]\nalist = []\nfor i in range(n):\n    x,y,a = map(int, input().split())\n    alist.append(a)\n    if a == 1:\n        for j in range(h):\n            for k in range(0,x):\n                s[j][k] = 0\n    if a == 2:\n        for j in range(h):\n            for k in range(x,w):\n                s[j][k] = 0\n    if a == 3:\n        for k in range(w):\n            for j in range(0,y):\n                s[j][k] = 0\n    if a == 4:\n        for k in range(w):\n            for j in range(y,h):\n                s[j][k] = 0\nans = 0\nfor i in range(h):\n    ans = ans + s[i].count(1)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14376.0, "status": "done"}, {"code": "W, H, N = map(int, input().split())\nx = []\ny = []\na = []\nX = [1]*W\nY = [1]*H\nans = 0\nfor _ in range(N):\n    i, j, k = map(int, input().split())\n    x.append(i)\n    y.append(j)\n    a.append(k)\nfor i in range(N):\n    if a[i] == 1:\n        for j in range(x[i]):\n            X[j] = 0\n    elif a[i] == 2:\n        for j in range(x[i], W):\n            X[j] = 0\n    elif a[i] == 3:\n        for j in range(y[i]):\n            Y[j] = 0\n    else:\n        for j in range(y[i], H):\n            Y[j] = 0\nfor i in range(H):\n    for j in range(W):\n        if X[j] and Y[i]:\n            ans += 1\nprint(ans)", "passed": true, "time": 0.14, "memory": 14116.0, "status": "done"}, {"code": "X, Y, N = list(map(int, input().split()))\nlst = [[0 for i in range(X)] for j in range(Y)]\n\nfor i in (list(range(N))):\n    x, y, a = list(map(int, input().split()))\n    if a == 1:\n        for j in range(Y):\n            for k in range(x):\n                lst[j][k] = 1\n    elif a == 2:\n        for j in range(Y):\n            for k in range(X-1, x-1, -1):\n                lst[j][k] = 1\n    elif a == 3:\n        for j in range(y):\n            for k in range(X):\n                lst[j][k] = 1\n    elif a == 4:\n        for j in range(Y-1, y-1, -1):\n            for k in range(X):\n                lst[j][k] = 1\n\ncount = 0\nfor i in lst:\n    count += i.count(0)\nprint(count)\n\n", "passed": true, "time": 0.14, "memory": 14084.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\n\ndef read():\n    W, H, N = list(map(int, input().strip().split()))\n    XYA = []\n    for i in range(N):\n        x, y, a = list(map(int, input().strip().split()))\n        XYA.append((x, y, a))\n    return W, H, N, XYA\n\n\ndef solve(W, H, N, XYA):\n    S = [[0 for j in range(W+1)] for i in range(H+1)]\n    for x, y, a in XYA:\n        if a == 1:\n            lt, rt, lb, rb = (0, 0), (x, 0), (0, H), (x, H)\n        elif a == 2:\n            lt, rt, lb, rb = (x, 0), (W, 0), (x, H), (W, H)\n        elif a == 3:\n            lt, rt, lb, rb = (0, 0), (W, 0), (0, y), (W, y)\n        elif a == 4:\n            lt, rt, lb, rb = (0, y), (W, y), (0, H), (W, H)\n        S[lt[1]][lt[0]] += 1\n        S[rt[1]][rt[0]] -= 1\n        S[lb[1]][lb[0]] -= 1\n        S[rb[1]][rb[0]] += 1\n    \n    for i in range(H):\n        for j in range(W+1):\n            S[i+1][j] += S[i][j]\n    for i in range(H+1):\n        for j in range(W):\n            S[i][j+1] += S[i][j]\n    \n    ans = 0\n    for i in range(H):\n        for j in range(W):\n            if S[i][j] == 0:\n                ans += 1\n    return ans\n\n\ndef __starting_point():\n    inputs = read()\n    print((solve(*inputs)))\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nl, r, t, b = 0, w, h, 0\nfor i in range(n):\n  x, y, a = map(int, input().split())\n  if a == 1:\n    l = max(x, l)\n  elif a == 2:\n    r = min(x, r)\n  elif a == 3:\n    b = max(y, b)\n  else:\n    t = min(y, t)\nif (r - l) <= 0 or (t - b) <= 0:\n  print(0)\nelse:\n  print((r - l) * (t - b))", "passed": true, "time": 0.14, "memory": 14136.0, "status": "done"}, {"code": "w,h,n=map(int,input().split())\nansw=set(range(w+1)) \nansh=set(range(w+1))\nfor i in range(n):\n  x,y,a=map(int,input().split())\n  if a==1:\n    answ=answ & set(range(x,w+1))\n  elif a==2:\n    answ=answ & set(range(x+1))\n  elif a==3:\n    ansh=ansh & set(range(y,h+1))\n  elif a==4:\n    ansh=ansh & set(range(y+1))\nif len(answ) == 0 or len(ansh)==0:\n  print(0)\nelse:\n  print((max(answ)-min(answ))*(max(ansh)-min(ansh)))", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "w,h,n = [int(x) for x in input().split()]\na = []\nfor i in range(n):\n  a.append([int(x) for x in input().split()])\n\nmp = [[0] * h for x in range(w)]\n\nfor i in range(n):\n  if a[i][2] == 1:\n    for j in range(a[i][0]):\n      for k in range(h):\n        mp[j][k] = 1\n  elif a[i][2] == 2:\n    for j in range(a[i][0],w):\n      for k in range(h):\n        mp[j][k] = 1\n  elif a[i][2] == 3:\n    for j in range(w):\n      for k in range(a[i][1]):\n        mp[j][k] = 1\n  elif a[i][2] == 4:\n    for j in range(w):\n      for k in range(a[i][1],h):\n        mp[j][k] = 1\n\nres = 0\nfor i in range(w):\n  for j in range(h):\n    if mp[i][j] == 0:\n      res += 1\n\nprint(res)", "passed": true, "time": 0.23, "memory": 14252.0, "status": "done"}, {"code": "W, H, N = list(map(int, input().split()))\ninput_list = []\nfor i in range(N):\n  input_list.append(list(map(int, input().split())))\n\npoint_list = []\nfor h in range(H):\n  list_ = []\n  for w in range(W):\n    list_.append(1)\n  point_list.append(list_)\n\nfor input_ in input_list:\n  x, y, a = input_\n  if a == 1:\n    for h in range(H):\n      for i in range(x):\n        point_list[h][i] = 0\n  if a == 2:\n    for h in range(H):\n      for i in range(x, W):\n        point_list[h][i] = 0\n  if a == 3:\n    for i in range(y):\n      for w in range(W):\n        point_list[i][w] = 0\n  if a == 4:\n    for i in range(y, H):\n      for w in range(W):\n        point_list[i][w] = 0\n\nans = sum([sum(point) for point in point_list])\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "import sys, math\nfrom itertools import combinations as c, product as p\nfrom collections import deque\nsys.setrecursionlimit(10**9)\n\n\ndef si(): return input()\ndef ii(): return int(input())\ndef fi(): return float(input())\ndef lint(): return list(map(int, input().split()))\ndef lint_dec(): return list(map(lambda x:int(x) - 1, input().split()))\ndef lnstr(n): return [input() for _ in range(n)]\ndef lnint(n): return [int(input()) for _ in range(n)]\ndef lint_list(n): return [lint() for _ in range(n)]\n\n\n\n############################################################\nW, H, N = lint()\nqueue = lint_list(N)\n\nxmin = max([x for x, y, a in queue if a == 1] + [0])\nxmax = min([x for x, y, a in queue if a == 2] + [W])\nymin = max([y for x, y, a in queue if a == 3] + [0])\nymax = min([y for x, y, a in queue if a == 4] + [H])\n\nprint(max(0, xmax - xmin) * max(0, ymax - ymin))", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "W,H,N=list(map(int,input().split()))\nwhite=[[1 for _ in range(H)] for _ in range(W)]\n\nfor i in range(N):\n    x,y,a=list(map(int,input().split()))\n    if a==1:\n        for i in range(x):\n            for j in range(H):\n                white[i][j]=0\n    elif a==2:\n        for i in range(x,W):\n            for j in range(H):\n                white[i][j]=0\n    elif a==3:\n        for i in range(W):\n            for j in range(y):\n                white[i][j]=0\n    else:\n        for i in range(W):\n            for j in range(y,H):\n                white[i][j]=0\nprint((sum(sum(x) for x in white)))\n", "passed": true, "time": 0.2, "memory": 14136.0, "status": "done"}, {"code": "W, H, N = list(map(int, input().split()))\n\nmax_x = 0\nmax_y = 0\nmin_x = W\nmin_y = H\nfor i in range(N):\n    x, y, a = list(map(int, input().split()))\n    if a == 1:\n        max_x = max(max_x, x)\n    elif a == 2:\n        min_x = min(min_x, x)\n    elif a == 3:\n        max_y = max(max_y, y)\n    else:\n        min_y = min(min_y, y)\n\n# print(max_x, max_y)\n# print(min_x, min_y)\nif(min_x > max_x) and (min_y > max_y):\n    print(((min_x - max_x) * (min_y - max_y)))\nelse:\n    print((0))\n", "passed": true, "time": 0.14, "memory": 14144.0, "status": "done"}, {"code": "W, H, N = list(map(int, input().split()))\nX = []\nY = []\nA = []\nfield = [[0] * W for _ in range(H)]\nfor i in range(N):\n    x, y, a = list(map(int, input().split()))\n    X.append(x)\n    Y.append(y)\n    A.append(a)\n\nfor i in range(N):\n    if A[i] == 1:\n        for j in range(X[i]):\n            for k in range(H):\n                field[k][j] = 1\n    elif A[i] == 2:\n        for j in range(X[i], W):\n            for k in range(H):\n                field[k][j] = 1\n    elif A[i] == 3:\n        for j in range(W):\n            for k in range(Y[i]):\n                field[k][j] = 1\n    else:\n        for j in range(W):\n            for k in range(Y[i], H):\n                field[k][j] = 1\n\nSum = 0\nfor i in range(W):\n    for j in range(H):\n        if field[j][i] == 0:\n            Sum += 1\n\nprint(Sum)\n", "passed": true, "time": 0.14, "memory": 14200.0, "status": "done"}, {"code": "w,h,n=map(int,input().split())\na=[[int(i) for i in input().split()] for i in range(n)]\n \nx,y=0,0\nfor s,t,u in a:\n    if u==1:\n        x=max(x,s)\n    elif u==2:\n        w=min(w,s)\n    elif u==3:\n        y=max(y,t)\n    else:\n        h=min(h,t)\nheight=max(0,h-y)\nwidth=max(0,w-x)\nprint(height*width)", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "w,h,n=list(map(int, input().split())) #\u521d\u671f\u5024\nlx=0\nly=0\nrx=w\nry=h\n\nfor i in range(n):\n   x,y,a=list(map(int, input().split()))\n   \n   if a==1:\n       if lx<x:\n           lx=x\n   elif a==2:\n       if rx>x:\n           rx=x\n           \n   elif a==3:\n       if ly<y:\n           ly=y\n   \n   else:\n       if ry>y:\n           ry=y\n# \u51fa\u529b\nprint((max(rx-lx,0)*max(ry-ly,0)))\n", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\nW, H, N = list(map(int, input().split()))\nxs = ys = 0\nxe = W\nye = H\nfor i in range(N):\n    x, y, a = list(map(int, input().split()))\n    if a == 1 and x > xs:\n        xs = x\n    elif a == 2 and x < xe:\n        xe = x\n    elif a == 3 and y > ys:\n        ys = y\n    elif a == 4 and y < ye:\n        ye = y\n\nw = xe - xs\nh = ye - ys\nif w > 0 and h > 0:\n    ans = w * h\nelse:\n    ans = 0\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14160.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nx, y, a = [], [], []\nfor i in range(n):\n    X, Y, A = map(int, input().split())\n    x.append(X)\n    y.append(Y)\n    a.append(A)\nzahyou = [[1 for _ in range(h)] for __ in range(w)]\n\ndef m1(d):\n    for i in range(d):\n        for j in range(h):\n            zahyou[i][j] = 0\n\ndef m2(d):\n    for i in range(w-d):\n        for j in range(h):\n            zahyou[i+d][j] = 0\n\ndef m3(d):\n    for i in range(w):\n        for j in range(d):\n            zahyou[i][j] = 0\n\ndef m4(d):\n    for i in range(w):\n        for j in range(h-d):\n            zahyou[i][j+d] = 0\n\nfor i in range(n):\n    if a[i] == 1:\n        m1(x[i])\n    elif a[i] == 2:\n        m2(x[i])\n    elif a[i] == 3:\n        m3(y[i])\n    else:\n        m4(y[i])\n\nprint(sum(map(sum,zahyou)))", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nW = [1] * w\nH = [1] * h\n\nfor i in range(n):\n    x, y, a = map(int, input().split())\n    if a == 1:\n        for j in range(x):\n            W[j] = 0\n    elif a == 2:\n        for j in range(x, w):\n            W[j] = 0\n    elif a == 3:\n        for j in range(y):\n            H[j] = 0\n    elif a == 4:\n        for j in range(y, h):\n            H[j] = 0\nprint(sum(W) * sum(H))", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "w, h, n = map(int, input().split())\nquery = [tuple(map(int, input().split())) for _ in range(n)]\n\nsx, sy = 0, 0\nfor x, y, a in query:\n    if a == 1:\n        sx = max(sx, x)\n    elif a == 2:\n        w = min(w, x)\n    elif a == 3:\n        sy = max(sy, y)\n    else:\n        h = min(h, y)\nprint(max(0, w - sx) * max(0, h - sy))", "passed": true, "time": 0.14, "memory": 14096.0, "status": "done"}]