Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	ll h, w;
	cin >> h >> w;
	ll ans = 1e9;
	if (w*h % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 1;i < h;i++) {
		ll s1 = i * w, s2 = w / 2 * (h - i), s3 = h * w - s1 - s2;
		ll a = max(s1, max(s2, s3));
		ll b = min(s1, min(s2, s3));
		if (a - b >= 0)ans = min(ans, a - b);
		//printf("h=%d %d %d %d\n",i,s1,s2,s3);
		ll t1 = i * w, t2 = (h - i) / 2 * w, s3 = h * w - s1 - s2;
		ll a = max(s1, max(s2, s3));
		ll b = min(s1, min(s2, s3));
		if (a - b >= 0)ans = min(ans, a - b);
		//printf("h=%d %d %d %d\n",i,s1,s2,s3);
	}
	for (int i = 1;i < w;i++) {
		ll s1 = i * h, s2 = h / 2 * (w - i), s3 = h * w - s1 - s2;
		ll a = max(s1, max(s2, s3));
		ll b = min(s1, min(s2, s3));
		if (a - b >= 0)ans = min(ans, a - b);
		//printf("w=%d %d %d %d\n",i,s1,s2,s3);
		ll s1 = i * h, s2 = (w - i) / 2 * h, s3 = h * w - s1 - s2;
		ll a = max(s1, max(s2, s3));
		ll b = min(s1, min(s2, s3));
		if (a - b >= 0)ans = min(ans, a - b);
		//printf("w=%d %d %d %d\n",i,s1,s2,s3);
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:54: error: redeclaration of 'll s3'
   20 |                 ll t1 = i * w, t2 = (h - i) / 2 * w, s3 = h * w - s1 - s2;
      |                                                      ^~
a.cc:15:54: note: 'll s3' previously declared here
   15 |                 ll s1 = i * w, s2 = w / 2 * (h - i), s3 = h * w - s1 - s2;
      |                                                      ^~
a.cc:21:20: error: redeclaration of 'll a'
   21 |                 ll a = max(s1, max(s2, s3));
      |                    ^
a.cc:16:20: note: 'll a' previously declared here
   16 |                 ll a = max(s1, max(s2, s3));
      |                    ^
a.cc:22:20: error: redeclaration of 'll b'
   22 |                 ll b = min(s1, min(s2, s3));
      |                    ^
a.cc:17:20: note: 'll b' previously declared here
   17 |                 ll b = min(s1, min(s2, s3));
      |                    ^
a.cc:32:20: error: redeclaration of 'll s1'
   32 |                 ll s1 = i * h, s2 = (w - i) / 2 * h, s3 = h * w - s1 - s2;
      |                    ^~
a.cc:27:20: note: 'll s1' previously declared here
   27 |                 ll s1 = i * h, s2 = h / 2 * (w - i), s3 = h * w - s1 - s2;
      |                    ^~
a.cc:32:32: error: redeclaration of 'll s2'
   32 |                 ll s1 = i * h, s2 = (w - i) / 2 * h, s3 = h * w - s1 - s2;
      |                                ^~
a.cc:27:32: note: 'll s2' previously declared here
   27 |                 ll s1 = i * h, s2 = h / 2 * (w - i), s3 = h * w - s1 - s2;
      |                                ^~
a.cc:32:54: error: redeclaration of 'll s3'
   32 |                 ll s1 = i * h, s2 = (w - i) / 2 * h, s3 = h * w - s1 - s2;
      |                                                      ^~
a.cc:27:54: note: 'll s3' previously declared here
   27 |                 ll s1 = i * h, s2 = h / 2 * (w - i), s3 = h * w - s1 - s2;
      |                                                      ^~
a.cc:33:20: error: redeclaration of 'll a'
   33 |                 ll a = max(s1, max(s2, s3));
      |                    ^
a.cc:28:20: note: 'll a' previously declared here
   28 |                 ll a = max(s1, max(s2, s3));
      |                    ^
a.cc:34:20: error: redeclaration of 'll b'
   34 |                 ll b = min(s1, min(s2, s3));
      |                    ^
a.cc:29:20: note: 'll b' previously declared here
   29 |                 ll b = min(s1, min(s2, s3));
      |                    ^