Language: C++

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

bool comp1(pair<int, int> a, pair<int, int> b){
    return max(a.first, a.second) < max(b.first, b.second);
}

bool comp2(pair<int, int> a, pair<int, int> b){
    return a.first < b.first;
}

bool comp3(pair<int, int> a, pair<int, int> b){
    return a.second < b.second;
}

bool comp4(pair<int, int> a, pair<int, int> b){
    return min(a.first, a.second) < min(b.first, b.second);
}

int main(void) {
    int n, ans = 0;
    vector<pair<int, int>> r1, r2, r3, b1, b2, b3;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (a > b) r1.push_back({a, b});
        if (a == b) r3.push_back({a, b});
        if (a < b) r2.push_back({a, b});
    }
    for (int i = 0; i < n; i++) {
        int c, d;
        cin >> c >> d;
        b1.push_back({c, d});
        b2.push_back({c, d});
        b3.push_back({c, d});
    }
    sort(r3.begin(), r3.end(), comp1);
    sort(r1.begin(), r1.end(), comp2);
    sort(r2.begin(), r2.end(), comp3);
    sort(b1.begin(), b1.end(), comp2);
    sort(b2.begin(), b2.end(), comp3);
    sort(b3.begin(), b3.end(), comp4);
    for (int i = 0; i < n; i++) {
        int now = -1;
        if (r[i].first > r[i].second) {
            for (int j = 0; j < b1.size(); j++) {
                if (r[i].first < b1[j].first && r[i].second < b1[j].second) {
                    ans++;
                    cout << r[i].first << ' ' << r[i].second << ' ' << b1[j].first << ' ' << b1[j].second << endl;
                    b2.erase(find(b2.begin(), b2.end(), b1[j]));
                    b3.erase(find(b3.begin(), b3.end(), b1[j]));
                    b1.erase(b1.begin() + j);
                    break;
                }
            }
        }
        if (r[i].first == r[i].second) {
            for (int j = 0; j < b3.size(); j++) {
                if (r[i].first < b3[j].first && r[i].second < b3[j].second) {
                    ans++;
                    cout << r[i].first << ' ' << r[i].second << ' ' << b3[j].first << ' ' << b3[j].second << endl;
                    b2.erase(find(b2.begin(), b2.end(), b3[j]));
                    b1.erase(find(b1.begin(), b1.end(), b3[j]));
                    b3.erase(b3.begin() + j);
                    break;
                }
            }
        }
        if (r[i].second > r[i].first) {
            for (int j = 0; j < b2.size(); j++) {
                if (r[i].first < b2[j].first && r[i].second < b2[j].second) {
                    ans++;
                    cout << r[i].first << ' ' << r[i].second << ' ' << b2[j].first << ' ' << b2[j].second << endl;
                    b1.erase(find(b1.begin(), b1.end(), b2[j]));
                    b3.erase(find(b3.begin(), b3.end(), b1[j]));
                    b2.erase(b2.begin() + j);
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:46:13: error: 'r' was not declared in this scope
   46 |         if (r[i].first > r[i].second) {
      |             ^
a.cc:58:13: error: 'r' was not declared in this scope
   58 |         if (r[i].first == r[i].second) {
      |             ^
a.cc:70:13: error: 'r' was not declared in this scope
   70 |         if (r[i].second > r[i].first) {
      |             ^