using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(long.Parse).ToArray(); var L = input[0]; var R = input[1]; var C = input[2]; var min = 999L; for (long i = L; i <= R; i++) { var charge = 1000 - (C * i) % 1000; if (charge == 1000) { min = 0; break; } min = Math.Min(min, charge); } Console.WriteLine(min); } }