Language: C++

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

int main() {
    int N;
    cin >> N;
    vector<pair<ll, ll>> P(N);
    ll mi = 1e10, ma = 0, mi_index, ma_index; 
    for (int i = 0; i < N; i++) {
        ll X, Y;
        cin >> X >> Y;
        if (X > Y) swap(X, Y);
        P[i] = {X, Y};
    }
    sort(P.begin(), P.end());
    mi = P[0].first;
    mi_index = 0;
    
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (N == 2) {
        cout << min(abs((P[0].first-P[1].first)*(P[0].second-P[1].second)), abs((P[0].first-P[1].second)*(P[0].second-P[1].first)));
        return 0;
    }
    
    for (int i = 0; i < N; i++) {
        if (ma <= P[i].second) {
            ma = P[i].second;
            ma_index = i;
        }
    }
    
    ll cand1, cand2;
    ll rmin = mi, rmax = mi, bmax = ma, bmin = ma;
    for (int i = 0; i < N; i++) {
        rmax = max(rmax, P[i].first);
        bmin = min(bmin, P[i].second);
    }
    cand1 = (rmax-rmin)*(bmax-bmin);
    
    if (mi_index == ma_index) {
        cout << cand1 << endl;
        return 0;
    }
    
    rmin = mi; rmax = ma;
    bmin = min(P[mi_index].second, P[ma_index].first);
    bmax = max(P[mi_index].second, P[ma_index].first);
    ll l = bmax-bmin-1, r = 1e9+1;
    while (r-l > 1) {
        ll c = (l+r)/2;
        priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
        for (int i = 0; i < N; i++) {
            if (i == mi_index || i == ma_index) continue;
            pq.push({P[i].first, -1});
            pq.push({P[i].second+c, 1});
            if (P[i].second - P[i].first > c) {
                pq.push({P[i].first + c, 1});
                pq.push({P[i].second, -1}); 
            }
        }
        int cnt = 0;
        bool check = false;
        while (!pq.empty()) {
            ll now = pq.top().first;
            cnt -= pq.top().second;
            pq.pop();
            if (!((now >= bmin && now <= bmax+c) || (now >= bmax && now <= bmax+c))) continue;
            if (cnt == N-2) {
                check = true;
                break;
            }
        }
        if (check) r = c;
        else l = c;
    }
    
    cand2 = r * (rmax - rmin);
    
    cout << min(cand1, cand2) << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<pair<ll, ll>> P(N);
    ll mi = 1e10, ma = 0, mi_index, ma_index; 
    for (int i = 0; i < N; i++) {
        ll X, Y;
        cin >> X >> Y;
        if (X > Y) swap(X, Y);
        P[i] = {X, Y};
    }
    sort(P.begin(), P.end());
    mi = P[0].first;
    mi_index = 0;
    
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (N == 2) {
        cout << min(abs((P[0].first-P[1].first)*(P[0].second-P[1].second)), abs((P[0].first-P[1].second)*(P[0].second-P[1].first)));
        return 0;
    }
    
    for (int i = 0; i < N; i++) {
        if (ma <= P[i].second) {
            ma = P[i].second;
            ma_index = i;
        }
    }
    
    ll cand1, cand2;
    ll rmin = mi, rmax = mi, bmax = ma, bmin = ma;
    for (int i = 0; i < N; i++) {
        rmax = max(rmax, P[i].first);
        bmin = min(bmin, P[i].second);
    }
    cand1 = (rmax-rmin)*(bmax-bmin);
    
    if (mi_index == ma_index) {
        cout << cand1 << endl;
        return 0;
    }
    
    rmin = mi; rmax = ma;
    bmin = min(P[mi_index].second, P[ma_index].first);
    bmax = max(P[mi_index].second, P[ma_index].first);
    ll l = bmax-bmin-1, r = 1e9+1;
    while (r-l > 1) {
        ll c = (l+r)/2;
        priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
        for (int i = 0; i < N; i++) {
            if (i == mi_index || i == ma_index) continue;
            pq.push({P[i].first, -1});
            pq.push({P[i].second+c, 1});
            if (P[i].second - P[i].first > c) {
                pq.push({P[i].first + c, 1});
                pq.push({P[i].second, -1}); 
            }
        }
        int cnt = 0;
        bool check = false;
        while (!pq.empty()) {
            ll now = pq.top().first;
            cnt -= pq.top().second;
            pq.pop();
            if (!((now >= bmin && now <= bmax+c) || (now >= bmax && now <= bmax+c))) continue;
            if (cnt == N-2) {
                check = true;
                break;
            }
        }
        if (check) r = c;
        else l = c;
    }
    
    cand2 = r * (rmax - rmin);
    
    cout << min(cand1, cand2) << endl;
    return 0;
}


Compiler output:
a.cc:91:5: error: redefinition of 'int main()'
   91 | int main() {
      |     ^~~~
a.cc:5:5: note: 'int main()' previously defined here
    5 | int main() {
      |     ^~~~