Language: C++

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

#define DEBUG 0
#define REP(i, n) for (int i = 0; i < (n); i++) 
typedef long long ll;
typedef pair<int,int> pint;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main() { 
    ll h,w;
    cin >> h >> w;
    ll hw = h * w;

    //それぞれの面積
    ll a,b,c;
    ll smax,smin;

    int res = INF;

    //方針: 基本的に全探索 smaxが半分を超えたら終了
    //パターンわけ 6パターンあるのでそれを全部調べる

    //1. 横で切る
    for(ll i = 1; i <= h-2; ++i)
    {
        a = w * i;
        if(a > hw / 2)break;
        for(ll j = i + 1; j <= h-1; ++j)
        {
            b = w * (j - i);
            if(b > hw / 2)break;
            c = w * (h - j);
            smax = max(a,max(b,c));
            smin = min(a,min(b,c));
            res = min(res, smax - smin);
        }
    }
    //2.縦できる
    for(ll i = 1; i <= w-2; ++i)
    {
        a = h * i;
        if(a > hw / 2)break;
        for(ll j = i + 1; j <= w-1; ++j)
        {
            b = h * (j - i);
            if(b > hw / 2)break;
            c = h * (h - j);
            smax = max(a,max(b,c));
            smin = min(a,min(b,c));
            res = min(res, smax - smin);
        }
    }
    //3. 左は1右を2分割
    for(ll i = 1; i <= w-2; ++i)
    {
        a = h * i;
        if(a > hw / 2)break;
        for(ll j = i + 1; j <= w-1; ++j)
        {
            b = h * (j - i);
            if(b > hw / 2)break;
            c = h * (h - j);
            smax = max(a,max(b,c));
            smin = min(a,min(b,c));
            res = min(res, smax - smin);
        }
    }
    cout << res << endl;

    return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:15: warning: overflow in conversion from 'long long int' to 'int' changes value from '1000000000000000000' to '-1486618624' [-Woverflow]
   27 |     int res = INF;
      |               ^~~
a.cc:44:22: error: no matching function for call to 'min(int&, ll)'
   44 |             res = min(res, smax - smin);
      |                   ~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:44:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   44 |             res = min(res, smax - smin);
      |                   ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:44:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   44 |             res = min(res, smax - smin);
      |                   ~~~^~~~~~~~~~~~~~~~~~
a.cc:59:22: error: no matching function for call to 'min(int&, ll)'
   59 |             res = min(res, smax - smin);
      |                   ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:59:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   59 |             res = min(res, smax - smin);
      |                   ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:59:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   59 |             res = min(res, smax - smin);
      |                   ~~~^~~~~~~~~~~~~~~~~~
a.cc:74:22: error: no matching function for call to 'min(int&, ll)'
   74 |             res = min(res, smax - smin);
      |                   ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:74:22: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   74 |             res = min(res, smax - smin);
      |                   ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:74:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   74 |             res = min(res, smax - smin);
      |                   ~~~^~~~~~~~~~~~~~~~~~