Language: C++

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int h,w,min=mod;
	cin>>h>>w;
	if(h%3==0||w%3==0)cout<<0<<endl;
	else{
	if(h<w)swap(h,w);
	int th=h,tw=w;
	long a1=h/3;
	if(h%3==2)a1++;
	h-=a1;
	a1*=w;
	FOR(i,0,2){
		if(i==1){
			h=tw;
			w=th;
			a1=h/3;
			if(h%3==2)a1++;
			h-=a1;
			a1*=w;
		}

	long a2,a3;
	if(w%2==0||h%2==0){
			a2=(long)h*w/2;
			a3=a2;
			//cout<<h<<w<<a1<<endl;
	}else{
	if(h<w)swap(h,w);
	//cout<<h<<w<<a1<<endl;
	a2=h/2;
	h-=a2;
	a2*=w;
	a3=(long)h*w;
	}
	if(a1<a2)swap(a1,a2);
	if(a2<a3)swap(a2,a3);
	if(a1<a2)swap(a1,a2);
	if(min>a1-a3)min=a1-a3;
}
	//cout<<a1<<a2<<a3<<endl;
	cout<<min<<endl;
}
    return 0;
}

#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int h,w,min=mod;
	cin>>h>>w;
	if(h%3==0||w%3==0)cout<<0<<endl;
	else{
	if(h<w)swap(h,w);
	long a1=h/3-2;
	long aa=a1,ah=h,aw=w;
	FOR(i,0,5){
		w=aw;
		h=ah;
		a1=aa+i;
	h-=a1;
	a1*=w;

	long a2,a3;
	if(w%2==0||h%2==0){
			a2=(long)h*w/2;
			a3=a2;
			//cout<<h<<w<<a1<<endl;
	}else{
	if(h<w)swap(h,w);
	//cout<<h<<w<<a1<<endl;
	a2=h/2;
	h-=a2;
	a2*=w;
	a3=(long)h*w;
	}
	if(a1<a2)swap(a1,a2);
	if(a2<a3)swap(a2,a3);
	if(a1<a2)swap(a1,a2);
	if(min>a1-a3)min=a1-a3;
}
	//cout<<a1<<a2<<a3<<endl;
	cout<<min<<endl;
}
    return 0;
}


Compiler output:
a.cc:5:19: warning: extra tokens at end of #include directive
    5 | #include <sstream>#include <cstdio>
      |                   ^
a.cc:116:14: error: redefinition of 'const double pi'
  116 | const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
      |              ^~
a.cc:39:14: note: 'const double pi' previously defined here
   39 | const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
      |              ^~
a.cc:117:11: error: redefinition of 'const int mod'
  117 | const int mod=1000000007;
      |           ^~~
a.cc:40:11: note: 'const int mod' previously defined here
   40 | const int mod=1000000007;
      |           ^~~
a.cc:119:5: error: redefinition of 'int main()'
  119 | int main(){
      |     ^~~~
a.cc:42:5: note: 'int main()' previously defined here
   42 | int main(){
      |     ^~~~