#![allow(unused_mut, non_snake_case, unused_imports, dead_code,unused_macros)] use std::iter; use std::cmp::{max, min, Ordering}; use std::mem::swap; use std::collections::{HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap,VecDeque}; use std::iter::FromIterator; // 高速 EOF要 //macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut 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! 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")};} // 低速 EOF不要 macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};} macro_rules! mut_input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() }; mut_input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()}; mut_input_inner!{next, $($r)*}};} macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};} macro_rules! mut_input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let mut $var = read_value!($next, $t);mut_input_inner!{$next $($r)*}};} macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::>()};($next:expr, chars) => {read_value!($next, String).chars().collect::>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};} // 非常時 fn read_line() -> String { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); s.trim().to_string() } fn read_vec() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } fn solve(){ input!(N:usize,info:[(usize,usize,usize,usize);N]); let info:Vec<(usize,usize,usize,usize)> = info; let mut before = Vec::new(); let mut after = Vec::new(); let mut used = vec![false;N]; while true{ let mut update = false; for i in 0..N{ if used[i] { continue; } used[i] = true; before.push((info[i].0,info[i].1)); let mut nx = info[i].2; let mut ny = info[i].3; for j in i+1..N{ if (nx,ny) == (info[j].0,info[j].1){ used[j] = true; nx = info[j].2; ny = info[j].3; } } after.push((nx,ny)); } if update { continue; } break; } let n = before.len(); let mut cnt = 0; let (mut f1,mut f2,mut f3) = (false,false,false); for i in 0..n{ if (2,8) == before[i] && (5,8) == after[i] { f1 = true; } if (3,9) == before[i] && (4,8) == after[i] { f2 = true; } if (7,9) == before[i] && (6,8) == after[i] { f3 = true; } } println!("{}", if f1 && f2 && f3 { "YES"} else {"NO"}); } fn main() { let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); }