#include using namespace std; using ll = long long; using ld = long double; using Pair = pair; using Tuple = tuple; using VI1 = vector; using VI2 = vector; using VL1 = vector; using VL2 = vector; using VD1 = vector; using VD2 = vector; using VB1 = vector; using VB2 = vector; using VP1 = vector; using VP2 = vector; using VT1 = vector; using VT2 = vector; using Queue = queue; using DQ = deque; using PQ = priority_queue, greater>; using Table = VI2; using Graph = VI2; /** io */ template std::vector input_vec(int N); template void output_row(std::vector &row); template void output_col(std::vector &col); void outputYesNo(bool yes, const string &Yes = "Yes", const string &No = "No"); /** minmax */ template bool chmin(T &a, T b); template bool chmax(T &a, T b); template T calc_gcd(T a, T b) { if (b == 0) return a; return calc_gcd(b, a % b); } template T calc_lcm(T a, T b) { assert(a > 0 && b > 0); T gcd = calc_gcd(a, b); return a / gcd * b; } auto solve() { int N; cin >> N; VI1 x(N), y(N); for (int i = 0; i < N; ++i) { cin >> x.at(i) >> y.at(i); } VT1 x_y_I(N); for (int i = 0; i < N; ++i) { x_y_I.at(i) = {x.at(i), y.at(i), i}; } sort(x_y_I.begin(), x_y_I.end()); VI1 to(N, -1); for (auto [xi, yi, i] : x_y_I) { if (to.at(i) != -1) continue; map mp; for (int j = 0; j < N; ++j) { if (i == j || to.at(j) != -1) continue; auto xj = x.at(j), yj = y.at(j); auto dx = xj - xi, dy = yj - yj; auto d2 = dx * dx + dy * dy; auto gcd = calc_gcd(abs(dx), abs(dy)); mp[Pair{dx / gcd, dy / gcd}].emplace_back(d2, j); } for (auto &[p, vec] : mp) { sort(vec.begin(), vec.end()); auto [_, j] = vec.at(0); if (to.at(j) != -1) continue; to.at(i) = j; to.at(j) = i; break; } } VP1 zw; for (int i = 0; i < N; ++i) { auto ti = to.at(i); if (ti == -1) continue; zw.emplace_back(i + 1, ti + 1); to.at(i) = to.at(ti) = -1; } return zw; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { auto result = solve(); // cout << result << '\n'; cout << result.size() << '\n'; for (auto [zi, wi] : result) { cout << zi << ' ' << wi << '\n'; } // output_row(result); // output_col(result); // outputYesNo(result, "Yes", "No"); } } /** @note 使用頻度が高く毎回貼付するのが面倒なライブラリを実装しておく。*/ template std::vector input_vec(int N) { std::vector v(N); for (auto &vi : v) { cin >> vi; } return v; } void outputYesNo(bool yes, const string &Yes, const string &No) { if (yes) cout << Yes << '\n'; else cout << No << '\n'; } template void output_row(std::vector &row) { int N = row.size(); for (int i = 0; i < N; ++i) { if (i > 0) cout << ' '; cout << row.at(i); } cout << '\n'; } template void output_col(std::vector &col) { int N = col.size(); for (int i = 0; i < N; ++i) { cout << col.at(i) << '\n'; } } template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }