Language: C++

#include <iostream>

using namespace std;

const long long INF = 9223372036854775807;

struct data {
  long long min = INF, max = 0;

  data &update(long long x) {
    if (x < min) min = x;
    if (x > max) max = x;
    return *this;
  }

  long long diff() const { return max - min; }
};

data operator^(const data &a, const data &b) {
  return a.diff() <= b.diff() ? a : b;
}

data dfs(long long h, long long w, int n) {
  if (n == 1) {
    long long S = h * w;
    return {S, S};
  }

  return dfs(h - h / n, w, n - 1).update(h / n * w) ^
         dfs(h - (h / n + 1), w, n - 1).update((h / n + 1) * w) ^
         dfs(h, w - w / n, n - 1).update(h * (w / n)) ^
         dfs(h, w - (w / n + 1), n - 1).update(h * (w / n + 1));
}

int main() {
  int H, W;
  cin >> H >> W;

  cout << dfs(H, W, 3).diff() << endl;
}


Compiler output:
a.cc:19:1: error: reference to 'data' is ambiguous
   19 | data operator^(const data &a, const data &b) {
      | ^~~~
In file included from /usr/include/c++/14/string:53,
                 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:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:8: note:                 'struct data'
    7 | struct data {
      |        ^~~~
a.cc:23:1: error: reference to 'data' is ambiguous
   23 | data dfs(long long h, long long w, int n) {
      | ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:8: note:                 'struct data'
    7 | struct data {
      |        ^~~~
a.cc: In function 'int main()':
a.cc:39:11: error: 'dfs' was not declared in this scope
   39 |   cout << dfs(H, W, 3).diff() << endl;
      |           ^~~