fn main() { let mut input = String::new(); std::io::Read::read_to_string(&mut std::io::stdin(), &mut input).ok(); let input: Vec = input .split_whitespace() .map(|n| n.parse().unwrap()) .collect(); let d = input[1]; let mut income = (0, -d); for tk in input[2..].chunks(2) { income = ( income.0.max(income.1 - d) + tk[0], income.1.max(income.0 - d) + tk[1], ); } println!("{}", income.0.max(income.1)); }