unittest
{
	assert( [ "5 4 2", "2 1 1", "3 3 4" ].parse.expand.solve == 9 );
	assert( [ "5 4 3", "2 1 1", "3 3 4", "1 4 2" ].parse.expand.solve == 0 );
	assert( [ "10 10 5", "1 6 1", "4 1 3", "6 9 4", "9 4 2", "3 1 3" ].parse.expand.solve == 64 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto whn = input.front.split.to!( long[] );
	auto xyas = new long[][]( whn[ 2 ] );
	foreach( ref xya; xyas )
	{
		input.popFront;
		xya = input.front.split.to!( long[] );
	}
	return tuple( whn[ 0 ], whn[ 1 ], xyas );
}

auto solve( long w, long h, long[][] xyas )
{
	auto css = new bool[][]( w, h );
	foreach( xya; xyas )
	{
		switch( xya[ 2 ] )
		{
			case 1 : css.fill( 0, 0, xya[ 0 ], h ); break;
			case 2 : css.fill( xya[ 0 ], 0, w, h ); break;
			case 3 : css.fill( 0, 0, w, xya[ 1 ] ); break;
			case 4 : css.fill( 0, xya[ 1 ], w, h ); break;
			default: assert( false );
		}
	}
	return css.joiner.count( false );
}

void fill( ref bool[][] css, long x1, long y1, long x2, long y2 )
{
	for( auto x = x1; x < x2; x++ )
	{
		for( auto y = y1; y < y2; y++ )
		{
			css[ x ][ y ] = true;
		}
	}
}
