#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"import numpy\n"
"I=lambda:map(int,input().split())\n"
"W,H,N=I()\n"
"m=numpy.zeros((H,W),int)\n"
"while N:x,y,a=I();m[y*(a>3):H*(a^3)or y,x*(a==2):W*~-a or x]=1;N-=1\n"
"print(W*H-m.sum())\n"
"\"";
  system(s);
  return 0;
}            