Language: C++

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <random>
#include <unordered_map>
#include <unordered_set>

using namespace std;

//呪文
#define DUMPOUT cerr
#define dump(...) DUMPOUT<<"  ";DUMPOUT<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;DUMPOUT<<"    ";dump_func(__VA_ARGS__)

typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef pair<string, string> pss;
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { ostr << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const unordered_map<_KTy, _Ty>& m) { if (m.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { ostr << ", " << *itr; }	ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { ostr << ", " << *itr; }	ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const unordered_set<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { ostr << ", " << *itr; }	ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const stack<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } stack<_Ty> t(s); ostr << "{" << t.top(); t.pop(); while (!t.empty()) { ostr << ", " << t.top(); t.pop(); } ostr << "}";	return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const list<_Ty>& l) { if (l.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { istr >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) istr >> v[i]; return istr; }
namespace aux { // print tuple
	template<typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream& os, const Ty& v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } };
	template<typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream& os, const Ty& value) { os << get<N>(value); } };
}
template<typename... Tys> ostream& operator<<(ostream& os, const tuple<Tys...>& t) { os << "{"; aux::tp<tuple<Tys...>, 0, sizeof...(Tys)-1>::print(os, t); os << "}"; return os; }

template<typename A, size_t N, typename T> inline void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); }

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define fake false



int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	ll H, W;
	cin >> H >> W;

	ll ans = INT64_MAX;

	if (H % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	else
		ans = min(ans, W);

	if (W % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	else
		ans = min(ans, H);

	for (int i = 0; i <= H; i++) {
		ll w = W / 2;
		ll s0 = W * i;
		ll s1 = w * (H - i);
		ll s2 = (W - w) * (H - i);
		ll dif = max(s0, max(s1, s2)) - min(s0, min(s1, s2));
		ans = min(ans, dif);
	}

	for (int i = 0; i <= W; i++) {
		ll h = H / 2;
		ll s0 = H * i;
		ll s1 = h * (W - i);
		ll s2 = (H - h) * (W - i);
		ll dif = max(s0, max(s1, s2)) - min(s0, min(s1, s2));
		ans = min(ans, dif);
	}

	cout << ans << endl;
	
	return 0;
}#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <random>
#include <unordered_map>
#include <unordered_set>

using namespace std;

//呪文
#define DUMPOUT cerr
#define dump(...) DUMPOUT<<"  ";DUMPOUT<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;DUMPOUT<<"    ";dump_func(__VA_ARGS__)

typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef pair<string, string> pss;
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { ostr << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const unordered_map<_KTy, _Ty>& m) { if (m.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { ostr << ", " << *itr; }	ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { ostr << ", " << *itr; }	ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const unordered_set<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { ostr << ", " << *itr; }	ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const stack<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } stack<_Ty> t(s); ostr << "{" << t.top(); t.pop(); while (!t.empty()) { ostr << ", " << t.top(); t.pop(); } ostr << "}";	return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const list<_Ty>& l) { if (l.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { istr >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) istr >> v[i]; return istr; }
namespace aux { // print tuple
	template<typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream& os, const Ty& v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } };
	template<typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream& os, const Ty& value) { os << get<N>(value); } };
}
template<typename... Tys> ostream& operator<<(ostream& os, const tuple<Tys...>& t) { os << "{"; aux::tp<tuple<Tys...>, 0, sizeof...(Tys)-1>::print(os, t); os << "}"; return os; }

template<typename A, size_t N, typename T> inline void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); }

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define fake false



int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	ll H, W;
	cin >> H >> W;

	ll ans = INT64_MAX;

	if (H % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	else
		ans = min(ans, W);

	if (W % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	else
		ans = min(ans, H);

	for (int i = 0; i <= H; i++) {
		ll w = W / 2;
		ll s0 = W * i;
		ll s1 = w * (H - i);
		ll s2 = (W - w) * (H - i);
		ll dif = max(s0, max(s1, s2)) - min(s0, min(s1, s2));
		ans = min(ans, dif);
	}

	for (int i = 0; i <= W; i++) {
		ll h = H / 2;
		ll s0 = H * i;
		ll s1 = h * (W - i);
		ll s2 = (H - h) * (W - i);
		ll dif = max(s0, max(s1, s2)) - min(s0, min(s1, s2));
		ans = min(ans, dif);
	}

	cout << ans << endl;
	
	return 0;
}

Compiler output:
a.cc:90:2: error: stray '#' in program
   90 | }#define _CRT_SECURE_NO_WARNINGS
      |  ^
a.cc:90:3: error: 'define' does not name a type
   90 | }#define _CRT_SECURE_NO_WARNINGS
      |   ^~~~~~
a.cc:103:49: error: redefinition of 'template<class _KTy, class _Ty> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)'
  103 | template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { ostr << "{" << m.first << ", " << m.second << "}"; return ostr; }
      |                                                 ^~~~~~~~
a.cc:14:49: note: 'template<class _KTy, class _Ty> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' previously declared here
   14 | template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { ostr << "{" << m.first << ", " << m.second << "}"; return ostr; }
      |                                                 ^~~~~~~~
a.cc:104:49: error: redefinition of 'template<class _KTy, class _Ty> std::ostream& operator<<(std::ostream&, const std::map<_KTy, _Ty>&)'
  104 | template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
      |                                                 ^~~~~~~~
a.cc:15:49: note: 'template<class _KTy, class _Ty> std::ostream& operator<<(std::ostream&, const std::map<_KTy, _Ty>&)' previously declared here
   15 | template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
      |                                                 ^~~~~~~~
a.cc:105:49: error: redefinition of 'template<class _KTy, class _Ty> std::ostream& operator<<(std::ostream&, const std::unordered_map<_KTy, _Ty>&)'
  105 | template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const unordered_map<_KTy, _Ty>& m) { if (m.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
      |                                                 ^~~~~~~~
a.cc:16:49: note: 'template<class _KTy, class _Ty> std::ostream& operator<<(std::ostream&, const std::unordered_map<_KTy, _Ty>&)' previously declared here
   16 | template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const unordered_map<_KTy, _Ty>& m) { if (m.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
      |                                                 ^~~~~~~~
a.cc:106:34: error: redefinition of 'template<class _Ty> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)'
  106 | template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { ostr << ", " << *itr; }     ostr << "}"; return ostr; }
      |                                  ^~~~~~~~
a.cc:17:34: note: 'template<class _Ty> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here
   17 | template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { ostr << ", " << *itr; }     ostr << "}"; return ostr; }
      |                                  ^~~~~~~~
a.cc:107:34: error: redefinition of 'template<class _Ty> std::ostream& operator<<(std::ostream&, const std::set<_Ty>&)'
  107 | template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { ostr << ", " << *itr; }     ostr << "}"; return ostr; }
      |                                  ^~~~~~~~
a.cc:18:34: note: 'template<class _Ty> std::ostream& operator<<(std::ostream&, const std::set<_Ty>&)' previously declared here
   18 | template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { ostr << ", " << *itr; }     ostr << "}"; return ostr; }
      |                                  ^~~~~~~~
a.cc:108:34: error: redefinition of 'template<class _Ty> std::ostream& operator<<(std::ostream&, const std::unordered_set<_Ty>&)'
  108 | template <typename _Ty> ostream& operator << (ostream& ostr, const unordered_set<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { ostr << ", " << *itr; }   ostr << "}"; return ostr; }
      |                                  ^~~~~~~~
a.cc:19:34: note: 'template<class _Ty> std::ostream& operator<<(std::ostream&, const std::unordered_set<_Ty>&)' previously declared here
   19 | template <typename _Ty> ostream& operator << (ostream& ostr, const unordered_set<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { ostr << ", " << *itr; }   ostr << "}"; return ostr; }
      |                                  ^~~~~~~~
a.cc:109:34: error: redefinition of 'template<class _Ty> std::ostream& operator<<(std::ostream&, const std::stack<_Ty>&)'
  109 | template <typename _Ty> ostream& operator << (ostream& ostr, const stack<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } stack<_Ty> t(s); ostr << "{" << t.top(); t.pop(); while (!t.empty()) { ostr << ", " << t.top(); t.pop(); } ostr << "}";      return ostr; }
      |                                  ^~~~~~~~
a.cc:20:34: note: 'template<class _Ty> std::ostream& operator<<(std::ostream&, const std::stack<_Ty>&)' previously declared here
   20 | template <typename _Ty> ostream& operator << (ostream& ostr, const stack<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } stack<_Ty> t(s); ostr << "{" << t.top(); t.pop(); while (!t.empty()) { ostr << ", " << t.top(); t.pop(); } ostr << "}";      return ostr; }
      |                                  ^~~~~~~~
a.cc:110:34: error: redefinition of 'template<class _Ty> std::ostream& operator<<(std::ostream&, const std::__cxx11::list<_Ty>&)'
  110 | template <typename _Ty> ostream& operator << (ostream& ostr, const list<_Ty>& l) { if (l.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
      |                                  ^~~~~~~~
a.cc:21:34: note: 'template<class _Ty> std::ostream& operator<<(std::ostream&, const std::__cxx11::list<_Ty>&)' previously declared here
   21 | template <typename _Ty> ostream& operator << (ostream& ostr, const list<_Ty>& l) { if (l.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
      |                                  ^~~~~~~~
a.cc:111:49: error: redefinition of 'template<class _KTy, class _Ty> std::istream& operator>>(std::istream&, std::pair<_T1, _T2>&)'
  111 | template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { istr >> m.first >> m.second; return istr; }
      |                                                 ^~~~~~~~
a.cc:22:49: note: 'template<class _KTy, class _Ty> std::istream& operator>>(std::istream&, std::pair<_T1, _T2>&)' previously declared here
   22 | template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { istr >> m.first >> m.second; return istr; }
      |                                                 ^~~~~~~~
a.cc:112:34: error: redefinition of 'template<class _Ty> std::istream& operator>>(std::istream&, std::vector<_Tp>&)'
  112 | template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) istr >> v[i]; return istr; }
      |                                  ^~~~~~~~
a.cc:23:34: note: 'template<class _Ty> std::istream& operator>>(std::istream&, std::vector<_Tp>&)' previously declared here
   23 | template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) istr >> v[i]; return istr; }
      |                                  ^~~~~~~~
a.cc:114:62: error: redefinition of 'struct aux::tp<Ty, N, L>'
  114 |         template<typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream& os, const Ty& v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } };
      |                                                              ^~
a.cc:25:62: note: previous definition of 'struct aux::tp<Ty, N, L>'
   25 |         template<typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream& os, const Ty& v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } };
      |                                                              ^~
a.cc:115:50: error: redefinition of 'struct aux::tp<Ty, N, N>'
  115 |         template<typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream& os, const Ty& value) { os << get<N>(value); } };
      |                                                  ^~~~~~~~~~~~
a.cc:26:50: note: previous definition of 'struct aux::tp<Ty, N, N>'
   26 |         template<typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream& os, const Ty& value) { os << get<N>(value); } };
      |                                                  ^~~~~~~~~~~~
a.cc:117:36: error: redefinition of 'template<class ... Tys> std::ostream& operator<<(std::ostream&, const std::tuple<_UTypes ...>&)'