#![allow(non_snake_case, unused_must_use, unused_imports)] use std::io::{self, prelude::*}; fn main() { let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout()); let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock())); macro_rules! input { ($t: tt, $n: expr) => { (0..$n).map(|_| input!($t)).collect::>() }; (Chars) => { input! {String}.chars().collect::>() }; (Usize1) => { stdin.next().unwrap().parse::().unwrap() - 1 }; ($t: ty) => { stdin.next().unwrap().parse::<$t>().unwrap() }; } let a = input!(usize); let b = input!(usize); let T = input!(usize, a); let S = input!(usize, b); let mut g = T[0]; for i in 1..a { g = gcd(g, T[i]); } let mut isok = true; for i in 0..(std::cmp::min(a, b)) { if T[i].abs_diff(S[i]) % g != 0 { isok = false; break; } } writeln!(buffer, "{}", if isok { "Yes" } else { "No" }); } fn gcd(a: usize, b: usize) -> usize { if a < b { return gcd(b, a); } if b == 0 { return a; } else { return gcd(b, a % b); } }