#include using namespace std; #define all(v) (v).begin(),(v).end() #define pb(a) push_back(a) #define rep(i, n) for(int i=0;i> n; vector>> dog(10000); ll a, b; rep(i, n) { cin >> a >> b; dog[b].push_back({a, i + 1}); } rep(i, 10000) sort(all(dog[i])); ll p = -1; vector> ans; rep(i, 10000) { int s = dog[i].size(); if(s == 0) continue; if(p == -1) { rep(j, s / 2) { ans.push_back({dog[i][j * 2].second, dog[i][j * 2 + 1].second}); } if(s&1) p = dog[i].back().second; } else { ans.push_back({p, dog[i][0].second}); p = -1; rep(j, (s - 1) / 2) { ans.push_back({dog[i][j * 2 + 1].second, dog[i][j * 2 + 2].second}); } if(s % 2 == 0) p = dog[i].back().second; } } cout << ans.size() << endl; for(auto [x, y] : ans) cout << x << " " << y << endl; return 0; }