#include #include #include #include using namespace std; const long long Target = 500000000000000000LL; void Operation(vector& A, vector& B, int idx1, int idx2) { long long avg1 = (A[idx1] + A[idx2]) / 2LL; long long avg2 = (B[idx1] + B[idx2]) / 2LL; A[idx1] = avg1; B[idx1] = avg2; A[idx2] = avg1; B[idx2] = avg2; } int main() { // Step 1. 入力 vector A(50, 0); vector B(50, 0); long long N; cin >> N; for (int i = 0; i < N; i++) cin >> A[i] >> B[i]; // Step 2. 最初のステップ vector> Answer; long long MinV = (1LL << 60); long long MinID = -1; for (int i = 1; i < N; i++) { long long v1 = (A[0] + A[i]) / 2LL; long long v2 = (B[0] + B[i]) / 2LL; long long err = min(abs(v1 - Target), abs(v2 - Target)); if (MinV > err) { MinV = err; MinID = i; } } Operation(A, B, 0, MinID); Answer.push_back(make_pair(0, MinID)); // Step 3. 貪欲法 long long RemainA = Target * 2 - A[0]; long long RemainB = Target * 2 - B[0]; vector Used(N, false); vector Order; Order.push_back(0); while (true) { vector> Vec; for (int i = 1; i < N; i++) { if (Used[i] == true) continue; long long v1 = abs(RemainA - A[i]); if (v1 >= RemainA) continue; long long v2 = abs(RemainB - B[i]); if (v2 >= RemainB) continue; Vec.push_back(make_pair(max(v1, v2), i)); } sort(Vec.begin(), Vec.end()); if (Vec.size() == 0) break; int idx = Vec[0].second; RemainA = min(6LL * Target, 2LL * RemainA - A[idx]); RemainB = min(6LL * Target, 2LL * RemainB - B[idx]); Order.push_back(idx); Used[idx] = true; } for (int i = 1; i < N; i++) { if (Used[i] == false) Order.push_back(i); } // Step 4. 答えを出す for (int i = N - 2; i >= 0; i--) { Answer.push_back(make_pair(Order[i], Order[i + 1])); Operation(A, B, Order[i], Order[i + 1]); } // Step 5. 出力 cout << Answer.size() << endl; for (int i = 0; i < Answer.size(); i++) cout << Answer[i].first + 1 << " " << Answer[i].second + 1 << endl; return 0; }