#[macro_export] macro_rules! setup { { mut $input:ident: SplitWhitespace $(,)? } => { use std::io::Read; let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut $input = buf.split_whitespace(); }; } #[macro_export] macro_rules! parse_next { ($str_iter:expr) => { $str_iter.next().unwrap().parse().unwrap() }; } use std::collections::HashSet; fn main() { setup! { mut input: SplitWhitespace }; let n: usize = parse_next!(input); let mut a: Vec = vec![]; let mut b: Vec = vec![]; let mut c: Vec = vec![]; let mut d: Vec = vec![]; let mut r: Vec = vec![]; (0..n).for_each(|_| { a.push(parse_next!(input)); b.push(parse_next!(input)); c.push(parse_next!(input)); d.push(parse_next!(input)); r.push(parse_next!(input)); }); let mut nums = HashSet::new(); (0..=9).for_each(|num| { nums.insert(num); }); for i in 0..n { match r[i].as_str() { "YES" => { for num in 0..=9 { if num == a[i] { continue; } if num == b[i] { continue; } if num == c[i] { continue; } if num == d[i] { continue; } nums.remove(&num); } } "NO" => { nums.remove(&a[i]); nums.remove(&b[i]); nums.remove(&c[i]); nums.remove(&d[i]); } _ => unreachable!(), } } let ans = nums.iter().nth(0).unwrap().clone(); println!("{}", ans); }