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 result: 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| result.push(i)); } result.sort(); for j in 0..h { println!("{}", result.iter().skip(j*w).take(w).map(|i| i.to_string()).collect::>().join(" ")); } }