macro_rules! scan_iter { ($buf:expr) => {{ use std::io::{stdin, BufRead}; use std::str::FromStr; $buf.clear(); stdin().lock().read_line(&mut $buf).unwrap(); $buf.trim() .split(" ") .map(|x| FromStr::from_str(x).unwrap()) }}; } macro_rules! scan_vec { ($buf:expr) => { scan_iter!($buf).collect::>() }; } macro_rules! scan_into { ($buf:expr) => { scan_vec!($buf).try_into().unwrap() }; } fn main() { let mut b = String::new(); let [l, r, c]: [i32; 3] = scan_into!(b); println!( "{}", (l..=r) .map(|x| match 1000 - (c * x) % 1000 { 1000 => 0, y => y, }) .min() .unwrap() ); }