Language: C++

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

template<typename T>
void input(T &x) {
	x=0; T a=1;
	register char c=getchar();
	for(;c<48||c>57;c=getchar())
		if(c==45) a=-1;
	for(;c>=48&&c<=57;c=getchar())
		x=x*10+c-48;
	x*=a;
	return;
}

#define MAXN 200010

struct Ball {
	
	int x,y;

	void Input() {
		input(x),input(y);
		if(x>y) swap(x,y);
		return;
	}

	bool operator < (const Ball &q) const {
		if(x!=q.x) return x<q.x;
		return y<q.y;
	}

};

Ball a[MAXN];

#define inf 2147483647

int main() {
	int n;
	input(n);
	if(n==1) {
		puts("0");
//		fclose(stdin),fclose(stdout);
		return 0;
    }
	for(int i=1;i<=n;i++) a[i].Input();
	sort(a+1,a+n+1);
	int Max=0,Min=inf,pos_Max,pos_Min;
	for(int i=1;i<=n;i++) {
		if(a[i].x<Min) Min=a[pos_Min=i].x;
		if(a[i].y>Max) Max=a[pos_Max=i].y;
	}
	int Rmax=Max,Rmin=inf,Bmin=Min,Bmax=0;
	for(int i=1;i<=n;i++) {
		Rmin=min(Rmin,a[i].y),
		Bmax=max(Bmax,a[i].x);
	}
	ll ans=(ll)(Rmax-Rmin)*(Bmax-Bmin);
	if(pos_Max!=pos_Min) {
		Bmax=Max,Bmin=Min,Rmax=a[n].x;
		ll Ans=inf;
		for(int i=1,j=a[1].y;i<n;i++) {
			Rmax=max(a[i].y,Rmax),
			Rmin=min(min(j,a[i].y),a[i+1].x),
			j=min(j,a[i].y),
			Ans=min(Ans,Rmax-Rmin);
		}
		ans=min(ans,Ans*(Bmax-Bmin));
	}
	printf("%lld\n",ans);
	return 0;
}


Compiler output:
a.cc: In function 'void input(T&)':
a.cc:10:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   10 |         register char c=getchar();
      |                       ^
a.cc: In function 'int main()':
a.cc:70:32: error: no matching function for call to 'min(ll&, int)'
   70 |                         Ans=min(Ans,Rmax-Rmin);
      |                             ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:3:
/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:70:32: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   70 |                         Ans=min(Ans,Rmax-Rmin);
      |                             ~~~^~~~~~~~~~~~~~~
/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:70:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   70 |                         Ans=min(Ans,Rmax-Rmin);
      |                             ~~~^~~~~~~~~~~~~~~
a.cc: In instantiation of 'void input(T&) [with T = int]':
a.cc:26:8:   required from here
   26 |                 input(x),input(y);
      |                 ~~~~~^~~
a.cc:10:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   10 |         register char c=getchar();
      |                       ^