#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { ll l, r, c; cin >> l >> r >> c; ll ans = 1e18; for (int x = l; x <= min(l + 1000, r); x++) { ll price = x * c; ans = min(ans, (1000 - price % 1000) % 1000); } cout << ans << endl; return 0; }