Problem:
Score : 200 points

Problem Statement

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 1

5 4 2
2 1 1
3 3 4

Sample Output 1

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.

Sample Input 2

5 4 3
2 1 1
3 3 4
1 4 2

Sample Output 2

0

It is possible that the whole region within the rectangle is painted black.

Sample Input 3

10 10 5
1 6 1
4 1 3
6 9 4
9 4 2
3 1 3

Sample Output 3

64

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

// All Library
// #include <bits/stdc++.h> // https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/precompiled/stdc%2B%2B.h

// C Library
// #include <cassert> // (assert.h) C Diagnostics Library (header)
// #include <cctype> // (ctype.h) Character handling functions (header)
// #include <cerrno> // (errno.h) C Errors (header)
// #include <cfloat> // (float.h) Characteristics of floating-point types (header)
// #include <ciso646> // (iso646.h) ISO 646 Alternative operator spellings (header)
// #include <climits> // (limits.h) Sizes of integral types (header)
// #include <clocale> // (locale.h) C localization library (header)
// #include <cmath> // (math.h) C numerics library (header)
// #include <csetjmp> // (setjmp.h) Non local jumps (header)
// #include <csignal> // (signal.h) C library to handle signals (header)
// #include <cstdarg> // (stdarg.h) Variable arguments handling (header)
// #include <cstdbool> // (stdbool.h) Boolean type (header)
// #include <cstddef> // (stddef.h) C Standard definitions (header)
// #include <cstdint> // (stdint.h) Integer types (header)
#include <cstdio> // (stdio.h) C library to perform Input/Output operations (header)
// #include <cstdlib> // (stdlib.h) C Standard General Utilities Library (header)
// #include <cstring> // (string.h) C Strings (header)
// #include <ctime> // (time.h) C Time Library (header)
// #include <cuchar> // (uchar.h) Unicode characters (header)
// #include <cwchar> // (wchar.h) Wide characters (header)
// #include <cwctype> // (wctype.h) Wide character type (header)

// Containers
// #include <array> // Array header (header)
// #include <bitset> // Bitset header (header)
#include <deque> // Deque header (header)
// #include <forward_list> // Forward list (header)
// #include <list> // List header (header)
#include <map> // Map header (header)
// #include <queue> // Queue header (header)
#include <set> // Set header (header)
// #include <stack> // Stack header (header)
// #include <unordered_map> //Unordered map header (header)
// #include <unordered_set> // Unordered set header (header)
#include <vector> // Vector header (header)

// Input/Output Stream Library
#include <iostream> // The class relies on a single streambuf object for both the input and output operations.
// #include <fstream> // Input/output stream class to operate on files.
// #include <sstream> //

// Miscellaneous headers
#include <algorithm> // Standard Template Library: Algorithms (library )
// #include <chrono> // Time library (header)
// #include <codecvt> // Unicode conversion facets (header)
// #include <complex> // Complex numbers library (header)
// #include <exception> // Standard exceptions (header)
// #include <functional> // Function objects (header)
// #include <initializer_list> // Initializer list (header)
// #include <iterator> // Iterator definitions (header)
// #include <limits> // Numeric limits (header)
// #include <locale> // Localization library (header)
// #include <memory> //Memory elements (header)
// #include <new> // Dynamic memory (header)
// #include <numeric> // Generalized numeric operations (header)
// #include <random> // Random (header)
// #include <ratio> // Ratio header (header)
// #include <regex> // Regular Expressions (header)
// #include <stdexcept> // Exception classes (header)
#include <string> // Strings (header)
// #include <system_error> // System errors (header)
#include <tuple> // Tuple library (header)
// #include <typeinfo> // Type information (header)
// #include <type_traits> //type_traits (header)
// #include <utility> // Utility components (header)
// #include <valarray> // Library for arrays of numeric values (header)

// Boost
// #include <boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace boost::multiprecision;

#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for((I)=0;(I)<(N);(I)++)
#define up(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define dw(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                             in(T &p){cin>>p;}
template<class T1,class T2>inline void                   in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void          in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}

// 【WIP】
// class fast_io{
// private:
// public:
//   void in(long&&... params){}
//   void out(){}
// };
// #define mygc(c) (c)=getchar_unlocked()
// #define mypc(c) putchar_unlocked(c)
// int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t') break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t') break;c[s++]=i;}return s;}
// void reader(int *x){int k,m=0;*x=0;for(;;){k=getchar_unlocked();if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){k=getchar_unlocked();if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
// void reader(char x[], int len){int i,k;if(len==0)return;for(;;){mygc(k);if(!(k==' '||k=='\n'||k=='\t'||k=='\r')){x[0]=k;break;}}REP(i,1,len)mygc(x[i]);}
// void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
// void writer(int x, char c){int i,sz=0,m=0;char buf[10];if(x<0)m=1,x=-x;while(x)buf[sz++]=x%10,x/=10;if(!sz)buf[sz++]=0;if(m)putchar_unlocked('-');while(sz--)putchar_unlocked(buf[sz]+'0');putchar_unlocked(c);}
// void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)putchar_unlocked(c[i]);}
// void writer(const char c[], int len){int i;rep(i,len)putchar_unlocked(c[i]);}

// 【WIP】
// class mod_int{
// public:
//   long n,MOD;
//   mod_int():MOD((long)1e9+7){}
//   // modint(int a) { x = a % mod; if (x < 0) x += mod; }
//   mod_int(T MOD){this->MOD=MOD;}
//   mod_int &operator+=(mod_int that){n=(n+that.n)%MOD;return *this;}
//   mod_int &operator-=(mod_int that){n=(n+MOD-that.n)%MOD;return *this;}
//   mod_int &operator*=(mod_int that){n=(long)n*that.n%MOD;return *this;}
//   mod_int &operator/=(mod_int that){return *this*=that.inverse();}
//   mod_int operator-(){return mod_int(-this->n);}
//   friend ostream& operator<<(ostream &out,mod_int m){return out<<m.n;}
//   mod_int inverse(){
//     long a=n,b=MOD,u=1,v=0;
//     while(b){int t=a/b;a-=t*b;u-=t*v;swap(a,b);swap(u,v);}
//     return mod_int(u);
//   }
// #define op(o,p) mod_int operator o(mod_int that){return mod_int(*this) p that;}
//   op(+,+=) op(-,-=) op(*,*=) op(/,/=)
// #undef op
// #define op(o) bool operator o(mod_int that)const{return n o that.n;}
//   op(==) op(!=) op(<) op(<=) op(>) op(>=)
// #undef op
// };

int w,h,n,l,r,d,u,x,y,a,i;
inline void solve(void){
  in(w,h,n);
  r=w,u=h;
  rep(i,n){
    in(x,y,a);
    if(a==1)l=x;
    else if(a==2)r=x;
    else if(a==3)d=y;
    else if(a==4)u=y;
  }
  out(max(r-l,0)*max(u-d,0));
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}