// Input macro macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! stdin { () => {{ use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }}; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // Test Code macro_rules! test { ($($input:expr => $output:expr),* $(,)*) => { #[test] fn solve_test() { $( assert_eq!(solve($input), $output); )* } }; } test! { // テストコードをここにコピペする r"3 7 9 6 8 2 8 5 8 3 9 4 8" => "YES", } fn main() { println!("{}", solve(&stdin!())); } fn solve(src: &str) -> String { input! { source = src, n: i32, // 問題に合わせて記述 procs: [[(i32,i32); 2]; n] } let mut a = (2,8); let mut b = (3,9); let mut c = (7,9); for proc in procs { match proc[0] { given if given == a => a = proc[1], given if given == b => b = proc[1], given if given == c => c = proc[1], _ => continue }; } if a == (5,8) && b == (4,8) && c == (6,8) { return "YES".to_string(); } else { return "NO".to_string(); } }