fun main(arr: Array<String>) {
    val (w,h,n) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { (1..w).map { 0 }.toMutableList() }.toMutableList()
    for(i in (1..n)) {
        val (x,y,a) = readLine()!!.split(" ").map { it.toInt() }
        when (a) {
            1 -> {
                (0 until h).forEach { yidx-> (0 until w).filter { it < x }.forEach { xidx -> map[yidx][xidx] = 1 } }
            }
            2 -> {
                (0 until h).forEach { yidx-> (0 until w).filter { it >= x }.forEach { xidx -> map[yidx][xidx] = 1 } }
            }
            3 -> {
                (0 until h).filter { it < y }.forEach { yidx -> map[yidx] = (0 until w).map { 1 }.toMutableList() }
            }
            else -> {
                (0 until h).filter { it >= y }.forEach { yidx -> map[yidx] = (0 until w).map { 1 }.toMutableList() }
            }
        }
    }
    val ans = map.map { it.count { it==0 } }.sum()
    println(ans)
}