Problem p02724 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define un(x) x.erase(unique(all(x)), x.end())
#define xx first
#define yy second
#define pb push_back
#define all(v) v.begin(), v.end()

#define D(x) cerr << #x " = " << x << '\\n'
#define DBG cerr << "Hi!" << '\\n'

#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a) memset(a, -1, sizeof(a))

// inline int setBit(int n,int pos) { return n = n | (1 << pos); }
// inline int resetBit(int n,int pos) { return n = n & ~(1 << pos); }
// inline bool checkBit(int n,int pos) { return (bool)(n & (1 << pos)); }

// int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
// int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// unsigned int num = rng();
// shuffle(V.begin(), V.end(), rng);

/******************************************************************************************/

// const int MAX = 500010;
// const int INF = 0x3f3f3f3f;
// const int MOD = 1000000007;

// inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
// inline int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }
// inline int mul(int a, int b) { return (a * 1LL * b) % MOD; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  /*#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  // freopen("out", "w", stdout);
  clock_t st = clock();
  #endif*/

  ll x;
  cin >> x;

  ll ans = 0;
  ans += 1000LL * (x / 500);
  x %= 500;
  ans += 5LL * (x / 5LL);

  cout << ans << endl;

  /*#ifndef ONLINE_JUDGE
cerr << "\\nTime taken: " << setprecision(5) << fixed << (clock() - st * 1.0) /
CLOCKS_PER_SEC; #endif*/
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define un(x) x.erase(unique(all(x)), x.end())
#define xx first
#define yy second
#define pb push_back
#define all(v) v.begin(), v.end()

#define D(x) cerr << #x " = " << x << '\\n'
#define DBG cerr << "Hi!" << '\\n'

#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a) memset(a, -1, sizeof(a))

// inline int setBit(int n,int pos) { return n = n | (1 << pos); }
// inline int resetBit(int n,int pos) { return n = n & ~(1 << pos); }
// inline bool checkBit(int n,int pos) { return (bool)(n & (1 << pos)); }

// int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
// int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// unsigned int num = rng();
// shuffle(V.begin(), V.end(), rng);

/******************************************************************************************/

// const int MAX = 500010;
// const int INF = 0x3f3f3f3f;
// const int MOD = 1000000007;

// inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
// inline int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }
// inline int mul(int a, int b) { return (a * 1LL * b) % MOD; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  // freopen("out", "w", stdout);
  clock_t st = clock();
#endif

  ll x;
  cin >> x;

  ll ans = 0;
  ans += 1000LL * (x / 500);
  x %= 500;
  ans += 5LL * (x / 5LL);

  cout << ans << endl;

#ifndef ONLINE_JUDGE
  cerr << "\\nTime taken: " << setprecision(5) << fixed
       << (clock() - st * 1.0) / CLOCKS_PER_SEC;
#endif
  return 0;
}