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 { let sq_dist_1 = self.x.pow(2) + self.y.pow(2); let sq_dist_2 = other.x.pow(2) + other.y.pow(2); if self.x == 0 && other.x == 0 { sq_dist_1.partial_cmp(&sq_dist_2) } else if self.x == 0 { Some(std::cmp::Ordering::Greater) } else if other.x == 0 { Some(std::cmp::Ordering::Less) } else { let frac1 = other.x * self.y; let frac2 = self.x * other.y; if frac1 == frac2 { sq_dist_1.partial_cmp(&sq_dist_2) } else { frac1.partial_cmp(&frac2) } } } } 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 } } } }