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

// Created by Rg
#include "bits/stdc++.h"
using namespace std;
#define f first
#define endl '\\n'
#define sc second
#define N (int)2e5 + 5
#define pb push_back
#define PI acos(-1.0)
#define int long long
#define mod 1000000007
#define ld long double
#define vi vector<int>
#define eb emplace_back
#define vpii vector<pii>
#define mii map<int, int>
#define pii pair<int, int>
#define pq priority_queue
#define test(x) while (x--)
#define hii cout << "hii" << endl
#define si size()
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define fo(i, a, n) for (int i = a; i < n; i++)
#define rfo(i, n, a) for (int i = n; i >= a; i--)
#define FAST                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define time()                                                                 \\
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\\n"
// inline void INP()
// {
//     #ifndef ONLINE_JUDGE
//         freopen("input.txt","r",stdin);
//         freopen("output.txt","w",stdout);
//     #endif
// }

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n, m, k, q, x, y;
string s;
vi adj[N];
int vis[N], par[N], a[N];

void go() {
  cin >> n;

  int ans = 0;

  if (n >= 500) {
    int d = n / 500;
    ans = d * 1000;

    int r = n - d * 500;
    r = r / 5;
    ans += r * 5;
  }

  else {
    int r = n / 5;
    ans += r * 5;
  }

  cout << ans << endl;
}

int32_t main() {
  // INP();
  FAST;
  int t = 1;
  // cin>>t;
  test(t) go();
}


Error: WA

Fixed submission:

// Created by Rg
#include "bits/stdc++.h"
using namespace std;
#define f first
#define endl '\\n'
#define sc second
#define N (int)2e5 + 5
#define pb push_back
#define PI acos(-1.0)
#define int long long
#define mod 1000000007
#define ld long double
#define vi vector<int>
#define eb emplace_back
#define vpii vector<pii>
#define mii map<int, int>
#define pii pair<int, int>
#define pq priority_queue
#define test(x) while (x--)
#define hii cout << "hii" << endl
#define si size()
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define fo(i, a, n) for (int i = a; i < n; i++)
#define rfo(i, n, a) for (int i = n; i >= a; i--)
#define FAST                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define time()                                                                 \\
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\\n"
inline void INP() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n, m, k, q, x, y;
string s;
vi adj[N];
int vis[N], par[N], a[N];

void go() {
  cin >> n;

  int ans = 0;

  if (n > 500) {
    int d = n / 500;
    ans = d * 1000;

    int r = n - d * 500;
    r = r / 5;
    ans += r * 5;
  }

  else {
    int r = n / 5;
    ans += r * 5;
  }

  cout << ans << endl;
}

int32_t main() {
  INP();
  FAST;
  int t = 1;
  // cin>>t;
  test(t) go();
}