Language: C++

#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
ll int MOD=998244353;
#define INF 1e9
#define N 310000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int n;
    cin>>n;
    vector<pii> v;
    ll int x[N],y[N];
    rep(i,n){
        cin>>x[i]>>y[i];
        v.pb({x[i],i});v.pb({y[i],i});
    }
    sort(v.begin(),v.end());
    rep(i,n){
        if(x[i]<y[i]) swap(x[i],y[i]);
    }
    ll int xM=0,xm=INF,yM=0,ym=INF;
    rep(i,n){
        if(x[i]>xM) xM=x[i];
        if(x[i]<xm) xm=x[i];
        if(y[i]>yM) yM=y[i];
        if(y[i]<ym) ym=y[i];
    }
    ll int ans1=(xM-xm)*(yM-ym);
    ll int a=v[0],b=v[2*n-1];
    pqg p;
    ll int d=0;
    rep(i,n){
        if(y[i]==a){
            p.push({x[i],i});
            d=max(d,x[i]);
        }
        else {
            p.push({y[i],i});
            d=max(d,y[i]);
        }
    }
    ll int c=p.top().first,range=d-c;
    while(1){
        pii pp=p.front();
        if(pp.first==x[pp.second]){
            break;
        }
        else if(x[pp.second]!=b){
            p.pop();
            p.push({x[pp.second],pp.second});
            c=p.top().first;d=max(d,x[pp.second]);
            range=min(range,d-c);
        }
        else break;
    }
    ll ans2=(b-a)*range;
    cout<<min(ans1,ans2);
    return 0;
}


Compiler output:
a.cc:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   17 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:38:17: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'long long int' in initialization
   38 |     ll int a=v[0],b=v[2*n-1];
      |                 ^
a.cc:38:28: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'long long int' in initialization
   38 |     ll int a=v[0],b=v[2*n-1];
      |                            ^
a.cc:43:19: error: no matching function for call to 'std::priority_queue<int, std::vector<int>, std::greater<int> >::push(<brace-enclosed initializer list>)'
   43 |             p.push({x[i],i});
      |             ~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = int; _Sequence = std::vector<int>; _Compare = std::greater<int>; value_type = int]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<int, std::vector<int>, std::greater<int> >::value_type&' {aka 'const int&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = int; _Sequence = std::vector<int>; _Compare = std::greater<int>; value_type = int]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<int, std::vector<int>, std::greater<int> >::value_type&&' {aka 'int&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:47:19: error: no matching function for call to 'std::priority_queue<int, std::vector<int>, std::greater<int> >::push(<brace-enclosed initializer list>)'
   47 |             p.push({y[i],i});
      |             ~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = int; _Sequence = std::vector<int>; _Compare = std::greater<int>; value_type = int]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<int, std::vector<int>, std::greater<int> >::value_type&' {aka 'const int&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = int; _Sequence = std::vector<int>; _Compare = std::greater<int>; value_type = int]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<int, std::vector<int>, std::greater<int> >::value_type&&' {aka 'int&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:51:22: error: request for member 'first' in 'p.std::priority_queue<int, std::vector<int>, std::greater<int> >::top()', which is of non-class type 'const __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'const int'}
   51 |     ll int c=p.top().first,range=d-c;
      |                      ^~~~~
a.cc:53:18: error: 'class std::priority_queue<int, std::vector<int>, std::greater<int> >' has no member named 'front'
   53 |         pii pp=p.front();
      |                  ^~~~~
a.cc:59:19: error: no matching function for call to 'std::priority_queue<int, std::vector<int>, std::greater<int> >::push(<brace-enclosed initializer list>)'
   59 |             p.push({x[pp.second],pp.second});
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = int; _Sequence = std::vector<int>; _Compare = std::greater<int>; value_type = int]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<int, std::vector<int>, std::greater<int> >::value_type&' {aka 'const int&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = int; _Sequence = std::vector<int>; _Compare = std::greater<int>; value_type = int]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<int, std::vector<int>, std::greater<int> >::value_type&&' {aka 'int&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:60:23: error: request for member 'first' in 'p.std::priority_queue<int, std::vector<int>, std::greater<int> >::top()', which is of non-class type 'const __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'const int'}
   60 |             c=p.top().first;d=max(d,x[pp.second]);
      |                       ^~~~~
a.cc:61:13: error: 'range' was not declared in this scope
   61 |             range=min(range,d-c);
      |             ^~~~~
a.cc:65:19: error: 'range' was not declared in this scope
   65 |     ll ans2=(b-a)*range;
      |                   ^~~~~