struct Frac { n: i64, d: i64, } impl Frac { fn cmp(&self, other: &Self) -> std::cmp::Ordering { (other.d * self.n).cmp(&(self.d * other.n)) } } fn main() { let mut xx = String::new(); std::io::Read::read_to_string(&mut std::io::stdin(), &mut xx).ok(); let xx: Vec = xx.split_whitespace().skip(1).flat_map(str::parse).collect(); let mut fractions: Vec = xx.chunks(2).map(|x| Frac { n: x[0], d: x[1] }).collect(); fractions.sort_unstable_by(Frac::cmp); fractions.reverse(); for f in fractions { println!("{} {}", f.n, f.d); } }