Skip to content

Instantly share code, notes, and snippets.

@sadmiko
Last active June 27, 2018 14:49
Show Gist options
  • Save sadmiko/6d86b1a3d5331fc5f9ce2fa74456d865 to your computer and use it in GitHub Desktop.
Save sadmiko/6d86b1a3d5331fc5f9ce2fa74456d865 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int h,w,a,b;
long long int ans,M,m,X,Y,Z;
cin>>h>>w;
if(h*w%3==0){
cout<<0<<endl;
return 0;
}
ans=min(h,w);
for(int k=0;k<2;++k){
for(int i=0;i<=1;++i){
for(int j=0;j<=1;++j){
a=w/3+i;b=h/2+j;
X=a*h;
Y=b*(w-a);
Z=(w-a)*(h-b);
M=max(X,Y);
M=max(M,Z);
m=min(X,Y);
m=min(m,Z);
ans=min(ans,M-m);
}
}
swap(h,w);
}
cout<<ans<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment