#![allow(non_snake_case, unused_imports)] use std::io::{self, prelude::*}; use std::str; fn main() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); macro_rules! input { ($T: ty) => { scan.token::<$T>() }; } macro_rules! input_line { ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::>() }; } let N = input!(usize); let K = input!(usize); let M1 = input!(usize); let A = input_line!(usize, M1); let M2 = input!(usize); let B = input_line!(usize, M2); // i 段目にきれいな状態で存在できる => dp[i] = true let mut dp = vec![false; N + 1]; dp[0] = true; let mut s = std::collections::BTreeSet::new(); for a in A { s.insert(a); } let mut t = std::collections::BTreeSet::new(); for b in B { t.insert(b); } for i in 0..N { if dp[i] && !s.contains(&(i + 1)) { dp[i + 1] = true; } if i + K <= N && dp[i] && !s.contains(&(i + K)) { dp[i + K] = true; } if !dp[i] && t.contains(&(i + 1)) { dp[i + 1] = true; } if i + K <= N && !dp[i] && t.contains(&(i + K)) { dp[i + K] = true; } } if dp[N] { println!("Yes"); } else { println!("No"); } } struct Scanner { reader: R, buf_str: Vec, buf_iter: str::SplitWhitespace<'static>, } impl Scanner { fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_whitespace(), } } fn token(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_whitespace()) } } } }