#include <bits/stdc++.h>                                                                     
                                                                                             
using namespace std;                                                                         
                                                                                             
#define all(x) x.begin(), x.end()                                                            
#define rep(i, n) for (int i = 0; i < n; ++i)                                                
#define reps(i, m, n) for (int i = m; i <= n; ++i)                                           
                                                                                             
using i64 = long long;                                                                       
using pii = pair<i64, i64>;                                                                  
                                                                                             
template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}   
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}   
                                                                                             
constexpr int INF = 0x3f3f3f3f;                                                              
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;                                                   
constexpr int mod = int(1e9) + 7;                                                            
                                                                                             
bool black[110][110];                                                                        
                                                                                             
signed main()                                                                                
{                                                                                            
  ios::sync_with_stdio(false);                                                               
  cin.tie(nullptr);                                                                          
  int w, h, n;                                                                               
  cin >> w >> h >> n;                                                                        
                                                                                             
  int x, y, a;                                                                               
  rep(i, n) {                                                                                
    cin >> x >> y >> a;                                                                      
                                                                                             
    if (a == 1) {                                                                            
      for (int i = 0; i < h; ++i) {                                                          
        for (int j = 0; j < x; ++j) {                                                        
          black[i][j] = 1;                                                                   
        }                                                                                    
      }                                                                                      
    }                                                                                        
                                                                                             
    if (a == 2) {                                                                            
      for (int i = 0; i < h; ++i) {                                                          
        for (int j = x; j < w; ++j) {                                                        
          black[i][j] = 1;                                                                   
        }                                                                                    
      }                                                                                      
    }                                                                                        
                                                                                             
    if (a == 3) {                                                                            
      for (int i = 0; i < y; ++i) {                                                          
        for (int j = 0; j < w; ++j) {                                                        
          black[i][j] = 1;                                                                   
        }                                                                                    
      }                                                                                      
    }                                                                                        
                                                                                             
    if (a == 4) {                                                                            
      for (int i = y; i < h; ++i) {                                                          
        for (int j = 0; j < w; ++j) {                                                        
          black[i][j] = 1;                                                                   
        }                                                                                    
      }                                                                                      
    }                                                                                        
                                                                                             
  }                                                                                          
                                                                                             
  int cnt = 0;                                                                               
  for (int i = 0; i < h; ++i) {                                                              
    for (int j = 0; j < w; ++j) {                                                            
      if (!black[i][j]) ++cnt;                                                               
    }                                                                                        
  }                                                                                          
                                                                                             
  cout << cnt << "\n";                                                                       
                                                                                             
  return 0;                                                                                  
}                                                                                            

Measured memory_bytes: 256