fn main() { let mut xx = String::new(); std::io::stdin().read_line(&mut xx).ok(); let xx: Vec = xx.split_whitespace().flat_map(str::parse).collect(); let mut max = 0; for a in xx[0]..=xx[1] { for b in xx[2]..=xx[3] { max = max.max((a + b) % xx[4]); } } println!("{max}"); }