fn g() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.split_whitespace().flat_map(str::parse).collect() } fn main() { let n = g(); let mut a = g(); let mut d = vec!["".to_owned(); n[0]]; let t: Vec<_> = (0..n[0]).map(|_| g()).collect(); for j in 0..n[1] { for i in 0..n[0] { let r = t[i][j]; if a[r] > 0 && d[i].is_empty() { d[i] = r.to_string(); a[r] -= 1; } } } println!("{}", d.join(" ")) }