#import <stdio.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define ABS(a) ((a)>0?(a):(-(a)))

long fl(double x) {
    long n = (long)x;
    return n + (((x != n) && (x < 0)) ? -1 : 0);
}

long r(double x) {
    double n = fl(x);
    double d = x - n;
    return ((x>=0)&&(d<0.5))||((x<0)&&(d<=0.5)) ? n : n+1;
}

int main() {
    long H,W;
    scanf("%ld %ld",&H,&W);
    if (W%3==0 || H%3==0) {
        printf("0");
        return 0;
    }
    long min = MIN(H,W);
    if (H%2==0) {
        long x = r(2.0*W/3);
        min = MIN(min, ABS(H/2*x - (W-x)*H));
    }
    if (W%2==0) {
        long x = r(2.0*H/3);
        min = MIN(min, ABS(W/2*x - (H-x)*W));
    }
    if (H%2==1) {
        long n = (H-1)/2;
        for (long x=MAX(1,2.0*W/3-2);x<=MIN(W-1,2.0*W/3+2);x++) {
            min = MIN(min,MAX(ABS((W-x)*H-(n+1)*x),ABS((W-x)*H-n*x)));
        }
    }
    if (W%2==1) {
        long n = (W-1)/2;
        for (long x=MAX(1,2.0*H/3-2);x<=MIN(H-1,2.0*H/3+2);x++) {
            min = MIN(min,MAX(ABS((H-x)*W-(n+1)*x),ABS((H-x)*W-n*x)));
        }
    }
    printf("%ld",min);
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_783/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_783/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"

@.str = private unnamed_addr constant [8 x i8] c"%ld %ld\00", align 1
@.str.2 = private unnamed_addr constant [4 x i8] c"%ld\00", align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i64 @fl(double noundef %x) local_unnamed_addr #0 {
entry:
  %conv = fptosi double %x to i64
  %conv1 = sitofp i64 %conv to double
  %cmp = fcmp une double %conv1, %x
  %cmp3 = fcmp olt double %x, 0.000000e+00
  %0 = and i1 %cmp3, %cmp
  %conv5 = sext i1 %0 to i64
  %add = add nsw i64 %conv5, %conv
  ret i64 %add
}

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

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i64 @r(double noundef %x) local_unnamed_addr #0 {
entry:
  %conv.i = fptosi double %x to i64
  %conv1.i = sitofp i64 %conv.i to double
  %cmp.i = fcmp une double %conv1.i, %x
  %cmp3.i = fcmp olt double %x, 0.000000e+00
  %0 = and i1 %cmp3.i, %cmp.i
  %conv5.i = sext i1 %0 to i64
  %add.i = add nsw i64 %conv5.i, %conv.i
  %conv = sitofp i64 %add.i to double
  %sub = fsub double %x, %conv
  %cmp = fcmp oge double %x, 0.000000e+00
  %cmp2 = fcmp olt double %sub, 5.000000e-01
  %or.cond = select i1 %cmp, i1 %cmp2, i1 false
  %cmp7 = fcmp ole double %sub, 5.000000e-01
  %or.cond10 = select i1 %cmp3.i, i1 %cmp7, i1 false
  %or.cond17 = select i1 %or.cond, i1 true, i1 %or.cond10
  %add = fadd double %conv, 1.000000e+00
  %cond = select i1 %or.cond17, double %conv, double %add
  %conv9 = fptosi double %cond to i64
  ret i64 %conv9
}

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #2 {
entry:
  %H = alloca i64, align 8
  %W = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %H) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %W) #6
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %H, ptr noundef nonnull %W)
  %0 = load i64, ptr %W, align 8
  %rem = srem i64 %0, 3
  %cmp = icmp eq i64 %rem, 0
  br i1 %cmp, label %if.then, label %lor.lhs.false

lor.lhs.false:                                    ; preds = %entry
  %1 = load i64, ptr %H, align 8
  %rem1 = srem i64 %1, 3
  %cmp2 = icmp eq i64 %rem1, 0
  br i1 %cmp2, label %if.then, label %if.end

if.then:                                          ; preds = %lor.lhs.false, %entry
  %putchar = call i32 @putchar(i32 48)
  br label %cleanup

if.end:                                           ; preds = %lor.lhs.false
  %cond = call i64 @llvm.smin.i64(i64 %1, i64 %0)
  %2 = and i64 %1, 1
  %cmp6 = icmp eq i64 %2, 0
  br i1 %cmp6, label %if.then7, label %if.end58

if.then7:                                         ; preds = %if.end
  %conv = sitofp i64 %0 to double
  %mul = fmul double %conv, 2.000000e+00
  %div = fdiv double %mul, 3.000000e+00
  %conv.i.i = fptosi double %div to i64
  %conv1.i.i = sitofp i64 %conv.i.i to double
  %cmp.i.i = fcmp une double %div, %conv1.i.i
  %cmp3.i.i = fcmp olt double %div, 0.000000e+00
  %3 = and i1 %cmp3.i.i, %cmp.i.i
  %conv5.i.i = sext i1 %3 to i64
  %add.i.i = add nsw i64 %conv5.i.i, %conv.i.i
  %conv.i = sitofp i64 %add.i.i to double
  %sub.i = fsub double %div, %conv.i
  %cmp.i = fcmp oge double %div, 0.000000e+00
  %cmp2.i = fcmp olt double %sub.i, 5.000000e-01
  %or.cond.i = select i1 %cmp.i, i1 %cmp2.i, i1 false
  %cmp7.i = fcmp ole double %sub.i, 5.000000e-01
  %or.cond10.i = select i1 %cmp3.i.i, i1 %cmp7.i, i1 false
  %or.cond17.i = select i1 %or.cond.i, i1 true, i1 %or.cond10.i
  %add.i = fadd double %conv.i, 1.000000e+00
  %cond.i = select i1 %or.cond17.i, double %conv.i, double %add.i
  %conv9.i = fptosi double %cond.i to i64
  %div9 = sdiv i64 %1, 2
  %mul10 = mul nsw i64 %div9, %conv9.i
  %sub.neg = sub i64 %conv9.i, %0
  %mul11.neg = mul i64 %1, %sub.neg
  %sub12 = add i64 %mul10, %mul11.neg
  %cond29 = call i64 @llvm.abs.i64(i64 %sub12, i1 true)
  %spec.select = call i64 @llvm.smin.i64(i64 %cond, i64 %cond29)
  br label %if.end58

if.end58:                                         ; preds = %if.then7, %if.end
  %min.0 = phi i64 [ %cond, %if.end ], [ %spec.select, %if.then7 ]
  %4 = and i64 %0, 1
  %cmp60 = icmp eq i64 %4, 0
  br i1 %cmp60, label %if.then62, label %if.end118

if.then62:                                        ; preds = %if.end58
  %conv64 = sitofp i64 %1 to double
  %mul65 = fmul double %conv64, 2.000000e+00
  %div66 = fdiv double %mul65, 3.000000e+00
  %conv.i.i762 = fptosi double %div66 to i64
  %conv1.i.i763 = sitofp i64 %conv.i.i762 to double
  %cmp.i.i764 = fcmp une double %div66, %conv1.i.i763
  %cmp3.i.i765 = fcmp olt double %div66, 0.000000e+00
  %5 = and i1 %cmp3.i.i765, %cmp.i.i764
  %conv5.i.i766 = sext i1 %5 to i64
  %add.i.i767 = add nsw i64 %conv5.i.i766, %conv.i.i762
  %conv.i768 = sitofp i64 %add.i.i767 to double
  %sub.i769 = fsub double %div66, %conv.i768
  %cmp.i770 = fcmp oge double %div66, 0.000000e+00
  %cmp2.i771 = fcmp olt double %sub.i769, 5.000000e-01
  %or.cond.i772 = select i1 %cmp.i770, i1 %cmp2.i771, i1 false
  %cmp7.i773 = fcmp ole double %sub.i769, 5.000000e-01
  %or.cond10.i774 = select i1 %cmp3.i.i765, i1 %cmp7.i773, i1 false
  %or.cond17.i775 = select i1 %or.cond.i772, i1 true, i1 %or.cond10.i774
  %add.i776 = fadd double %conv.i768, 1.000000e+00
  %cond.i777 = select i1 %or.cond17.i775, double %conv.i768, double %add.i776
  %conv9.i778 = fptosi double %cond.i777 to i64
  %div68 = sdiv i64 %0, 2
  %mul69 = mul nsw i64 %div68, %conv9.i778
  %sub70.neg = sub i64 %conv9.i778, %1
  %mul71.neg = mul i64 %sub70.neg, %0
  %sub72 = add i64 %mul71.neg, %mul69
  %cond89 = call i64 @llvm.abs.i64(i64 %sub72, i1 true)
  %spec.select785 = call i64 @llvm.smin.i64(i64 %min.0, i64 %cond89)
  br label %if.end118

if.end118:                                        ; preds = %if.then62, %if.end58
  %min.1 = phi i64 [ %min.0, %if.end58 ], [ %spec.select785, %if.then62 ]
  %6 = and i64 %1, -9223372036854775807
  %cmp120 = icmp eq i64 %6, 1
  br i1 %cmp120, label %if.then122, label %if.end343

if.then122:                                       ; preds = %if.end118
  %sub123 = add nsw i64 %1, -1
  %div124783790 = lshr i64 %sub123, 1
  %conv126 = sitofp i64 %0 to double
  %mul127 = fmul double %conv126, 2.000000e+00
  %div128 = fdiv double %mul127, 3.000000e+00
  %sub129 = fadd double %div128, -2.000000e+00
  %cmp130 = fcmp olt double %sub129, 1.000000e+00
  %cond139 = select i1 %cmp130, double 1.000000e+00, double %sub129
  %conv140 = fptosi double %cond139 to i64
  %sub142 = add nsw i64 %0, -1
  %conv143 = sitofp i64 %sub142 to double
  %add = fadd double %div128, 2.000000e+00
  %cmp147 = fcmp ogt double %add, %conv143
  %conv143.add = select i1 %cmp147, double %conv143, double %add
  %conv141793 = sitofp i64 %conv140 to double
  %cmp159794 = fcmp ult double %conv143.add, %conv141793
  br i1 %cmp159794, label %if.end343, label %for.body.lr.ph

for.body.lr.ph:                                   ; preds = %if.then122
  %add163.neg = xor i64 %div124783790, -1
  br label %for.body

for.body:                                         ; preds = %for.body.lr.ph, %for.body
  %x125.0796 = phi i64 [ %conv140, %for.body.lr.ph ], [ %inc, %for.body ]
  %min.2795 = phi i64 [ %min.1, %for.body.lr.ph ], [ %cond342, %for.body ]
  %sub161 = sub nsw i64 %0, %x125.0796
  %mul162 = mul nsw i64 %sub161, %1
  %mul164.neg = mul i64 %x125.0796, %add163.neg
  %sub165 = add i64 %mul162, %mul164.neg
  %cond182 = call i64 @llvm.abs.i64(i64 %sub165, i1 true)
  %mul185 = mul nsw i64 %x125.0796, %div124783790
  %sub186 = sub nsw i64 %mul162, %mul185
  %cond201 = call i64 @llvm.abs.i64(i64 %sub186, i1 true)
  %minmaxop = call i64 @llvm.umax.i64(i64 %cond182, i64 %cond201)
  %cond342 = call i64 @llvm.smin.i64(i64 %minmaxop, i64 %min.2795)
  %inc = add nsw i64 %x125.0796, 1
  %conv141 = sitofp i64 %inc to double
  %cmp159 = fcmp ult double %conv143.add, %conv141
  br i1 %cmp159, label %if.end343, label %for.body

if.end343:                                        ; preds = %for.body, %if.then122, %if.end118
  %min.3 = phi i64 [ %min.1, %if.end118 ], [ %min.1, %if.then122 ], [ %cond342, %for.body ]
  %7 = and i64 %0, -9223372036854775807
  %cmp345 = icmp eq i64 %7, 1
  br i1 %cmp345, label %if.then347, label %if.end576

if.then347:                                       ; preds = %if.end343
  %sub349 = add nsw i64 %0, -1
  %div350784791 = lshr i64 %sub349, 1
  %conv352 = sitofp i64 %1 to double
  %mul353 = fmul double %conv352, 2.000000e+00
  %div354 = fdiv double %mul353, 3.000000e+00
  %sub355 = fadd double %div354, -2.000000e+00
  %cmp356 = fcmp olt double %sub355, 1.000000e+00
  %cond365 = select i1 %cmp356, double 1.000000e+00, double %sub355
  %conv366 = fptosi double %cond365 to i64
  %sub369 = add nsw i64 %1, -1
  %conv370 = sitofp i64 %sub369 to double
  %add374 = fadd double %div354, 2.000000e+00
  %cmp375 = fcmp ogt double %add374, %conv370
  %conv370.add374 = select i1 %cmp375, double %conv370, double %add374
  %conv368797 = sitofp i64 %conv366 to double
  %cmp387798 = fcmp ult double %conv370.add374, %conv368797
  br i1 %cmp387798, label %if.end576, label %for.body390.lr.ph

for.body390.lr.ph:                                ; preds = %if.then347
  %add393.neg = xor i64 %div350784791, -1
  br label %for.body390

for.body390:                                      ; preds = %for.body390.lr.ph, %for.body390
  %x351.0800 = phi i64 [ %conv366, %for.body390.lr.ph ], [ %inc574, %for.body390 ]
  %min.4799 = phi i64 [ %min.3, %for.body390.lr.ph ], [ %cond572, %for.body390 ]
  %sub391 = sub nsw i64 %1, %x351.0800
  %mul392 = mul nsw i64 %sub391, %0
  %mul394.neg = mul i64 %x351.0800, %add393.neg
  %sub395 = add i64 %mul392, %mul394.neg
  %cond412 = call i64 @llvm.abs.i64(i64 %sub395, i1 true)
  %mul415 = mul nsw i64 %x351.0800, %div350784791
  %sub416 = sub nsw i64 %mul392, %mul415
  %cond431 = call i64 @llvm.abs.i64(i64 %sub416, i1 true)
  %minmaxop792 = call i64 @llvm.umax.i64(i64 %cond412, i64 %cond431)
  %cond572 = call i64 @llvm.smin.i64(i64 %minmaxop792, i64 %min.4799)
  %inc574 = add nsw i64 %x351.0800, 1
  %conv368 = sitofp i64 %inc574 to double
  %cmp387 = fcmp ult double %conv370.add374, %conv368
  br i1 %cmp387, label %if.end576, label %for.body390

if.end576:                                        ; preds = %for.body390, %if.then347, %if.end343
  %min.5 = phi i64 [ %min.3, %if.end343 ], [ %min.3, %if.then347 ], [ %cond572, %for.body390 ]
  %call577 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %min.5)
  br label %cleanup

cleanup:                                          ; preds = %if.end576, %if.then
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %W) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %H) #6
  ret i32 0
}

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #5

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.abs.i64(i64, i1 immarg) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #4

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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 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 #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nofree nounwind }
attributes #6 = { 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)"}
