#import <stdio.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
int main() {
    @autoreleasepool {
        int W,H,N;
        scanf("%d %d %d", &W,&H,&N);
        int minX = 0;
        int minY = 0;
        int maxX = W;
        int maxY = H;
        for (int i=0; i<N; i++){
            int x,y,a;
            scanf("%d %d %d", &x,&y,&a);
            switch (a) {
                case 1:
                    minX = MAX(minX, x);
                    break;
                case 2:
                    maxX = MIN(maxX, x);
                    break;
                case 3:
                    minY = MAX(minY, y);
                    break;
                case 4:
                    maxY = MIN(maxY, y);
                    break;
                default:
                    break;
            }
        }
        W = MAX(maxX - minX,0);
        H = MAX(maxY - minY,0);
        printf("%d", W*H);
    }
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_885/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_885/source.m"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

$.objc_sel_namealloc = comdat any

$.objc_sel_namedrain = comdat any

$.objc_sel_nameinit = comdat any

@0 = private unnamed_addr constant [18 x i8] c"NSAutoreleasePool\00", align 1
@__objc_class_name_NSAutoreleasePool = external global i64
@__objc_class_ref_NSAutoreleasePool = weak local_unnamed_addr constant ptr @__objc_class_name_NSAutoreleasePool
@.str = private unnamed_addr constant [9 x i8] c"%d %d %d\00", align 1
@.str.1 = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@1 = private unnamed_addr constant [12 x i8] c"AnotherHack\00", align 1
@2 = private unnamed_addr constant [33 x i8] c"__ObjC_Protocol_Holder_Ugly_Hack\00", align 1
@.objc_protocol_list = internal global { ptr, i64, [0 x ptr] } zeroinitializer, align 8
@3 = internal global { ptr, ptr, ptr, ptr, ptr } { ptr @1, ptr @2, ptr null, ptr null, ptr @.objc_protocol_list }, align 8
@.objc_sel_namealloc = linkonce_odr constant [6 x i8] c"alloc\00", comdat
@.objc_sel_namedrain = linkonce_odr constant [6 x i8] c"drain\00", comdat
@.objc_sel_nameinit = linkonce_odr constant [5 x i8] c"init\00", comdat
@.objc_selector_list = internal global [4 x { ptr, ptr }] [{ ptr, ptr } { ptr @.objc_sel_namealloc, ptr null }, { ptr, ptr } { ptr @.objc_sel_namedrain, ptr null }, { ptr, ptr } { ptr @.objc_sel_nameinit, ptr null }, { ptr, ptr } zeroinitializer], align 8
@4 = internal global { i64, ptr, i16, i16, [3 x ptr] } { i64 3, ptr @.objc_selector_list, i16 0, i16 1, [3 x ptr] [ptr @3, ptr null, ptr null] }, align 8
@.objc_source_file_name = private unnamed_addr constant [129 x i8] c"/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_885//data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_885/source.m\00", align 1
@5 = internal global { i64, i64, ptr, ptr } { i64 8, i64 32, ptr @.objc_source_file_name, ptr @4 }, align 8
@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @.objc_load_function, ptr null }]

; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
entry:
  %W = alloca i32, align 4
  %H = alloca i32, align 4
  %N = alloca i32, align 4
  %x = alloca i32, align 4
  %y = alloca i32, align 4
  %a = alloca i32, align 4
  %0 = tail call ptr (ptr, ...) @objc_lookup_class(ptr nonnull @0) #4
  %1 = tail call ptr @objc_msg_lookup(ptr %0, ptr nonnull @.objc_selector_list) #4, !GNUObjCMessageSend !5
  %call = tail call ptr %1(ptr noundef %0, ptr noundef nonnull @.objc_selector_list) #4, !GNUObjCMessageSend !5
  %2 = tail call ptr @objc_msg_lookup(ptr %call, ptr nonnull getelementptr inbounds ([4 x { ptr, ptr }], ptr @.objc_selector_list, i64 0, i64 2)) #4, !GNUObjCMessageSend !6
  %call1 = tail call ptr %2(ptr noundef %call, ptr noundef nonnull getelementptr inbounds ([4 x { ptr, ptr }], ptr @.objc_selector_list, i64 0, i64 2)) #4, !GNUObjCMessageSend !6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %W) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %H) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %N) #4
  %call2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %W, ptr noundef nonnull %H, ptr noundef nonnull %N)
  %3 = load i32, ptr %W, align 4, !tbaa !7
  %4 = load i32, ptr %H, align 4, !tbaa !7
  %5 = load i32, ptr %N, align 4, !tbaa !7
  %cmp50 = icmp sgt i32 %5, 0
  br i1 %cmp50, label %for.body, label %for.cond.cleanup

for.cond.cleanup:                                 ; preds = %sw.epilog, %entry
  %minX.0.lcssa = phi i32 [ 0, %entry ], [ %minX.1, %sw.epilog ]
  %minY.0.lcssa = phi i32 [ 0, %entry ], [ %minY.1, %sw.epilog ]
  %maxX.0.lcssa = phi i32 [ %3, %entry ], [ %maxX.1, %sw.epilog ]
  %maxY.0.lcssa = phi i32 [ %4, %entry ], [ %maxY.1, %sw.epilog ]
  %sub = sub nsw i32 %maxX.0.lcssa, %minX.0.lcssa
  %cond28 = call i32 @llvm.smax.i32(i32 %sub, i32 0)
  store i32 %cond28, ptr %W, align 4, !tbaa !7
  %sub29 = sub nsw i32 %maxY.0.lcssa, %minY.0.lcssa
  %cond35 = call i32 @llvm.smax.i32(i32 %sub29, i32 0)
  store i32 %cond35, ptr %H, align 4, !tbaa !7
  %mul = mul nsw i32 %cond35, %cond28
  %call36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %mul)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %N) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %H) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %W) #4
  %6 = call ptr @objc_msg_lookup(ptr %call1, ptr nonnull getelementptr inbounds ([4 x { ptr, ptr }], ptr @.objc_selector_list, i64 0, i64 1)) #4, !GNUObjCMessageSend !11
  call void %6(ptr noundef %call1, ptr noundef nonnull getelementptr inbounds ([4 x { ptr, ptr }], ptr @.objc_selector_list, i64 0, i64 1)) #4, !GNUObjCMessageSend !11
  ret i32 0

for.body:                                         ; preds = %entry, %sw.epilog
  %i.055 = phi i32 [ %inc, %sw.epilog ], [ 0, %entry ]
  %maxY.054 = phi i32 [ %maxY.1, %sw.epilog ], [ %4, %entry ]
  %maxX.053 = phi i32 [ %maxX.1, %sw.epilog ], [ %3, %entry ]
  %minY.052 = phi i32 [ %minY.1, %sw.epilog ], [ 0, %entry ]
  %minX.051 = phi i32 [ %minX.1, %sw.epilog ], [ 0, %entry ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %x) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %y) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %a) #4
  %call3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %x, ptr noundef nonnull %y, ptr noundef nonnull %a)
  %7 = load i32, ptr %a, align 4, !tbaa !7
  switch i32 %7, label %sw.epilog [
    i32 1, label %sw.bb
    i32 2, label %sw.bb5
    i32 3, label %sw.bb11
    i32 4, label %sw.bb17
  ]

sw.bb:                                            ; preds = %for.body
  %8 = load i32, ptr %x, align 4
  %cond = call i32 @llvm.smax.i32(i32 %minX.051, i32 %8)
  br label %sw.epilog

sw.bb5:                                           ; preds = %for.body
  %9 = load i32, ptr %x, align 4
  %cond10 = call i32 @llvm.smin.i32(i32 %maxX.053, i32 %9)
  br label %sw.epilog

sw.bb11:                                          ; preds = %for.body
  %10 = load i32, ptr %y, align 4
  %cond16 = call i32 @llvm.smax.i32(i32 %minY.052, i32 %10)
  br label %sw.epilog

sw.bb17:                                          ; preds = %for.body
  %11 = load i32, ptr %y, align 4
  %cond22 = call i32 @llvm.smin.i32(i32 %maxY.054, i32 %11)
  br label %sw.epilog

sw.epilog:                                        ; preds = %for.body, %sw.bb17, %sw.bb11, %sw.bb5, %sw.bb
  %minX.1 = phi i32 [ %minX.051, %for.body ], [ %minX.051, %sw.bb17 ], [ %minX.051, %sw.bb11 ], [ %minX.051, %sw.bb5 ], [ %cond, %sw.bb ]
  %minY.1 = phi i32 [ %minY.052, %for.body ], [ %minY.052, %sw.bb17 ], [ %cond16, %sw.bb11 ], [ %minY.052, %sw.bb5 ], [ %minY.052, %sw.bb ]
  %maxX.1 = phi i32 [ %maxX.053, %for.body ], [ %maxX.053, %sw.bb17 ], [ %maxX.053, %sw.bb11 ], [ %cond10, %sw.bb5 ], [ %maxX.053, %sw.bb ]
  %maxY.1 = phi i32 [ %maxY.054, %for.body ], [ %cond22, %sw.bb17 ], [ %maxY.054, %sw.bb11 ], [ %maxY.054, %sw.bb5 ], [ %maxY.054, %sw.bb ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %a) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %y) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %x) #4
  %inc = add nuw nsw i32 %i.055, 1
  %12 = load i32, ptr %N, align 4, !tbaa !7
  %cmp = icmp slt i32 %inc, %12
  br i1 %cmp, label %for.body, label %for.cond.cleanup
}

declare ptr @objc_lookup_class(ptr, ...) local_unnamed_addr

declare ptr @objc_msg_lookup(ptr, ptr) local_unnamed_addr

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

define internal void @.objc_load_function() {
entry:
  tail call void (ptr, ...) @__objc_exec_class(ptr nonnull @5)
  ret void
}

declare void @__objc_exec_class(ptr, ...) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #3

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!"alloc", !"", i1 false}
!6 = !{!"init", !"", i1 false}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"drain", !"", i1 false}
