use std::io::Read; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let (mut b, mut e) = (vec![], vec![]); s.split_whitespace() .skip(1) .collect::>() .chunks(2) .for_each(|v| match v[0] { "1" => b.push(v[1]), _ => e.push(v[1]), }); b.reverse(); println!("{}{}", b.join(""), e.join("")) }