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

/*Author: Qaseem Hasan alias Mikepayne14(Codeforces,SPOJ)
                           qaseem_hasan_ (HackerEarth,Codechef,HackerRank)
*/

//---------------------------------------------------------
// #pragma GCC optimize "trapv"

#include <bits/stdc++.h>
using namespace std;
//---------------------------------------------------------
template <typename T, typename U> inline void amin(T &x, U y) {
  if (y < x)
    x = y;
} // x=min,y=item
template <typename T, typename U> inline void amax(T &x, U y) {
  if (x < y)
    x = y;
}

template <typename ForwardIterator, typename T>
T first_val(ForwardIterator first, ForwardIterator last, T value) {
  auto it = std::lower_bound(first, last, value);
  return (it != last) ? (it - first) : -1;
}

template <typename ForwardIterator, typename T>
T last_val(ForwardIterator first, ForwardIterator last, T value) {
  auto it = std::upper_bound(first, last, value);
  return ((it != last) ? (it - first) : -1) - 1;
}
//--------------------------------------------------------
#define acc accumulate
#define eb emplace_back
#define ll long long int
#define lld long long double
#define mii map<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define seti set<int>
#define F first
#define S second
#define fil(v, x) fill(all(v), x)
#define filcon(v, x) iota(all(v), x)
#define rep(n) for (int i = 0; i < n; ++i)
#define repr(n) for (int i = n - 1; i >= 0; --i)
#define erase(v, e) v.erase(std::remove(v.begin(), v.end(), e), v.end())
#define sqr(x) ((x) * (x))
#define MEM(a, b) memset(a, b, sizeof(a))
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define inrange(i, a, b) ((i >= min(a, b)) && (i <= max(a, b)))
#define FLSH fflush(stdout)
// #define min_all(a,b,c,d,...) min({a,b,c,d,...})
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO                                                                \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define make_unique(v)                                                         \\
  sort(all(v));                                                                \\
  v.erase(unique(all(v)), v.end());
#define INF (int)1e9
#define EPS 1e-8
#define MOD 1e9 + 7
#define tr(x) cout << #x << " = { " << x << " }\\n";
#define khatam '\\n'
#define PI acos(-1);

//--------------------------------------------------------

// int ar[40001][40001];

// ll ar[10001];

//--------------------------------------------------------
/*bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.F < j.F;
}*/

void solve() {
  ll n;
  cin >> n;
  ll sum = n / 500;
  ll happy = sum * 1000;
  ll res = (n - sum * 500) / 5;
  happy += res * 5;
  cout << happy << khatam;
}

int main() {
  FAST_IO;
  /*    #ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
      #endif*/
  //--------------------------------------------------------
  solve();
}

Error: WA

Fixed submission:


/*Author: Qaseem Hasan alias Mikepayne14(Codeforces,SPOJ)
                           qaseem_hasan_ (HackerEarth,Codechef,HackerRank)
*/

//---------------------------------------------------------
// #pragma GCC optimize "trapv"

#include <bits/stdc++.h>
using namespace std;
//---------------------------------------------------------
template <typename T, typename U> inline void amin(T &x, U y) {
  if (y < x)
    x = y;
} // x=min,y=item
template <typename T, typename U> inline void amax(T &x, U y) {
  if (x < y)
    x = y;
}

template <typename ForwardIterator, typename T>
T first_val(ForwardIterator first, ForwardIterator last, T value) {
  auto it = std::lower_bound(first, last, value);
  return (it != last) ? (it - first) : -1;
}

template <typename ForwardIterator, typename T>
T last_val(ForwardIterator first, ForwardIterator last, T value) {
  auto it = std::upper_bound(first, last, value);
  return ((it != last) ? (it - first) : -1) - 1;
}
//--------------------------------------------------------
#define acc accumulate
#define eb emplace_back
#define ll long long int
#define lld long long double
#define mii map<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define seti set<int>
#define F first
#define S second
#define fil(v, x) fill(all(v), x)
#define filcon(v, x) iota(all(v), x)
#define rep(n) for (int i = 0; i < n; ++i)
#define repr(n) for (int i = n - 1; i >= 0; --i)
#define erase(v, e) v.erase(std::remove(v.begin(), v.end(), e), v.end())
#define sqr(x) ((x) * (x))
#define MEM(a, b) memset(a, b, sizeof(a))
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define inrange(i, a, b) ((i >= min(a, b)) && (i <= max(a, b)))
#define FLSH fflush(stdout)
// #define min_all(a,b,c,d,...) min({a,b,c,d,...})
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO                                                                \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define make_unique(v)                                                         \\
  sort(all(v));                                                                \\
  v.erase(unique(all(v)), v.end());
#define INF (int)1e9
#define EPS 1e-8
#define MOD 1e9 + 7
#define tr(x) cout << #x << " = { " << x << " }\\n";
#define khatam '\\n'
#define PI acos(-1);

//--------------------------------------------------------

// int ar[40001][40001];

// ll ar[10001];

//--------------------------------------------------------
/*bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.F < j.F;
}*/

void solve() {
  ll n;
  cin >> n;
  ll sum = n / 500;
  ll happy = sum * 1000;
  ll res = (n - sum * 500) / 5;
  happy += res * 5;
  cout << happy << khatam;
}

int main() {
  FAST_IO;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  //--------------------------------------------------------
  solve();
}