Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li, li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i, l, r) for (li i = l; i <= r; ++i)
#define fr(i, l, r) for (li i = l; i >= r; --i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base, li exp, li M) {
  li res = 1;
  while (exp > 0) {
    if (exp & 1)
      res = (res * base) % M;

    base = (base * base) % M;
    exp >>= 1;
  }
  return res;
}

vi par, sz, vis, dis;
vector<vi> graph;
vector<vector<pair<li, li>>> wgraph;

void init(li n) {
  par.resize(n);
  sz.resize(n);
  wgraph.resize(n);
  dis.resize(n);
  vis.resize(n);
  graph.resize(n);

  f(i, 0, n - 1) {
    par[i] = i;
    sz[i] = 1;
    dis[i] = 1e18;
  }
}

li root(li a) {
  while (a != par[a]) {
    par[a] = par[par[a]];
    a = par[a];
  }

  return a;
}

void unio(li a, li b) {
  li r_a = root(a);
  li r_b = root(b);

  if (par[r_a] != r_b) {
    if (sz[r_a] < sz[r_b]) {
      par[r_a] = par[r_b];
      sz[r_b] += sz[r_a];
      sz[r_a] = 0;
    } else {
      par[r_b] = par[r_a];
      sz[r_a] += sz[r_b];
      sz[r_b] = 0;
    }
  }
}

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

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  li n, a, b;

  cin >> n >> a >> b;

  li tp1, tp2;

  tp1 = n / (a + b);

  tp2 = min(n % (a + b), a);

  cout << tp1 * a + tp2;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li, li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i, l, r) for (li i = l; i <= r; ++i)
#define fr(i, l, r) for (li i = l; i >= r; --i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base, li exp, li M) {
  li res = 1;
  while (exp > 0) {
    if (exp & 1)
      res = (res * base) % M;

    base = (base * base) % M;
    exp >>= 1;
  }
  return res;
}

vi par, sz, vis, dis;
vector<vi> graph;
vector<vector<pair<li, li>>> wgraph;

void init(li n) {
  par.resize(n);
  sz.resize(n);
  wgraph.resize(n);
  dis.resize(n);
  vis.resize(n);
  graph.resize(n);

  f(i, 0, n - 1) {
    par[i] = i;
    sz[i] = 1;
    dis[i] = 1e18;
  }
}

li root(li a) {
  while (a != par[a]) {
    par[a] = par[par[a]];
    a = par[a];
  }

  return a;
}

void unio(li a, li b) {
  li r_a = root(a);
  li r_b = root(b);

  if (par[r_a] != r_b) {
    if (sz[r_a] < sz[r_b]) {
      par[r_a] = par[r_b];
      sz[r_b] += sz[r_a];
      sz[r_a] = 0;
    } else {
      par[r_b] = par[r_a];
      sz[r_a] += sz[r_b];
      sz[r_b] = 0;
    }
  }
}

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

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  li n, a, b;

  cin >> n >> a >> b;

  li tp1, tp2;

  tp1 = n / (a + b);

  tp2 = min(n % (a + b), a);

  cout << tp1 * a + tp2;

  return 0;
}