Language: C++

#include<bits/stdc++.h>
using namespace std;

int main(){
	int H,W;
	cin >> H >> W;
	long long ans;
	int hei,wid;
	long long S1,S2,mini;
	if(H%3==0||W%3==0){
		ans=0;
	}else if(H%2==0){
		 hei=H/2;
		 wid=W/3;
		 mini = hei*(W-3*wid);
		 wid++;
		 S1=hei*wid*2;
		 S2=hei*(W-wid);
		 while(abs(S2-S1)<mini){
			 mini=abs(S2-S1);
			 wid++;
			 S1=hei*wid*2;
			 S2=hei*(W-wid);
		 }
		 ans=mini;
	}else if(W%2==0){
		hei=H/3;
		wid=W/2;
		mini=wid*(H-hei*3);
		hei++;
		S1=wid*hei*2;
		S2=wid*(H-hei);
		while(abs(S2-S1)<mini){
			mini=abs(S2-S1);
			hei++;
			S1=wid*hei*2;
			S2=wid*(H-hei);
		}
		ans=mini;
	}else{
		hei=H/2;
		wid=W/2;
		mini=H*(W-wid)-hei*wid;
		wid++;
		S1=hei*wid;
		S2=H*(W-wid);
		while(min(abs(S2-S1),wid)<mini){
			mini=min(abs(S2-S1),wid);
			wid++;
			S1=hei*wid;
			S2=H*(W-wid);
		}
		ans=mini;
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:26: error: no matching function for call to 'min(long long int, int&)'
   47 |                 while(min(abs(S2-S1),wid)<mini){
      |                       ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/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:47:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   47 |                 while(min(abs(S2-S1),wid)<mini){
      |                       ~~~^~~~~~~~~~~~~~~~
/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:
/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:47:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   47 |                 while(min(abs(S2-S1),wid)<mini){
      |                       ~~~^~~~~~~~~~~~~~~~
a.cc:48:33: error: no matching function for call to 'min(long long int, int&)'
   48 |                         mini=min(abs(S2-S1),wid);
      |                              ~~~^~~~~~~~~~~~~~~~
/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:48:33: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   48 |                         mini=min(abs(S2-S1),wid);
      |                              ~~~^~~~~~~~~~~~~~~~
/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:48:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   48 |                         mini=min(abs(S2-S1),wid);
      |                              ~~~^~~~~~~~~~~~~~~~