use std::collections::VecDeque; use std::io::*; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let mut q: Vec> = vec![VecDeque::new(); n]; for i in 0..n { let p: usize = itr.next().unwrap().parse().unwrap(); for _ in 0..p { let a: usize = itr.next().unwrap().parse().unwrap(); q[i].push_back(a); } } let mut out = Vec::new(); loop { let mut ok = false; for i in 0..n { if let Some(x) = q[i].pop_front() { ok = true; write!(out, "{} ", x).ok(); } } if !ok { break; } } let m = out.len(); out[m - 1] = '\n' as u8; stdout().write_all(&out).unwrap(); }