use amplitude::Amplitude; fn main() { let n = { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.trim().parse::().unwrap() }; let xy: Vec<_> = (0..n) .map(|_| { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse::().unwrap(), iter.next().unwrap().parse::().unwrap(), ) }) .collect(); let mut amplitudes: Vec<_> = xy .iter() .enumerate() .map(|(i, &(x, y))| (Amplitude::new(x, y), i)) .collect(); amplitudes.sort_unstable_by_key(|x| x.0); let mut ans = vec![]; for i in (0..(n - 1)).step_by(2) { ans.push((amplitudes[i].1, amplitudes[i + 1].1)) } println!("{}", ans.len()); for e in ans { println!("{} {}", e.0 + 1, e.1 + 1); } } pub mod amplitude { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Amplitude { pub x: usize, pub y: usize, } impl PartialOrd for Amplitude { fn partial_cmp(&self, other: &Self) -> Option { if self.x == other.x { self.y.partial_cmp(&other.y) } else { self.x.partial_cmp(&other.x) } } } impl Ord for Amplitude { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.partial_cmp(other).unwrap() } } impl Amplitude { pub fn new(x: usize, y: usize) -> Self { Self { x, y } } } }