#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP_OVERLOAD(arg1, arg2, arg3, arg4, NAME, ...) NAME #define REP3(i, l, r, s) \ for (int i = int(l), rep3_r = int(r), rep3_s = int(s); i < rep3_r; \ i += rep3_s) #define REP2(i, l, r) REP3(i, l, r, 1) #define REP1(i, n) REP2(i, 0, n) #define rep(...) REP_OVERLOAD(__VA_ARGS__, REP3, REP2, REP1, )(__VA_ARGS__) #define repin(i, l, r) for (int i = int(l), repin_r = int(r); i <= repin_r; ++i) #define RREP_OVERLOAD(arg1, arg2, arg3, arg4, NAME, ...) NAME #define RREP3(i, l, r, s) \ for (int i = int(r) - 1, rrep3_l = int(l), rrep3_s = int(s); i >= rrep3_l; \ i -= rrep3_s) #define RREP2(i, l, r) RREP3(i, l, r, 1) #define RREP1(i, n) RREP2(i, 0, n) #define rrep(...) RREP_OVERLOAD(__VA_ARGS__, RREP3, RREP2, RREP1, )(__VA_ARGS__) #define rrepin(i, l, r) \ for (int i = int(r), rrepin_l = int(l); i >= rrepin_l; --i) #include #include #include #include namespace rklib { // a <- max(a, b) template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } // a <- min(a, b) template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } // if a < 0: a <- b // else: a <- min(a, b) template bool chmin_non_negative(T &a, const T &b) { if (a < 0 || a > b) { a = b; return true; } return false; } // floor(num / den) template T div_floor(T num, T den) { if (den < 0) num = -num, den = -den; return num >= 0 ? num / den : (num + 1) / den - 1; } // ceil(num / den) template T div_ceil(T num, T den) { if (den < 0) num = -num, den = -den; return num <= 0 ? num / den : (num - 1) / den + 1; } namespace internal { template T remainder_count(T r, T b, T m) { return r / m * b + std::min(b, r % m); } } // namespace internal // Number of integer x s.t. // - x in [l, r) // - x mod m in [a, b) template T remainder_count(T l, T r, T a, T b, T m) { assert(l >= 0); assert(m >= 1); if (l >= r || a >= b) return 0; if (m <= a || b < 0) return 0; chmax(a, T(0)); chmin(b, m); auto res = internal::remainder_count(r, b, m); if (l >= 1) res -= internal::remainder_count(l, b, m); if (a >= 1) res -= internal::remainder_count(r, a, m); if (l >= 1 && a >= 1) res += internal::remainder_count(l, a, m); return res; } } // namespace rklib using namespace std; using namespace rklib; using lint = long long; using pii = pair; using pll = pair; int main() { int n; cin >> n; vector x(n), y(n); rep(i, n) cin >> x[i] >> y[i]; vector ys[8010]; // (y, idx) rep(i, n) ys[x[i]].push_back({y[i], i}); { int cur = 0; rep(i, n) if (!ys[i].empty()) { if (cur % 2 == 0) { sort(ys[i].begin(), ys[i].end()); } else { sort(ys[i].begin(), ys[i].end(), greater<>()); } ++cur; } } vector vs; rep(i, 8010) for (auto [y, idx] : ys[i]) vs.push_back(idx + 1); cout << vs.size() / 2 << "\n"; rep(i, 0, vs.size(), 2) { cout << vs[i] << " " << vs[i + 1] << "\n"; } }