use std::collections::HashMap; fn main() { let (n, m) = { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); let mut iter = line.split_whitespace(); ( iter.next().unwrap().parse::().unwrap(), iter.next().unwrap().parse::().unwrap(), ) }; let aa: Vec<_> = { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|x| x.parse::().unwrap()) .collect() }; let bb: Vec<_> = { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|x| x.parse::().unwrap()) .collect() }; let cc: Vec<_> = { let mut line = String::new(); std::io::stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|x| x.parse::().unwrap()) .collect() }; let mut diff = vec![0; n]; let mut cur = 0; for (i, &a) in aa.iter().enumerate() { diff[i] = cur - a; cur += bb[i % m]; } let mut counter: HashMap = HashMap::new(); for (i, &d) in diff.iter().enumerate() { *counter.entry(d).or_default() += cc[i]; } let ans = cc.iter().sum::() - counter.values().max().unwrap(); println!("{}", ans); }