Problem p02983 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
  if (n == 0)
    return 1;
  if (n % 2)
    return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
  return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact_memo[114514];
int fact(int n) {
  int ans = 1;
  if (fact_memo[n])
    return fact_memo[n];
  rep(i, n) {
    ans *= (i + 1);
    if (mod <= ans)
      ans %= mod;
  }
  return (ans + mod) % mod;
}

int comb(int n, int r) {
  if (n < r)
    return 0;
  if (n - r < r)
    r = n - r;
  return (fact(n) * modpow(fact(n - r), mod - 2) % mod *
              modpow(fact(r), mod - 2) +
          mod) %
         mod;
}

int perm(int n, int r) {
  if (n < r)
    return 0;
  if (n - r < r)
    r = n - r;
  return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

bool pri(int p) {
  for (int i = 2; i * i <= p; i++)
    if (p % i == 0)
      return false;
  return p > 1;
}

int l, r;
int ans = inf;
signed main() {
  cin >> l >> r;
  rep(i, 2019) {
    if (r <= i)
      break;
    for (int j = r; j > l + i; j--) {
      ans = min(ans, (l + i) * j % 2019);
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
  if (n == 0)
    return 1;
  if (n % 2)
    return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
  return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact_memo[114514];
int fact(int n) {
  int ans = 1;
  if (fact_memo[n])
    return fact_memo[n];
  rep(i, n) {
    ans *= (i + 1);
    if (mod <= ans)
      ans %= mod;
  }
  return (ans + mod) % mod;
}

int comb(int n, int r) {
  if (n < r)
    return 0;
  if (n - r < r)
    r = n - r;
  return (fact(n) * modpow(fact(n - r), mod - 2) % mod *
              modpow(fact(r), mod - 2) +
          mod) %
         mod;
}

int perm(int n, int r) {
  if (n < r)
    return 0;
  if (n - r < r)
    r = n - r;
  return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

bool pri(int p) {
  for (int i = 2; i * i <= p; i++)
    if (p % i == 0)
      return false;
  return p > 1;
}

int l, r;
int ans = inf;
signed main() {
  cin >> l >> r;
  rep(i, 2019) {
    if (r <= i)
      break;
    for (int j = r; j > l + i; j--) {
      if (2019 < r - j)
        break;
      ans = min(ans, (l + i) * j % 2019);
    }
  }
  cout << ans << endl;
}