#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> l >> r >> c; c %= 1000; vector x(1000,false); for(ll i=l;i<=r;i++){ if(x[(i*c)%1000]) break; chmin(ans, (1000-(i*c)%1000)%1000); x[(i*c)%1000] = true; } cout << ans << '\n'; return 0; }