use std::io::{self, BufWriter, Read, Write}; struct Scanner<'a>(std::str::SplitWhitespace<'a>); impl<'a> Scanner<'a> { fn new(s: &'a str) -> Self { Self(s.split_whitespace()) } fn next(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, { let s = self.0.next().expect("found EOF"); match s.parse() { Ok(v) => v, Err(msg) => { println!( "parse error. T = {}, s = \"{}\": {:?}", std::any::type_name::(), s, msg ); panic!() } } } } const MOD: u64 = 1000000007; fn normalize(mut x: i32) -> u64 { if x < 0 { x += MOD as i32; } return x as u64; } fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = Scanner::new(&s); let stdout = io::stdout(); let mut stdout = BufWriter::new(stdout.lock()); let k = sc.next::(); let n = sc.next::(); let m = sc.next::(); let a = (0..k).map(|_| normalize(sc.next())).collect::>(); let c = (0..k).map(|_| normalize(sc.next())).collect::>(); let mut ls = vec![0; n + 1]; let mut rs = vec![Vec::new(); n + 1]; for _ in 0..m { let (l, r) = (sc.next::(), sc.next::()); ls[l] += 1; rs[r].push(r - l); } let step = |seq: &mut Vec| { let next = (0..k).fold(0, |x, i| (x + c[i] * seq[k - 1 - i]) % MOD); seq.remove(0); seq.push(next); }; let base = { let mut state = a.clone(); (0..n) .map(move |_| { let res = state.clone(); step(&mut state); res }) .collect::>() }; let mut now = vec![0; k]; for i in 0..n { step(&mut now); for j in 0..k { now[j] += ls[i] * a[j]; now[j] %= MOD; } for &r in &rs[i] { for j in 0..k { now[j] += MOD - base[r][j]; now[j] %= MOD; } } writeln!(stdout, "{}", now[0]).unwrap(); } stdout.flush().unwrap(); }