muteki_gakoi_movement = { '7 9' => '6 8', '2 8' => '5 8', '3 9' => '4 8' } movement = {} gets.to_i.times do x1, y1, x2, y2 = gets.split.map(&:to_i) movement[[x1, y1].join(' ')] = [x2, y2].join(' ') end puts muteki_gakoi_movement.all? { |start_p, end_p| before, current = nil, start_p while current = movement[current] break true if current == end_p break false if before == movement[current] before = current end } ? 'YES' : 'NO'