const MOD: i64 = 998244353; fn main() { input! { n: i64, x: i64, y: i64, a: [i64;x], b: [i64;y], } const BIT_MX: i64 = 5; let mut ans = 0; for bit in 0..BIT_MX { let a_sum = a .iter() .map(|&x| if (x >> bit) & 1 == 1 { 1 } else { 0 }) .collect::>() .iter() .sum::(); let b_sum = b .iter() .map(|&x| if (x >> bit) & 1 == 1 { 1 } else { 0 }) .collect::>() .iter() .sum::(); let mut dp = [1, 0]; for _ in 0..n { let mut tmp = [0; 2]; tmp[0] = (x - a_sum) * dp[0]; tmp[0] %= MOD; tmp[1] = a_sum * (dp[0] + dp[1]) + (x - a_sum) * dp[1]; tmp[1] %= MOD; dp = tmp; tmp[0] = b_sum * dp[0] + (y - b_sum) * (dp[0] + dp[1]); tmp[0] %= MOD; tmp[1] = b_sum * dp[1]; tmp[1] %= MOD; dp = tmp; } ans += (1 << bit) * dp[1] % MOD; ans %= MOD; } println!("{}", ans) } /* マクロ */ #[macro_export] 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_export] 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_export] 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, bytes) => { read_value!($iter, String).bytes().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; }