($l,$r,$c)=glob<>; $r=$l+999 if $r>$l+999; $z=1000; for($l..$r){ $y=-$_*$c%1000; $z=$y if $z>$y; } print$z;