fn main() { let mut hw = String::new(); std::io::stdin().read_line(&mut hw).ok(); let hw: Vec = hw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let h = hw[0]; let w = hw[1]; let mut xs: Vec = vec![]; for _ in 0 .. h { let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); a.trim().split_whitespace().map(|s| s.parse::().unwrap()).for_each(|i| xs.push(i)); } xs.sort(); for i in 0..h { println!("{}", xs.iter().skip(i*w).take(w).map(|x| x.to_string()).collect::>().join(" ")); } }