use std::io::{self, Read}; fn main() { let mut input = String::new(); io::stdin().read_to_string(&mut input).unwrap(); let mut it = input.split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let w: usize = it.next().unwrap().parse().unwrap(); let mut x = vec![0_usize; n]; let mut max_x = 0_usize; for v in &mut x { *v = it.next().unwrap().parse().unwrap(); max_x = max_x.max(*v); } let mut value_sum = vec![0_u64; max_x + 1]; for &weight in &x { let y: u64 = it.next().unwrap().parse().unwrap(); value_sum[weight] += y; } let mut ans = 0_u64; for d in w..=max_x { let mut total = 0_u64; let mut multiple = d; while multiple <= max_x { total += value_sum[multiple]; multiple += d; } ans = ans.max(total); } println!("{}", ans); }