prithivMLmods/Coder-Stat huggingface dataset:
Problem p02754 (C++)

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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  long long aa = (N / (A + B)) * A;
  long long rest = N - (aa / A) * (A + B);
  if (rest >= A)
    aa += A;
  else
    aa += rest;
  cout << aa << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  if (A > 0) {
    long long aa = (N / (A + B)) * A;
    long long rest = N - (aa / A) * (A + B);
    if (rest >= A)
      aa += A;
    else
      aa += rest;
    cout << aa << endl;
  } else
    cout << 0 << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main() {
  ll i, j, n, b, r, c = 0;
  cin >> n >> b >> r;
l1:
  ll val = n / (b + r);
  c += val * b;
  ll val2 = n % (b + r);
  if (val2 <= b)
    c += val2;
  else {
    n = val2;
    goto l1;
  }
  cout << c;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main() {
  ll i, j, n, b, r, c = 0;
  cin >> n >> b >> r;
l1:
  ll val = n / (b + r);
  c = val * (b + r);
  ll val2 = n - c;
  if (val2 > b)
    val2 = b;
  cout << val * b + val2;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, red, blue, ans, rem;
  cin >> n >> blue >> red;
  ans = n / (red + blue) * blue;
  rem = n % (red + blue);
  ans += min(rem, blue);
  cout << ans;
}


Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {
  long long n, red, blue, ans, rem;
  cin >> n >> blue >> red;
  ans = n / (red + blue) * blue;
  rem = n % (red + blue);
  ans += min(rem, blue);
  cout << ans;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

#define ll long long
#define FOR(x, z, y) for (ll x = z; x < (ll)y; x++)

int main() {

  int n, a, b, blue = 0;
  cin >> n >> a >> b;

  cout << n / (a + b) * a + min(n % (a + b), a);
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

#define ll long long
#define FOR(x, z, y) for (ll x = z; x < (ll)y; x++)

int main() {

  ll n, a, b;
  cin >> n >> a >> b;

  cout << n / (a + b) * a + min(n % (a + b), a);
}
Problem p02754 (C++)

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

int main() {
  int N, A, B, X, Y, ans;
  cin >> N >> A >> B;

  X = N / (A + B);
  Y = N % (A + B);

  if (Y > A) {
    ans = A * X + A;
  } else {
    ans = A * X + Y;
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N, A, B, X, Y, ans;
  cin >> N >> A >> B;

  X = N / (A + B);
  Y = N % (A + B);

  if (Y > A) {
    ans = A * X + A;
  } else {
    ans = A * X + Y;
  }

  cout << ans << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF (1 << 29)
#define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void) {
  ll n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  int ttl = 0;
  while (ttl <= n) {
    if (ttl + a > n) {
      ans += (n - ttl);
    } else {
      ans += a;
    }
    ttl += a;
    ttl += b;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF (1 << 29)
#define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void) {
  ll n, a, b;
  cin >> n >> a >> b;
  ll block = n / (a + b);
  ll amari = n % (a + b);
  ll ans = block * a + min(amari, a);
  cout << ans << endl;
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main() {
  ll N, A, B;
  cin >> N >> A >> B;

  ll count = 0;
  while (N > 0) {
    if (N - A > 0) {
      N -= A;
      count += A;
    } else {
      count += N;
      N = 0;
    }
    N -= B;
  }

  cout << count << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main() {
  ll N, A, B;
  cin >> N >> A >> B;

  ll num = N / (A + B);
  ll count = num * A;

  ll remain = N - (num * (A + B));
  if (remain - A > 0) {
    count += A;
  } else {
    count += remain;
  }

  cout << count << endl;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repone(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define Rep(j, n) for (int j = 0; j < (int)(n); ++j)
#define Repo(j, o, n) for (int j = o; j < (int)(n); ++j)
#define Repone(j, n) for (int j = 1; j < (int)(n); ++j)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v, i) (v).erase(v.begin() + (i))
#define pbpair(a, b) push_back(make_pair(a, b))
#define MOD 1000000007
const long long INF = 1LL << 60;
#define pairint pair<int, int>
signed main() {
  int x = 0, y = 0, z = 0, w = 0, n = 0, m = 0;
  std::cin >> x >> y >> z;
  std::vector<int> v;
  if (y == 0) {
    std::cout << 0 << '\n';
    return 0;
  } else if (z == 0) {
    std::cout << x << '\n';
    return 0;
  }
  while (v.size() < x) {
    rep(i, y) v.pb(0);
    rep(i, z) v.pb(1);
  }
  rep(i, x) if (v[i] == 0) n++;
  std::cout << n << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repone(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define Rep(j, n) for (int j = 0; j < (int)(n); ++j)
#define Repo(j, o, n) for (int j = o; j < (int)(n); ++j)
#define Repone(j, n) for (int j = 1; j < (int)(n); ++j)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v, i) (v).erase(v.begin() + (i))
#define pbpair(a, b) push_back(make_pair(a, b))
#define MOD 1000000007
const long long INF = 1LL << 60;
#define pairint pair<int, int>
signed main() {
  int x = 0, y = 0, z = 0, w = 0, n = 0, m = 0;
  std::cin >> x >> y >> z;
  if (x % (y + z) == 0)
    std::cout << x / (y + z) * y << '\n';
  else if (x % (y + z) <= y)
    std::cout << x / (y + z) * y + x % (y + z) << '\n';
  else
    std::cout << x / (y + z) * y + y << '\n';
}
Problem p02754 (C++)

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

int main() {
  int n;
  int a, b;
  int cnt;
  int rem;

  cin >> n >> a >> b;
  cnt = 0;
  cnt += (n / (a + b)) * a;
  rem = n % (a + b);
  cnt += min(rem, a);
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

signed main() {
  long long n;
  long long a, b;
  long long cnt;
  long long rem;

  cin >> n >> a >> b;
  cnt = 0;
  cnt += (n / (a + b)) * a;
  rem = n % (a + b);
  cnt += min(rem, a);
  cout << cnt << endl;
  return 0;
}
Problem p02754 (C++)

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if (N % (A + B) > A) {
    cout << (N / (A + B)) * A + A << endl;
  } else {
    cout << (N / (A + B)) * A + N % (A + B) << endl;
  }
}

// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));

// 入力 (2重ループを用いる)
// for (int i = 0; i < 3; i++) {
// for (int j = 0; j < 4; j++) {
// cin >> data.at(i).at(j);
//}
//}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  if (N % (A + B) > A) {
    cout << (N / (A + B)) * A + A << endl;
  } else {
    cout << (N / (A + B)) * A + N % (A + B) << endl;
  }
}

// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));

// 入力 (2重ループを用いる)
// for (int i = 0; i < 3; i++) {
// for (int j = 0; j < 4; j++) {
// cin >> data.at(i).at(j);
//}
//}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>

int main() {
  int n, a, b;
  std::cin >> n >> a >> b;
  std::cout << (n / (a + b)) * a + std::min(a, n % (a + b));
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>

int main() {
  long long n, a, b;
  std::cin >> n >> a >> b;
  std::cout << (n / (a + b)) * a + std::min(a, n % (a + b));
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l + r) >> 1)
#define ll long long
using namespace std;

int main() {
  int n, a, b;
  int ans;
  cin >> n >> a >> b;
  ans = n / (a + b) * a;
  n -= n / (a + b) * (a + b);
  if (n <= a)
    ans += n;
  else
    ans += a;
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l + r) >> 1)
#define ll long long
using namespace std;

int main() {
  long long n, a, b;
  long long ans;
  cin >> n >> a >> b;
  ans = n / (a + b) * a;
  n -= n / (a + b) * (a + b);
  if (n <= a)
    ans += n;
  else
    ans += a;
  cout << ans << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ull n, a, b;
  cin >> n >> a >> b;
  if (a + b == 0)
    cout << 0 << '\n';
  else {
    ull s = n % (a + b);
    ull r = n - s;
    r /= (a + b);
    r *= a;
    if (s != 0)
      r += s % a;
    cout << r << ' ';
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ull n, a, b;
  cin >> n >> a >> b;
  ull s = n % (a + b);
  ull r = ((n - s) / (a + b)) * a;
  r += (s <= a ? s : a);
  cout << r << '\n';
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  int index = 1;
  ll ans = 0;
  while (n > 0) {
    // add blue ball
    if (index % 2 == 1) {
      if (n > a) {
        n = n - a;
        ans += a;
      } else {
        ans += n;
        n = 0;
      }
    } else // add red ball
    {
      n = n - b;
    }
    index++;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = n / (a + b) * a;
  ll remainder = n % (a + b);
  if (remainder >= a)
    ans += a;
  else
    ans += remainder;
  cout << ans;
}
Problem p02754 (C++)

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

int main() {
  int n, a, b, ans;
  cin >> n >> a >> b;
  if (n % (a + b) <= a)
    ans = a * (n / (a + b)) + n % (a + b);
  else
    ans = a * (n / (a + b)) + a;
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, a, b, ans;
  cin >> n >> a >> b;
  if (n % (a + b) <= a)
    ans = a * (n / (a + b)) + n % (a + b);
  else
    ans = a * (n / (a + b)) + a;
  cout << ans;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define All(a) a.begin(), a.end()
#define INF 1000000007
const int MOD = 1000000007;
// accumulate(vec.begin(), vec.end(), 0)

int gcd(int x, int y) {
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << a * (n / (a + b)) + min(a, n % (a + b)) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define All(a) a.begin(), a.end()
#define INF 1000000007
const int MOD = 1000000007;
// accumulate(vec.begin(), vec.end(), 0)

int gcd(int x, int y) {
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  cout << a * (n / (a + b)) + min(a, n % (a + b)) << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define pii pair<int, int>

ll ans;
int N, A, B, k, l;

void solve() {
  k = N / (A + B);
  l = N % (A + B);

  cout << A * k + min(l, A) << endl;
}

int main() {
  cin >> N >> A >> B;

  solve();
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define pii pair<int, int>

ll N, A, B, k, l;

void solve() {
  k = N / (A + B);
  l = N % (A + B);

  cout << A * k + min(l, A) << endl;
}

int main() {
  cin >> N >> A >> B;

  solve();
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<char> balls;
  int i, j, k;
  for (i = 0; i < n;) {
    for (j = 0; j < a; ++j) {
      balls.push_back('b');
      i++;
    }
    for (k = 0; k < b; ++k) {
      balls.push_back('r');
      i++;
    }
  }
  int ans = 0;
  for (i = 0; i < n; ++i) {
    // cout << balls.at(i);
    if (balls.at(i) == 'b') {
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long N, A, B;
  cin >> N >> A >> B;
  long x = N / (A + B);
  long r = N % (A + B);
  long ans = A * x;
  if (A <= r) {
    ans += A;
  } else {
    ans += r;
  }
  cout << ans << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>

using namespace std;

int main(void) {
  unsigned int N, div, rem;
  unsigned int A, B, ans;
  cin >> N >> A >> B;
  div = N / (A + B);
  rem = N % (A + B);
  if (rem < A) {
    ans = A * div + rem;
  } else {
    ans = A * div + A;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main(void) {
  unsigned long N, div, rem;
  unsigned long A, B, ans;
  cin >> N >> A >> B;
  div = N / (A + B);
  rem = N % (A + B);
  if (rem < A) {
    ans = A * div + rem;
  } else {
    ans = A * div + A;
  }
  cout << ans << endl;
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll N;
  ll A, B;
  cin >> N >> A >> B;

  ll x, y;
  x = N / (A + B) * A;
  y = N % (A + B);

  ll cnt = x;
  if (y > 0) {
    for (ll i = 0; i < y; i++) {
      if (i < A)
        cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll N;
  ll A, B;
  cin >> N >> A >> B;

  ll x, y;
  x = N / (A + B) * A;
  y = N % (A + B);

  ll cnt = x;
  if (y > 0) {
    if (y > A)
      cnt += A;
    else
      cnt += y;
  }

  cout << cnt << endl;
  return 0;
}
Problem p02754 (C++)

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  if (N % (A + B) < A) {
    cout << (N / (A + B)) * A + N % (A + B) << endl;
  } else {
    cout << (N / (A + B)) * A + A << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, A, B;
  cin >> N >> A >> B;

  if (N % (A + B) < A) {
    cout << (N / (A + B)) * A + N % (A + B) << endl;
  } else {
    cout << (N / (A + B)) * A + A << endl;
  }
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define mod 1000000007
#define endl '\n'
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  if (a == 0) {
    cout << 0;
    return 0;
  }
  ans = ans + (n / (a + b));
  ans *= a;
  // cout<<ans<<" "<<n%(a+b)<<endl;
  // ll x=(n%(a+b))%a;
  if ((n % (a + b)) > 0 && (n % (a + b) <= a))
    ans += (n % (a + b));
  else if ((n % (a + b) > a))
    ans += a;

  cout << ans;
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define mod 1000000007
#define endl '\n'
int main() {
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "rt", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif
  fast ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  if (a == 0) {
    cout << 0;
    return 0;
  }
  ans = ans + (n / (a + b));
  ans *= a;
  // cout<<ans<<" "<<n%(a+b)<<endl;
  // ll x=(n%(a+b))%a;
  if ((n % (a + b)) > 0 && (n % (a + b) <= a))
    ans += (n % (a + b));
  else if ((n % (a + b) > a))
    ans += a;

  cout << ans;
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
Problem p02754 (C++)

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

int a, b, c;
int main() {
  cin >> a >> b >> c;
  cout << a / (b + c) * b + min(a % (b + c), b);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

long long a, b, c;
int main() {
  cin >> a >> b >> c;
  cout << a / (b + c) * b + min(a % (b + c), b);
}
Problem p02754 (C++)

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  int n, b, r, ball_count, ans = 0;
  cin >> n >> b >> r;
  ball_count = b + r;
  ans = n / ball_count * b + (n - n / ball_count * ball_count < b
                                  ? n - n / ball_count * ball_count
                                  : b);
  cout << ans << endl;
}

signed main() {
  solve();

  return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  ll n, b, r, ball_count, ans = 0;
  cin >> n >> b >> r;
  ball_count = b + r;
  ans = n / ball_count * b + (n - n / ball_count * ball_count < b
                                  ? n - n / ball_count * ball_count
                                  : b);
  cout << ans << endl;
}

signed main() {
  solve();

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int mod = 1000000007;

int main() {
  ll n;
  cin >> n;
  ll a, b;
  cin >> a >> b;
  ll cnt = 0;
  while (n > (a + b)) {
    n -= a;
    n -= b;
    cnt++;
  }
  ll ans = 0;
  if (n - a > 0) {
    ans = cnt * a + a;
  } else {
    ans = cnt * a + n;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int mod = 1000000007;

int main() {
  ll n;
  cin >> n;
  ll a, b;
  cin >> a >> b;
  ll cnt = 0;
  cnt = n / (a + b);
  n -= cnt * (a + b);
  ll ans = 0;
  if (n - a > 0) {
    ans = cnt * a + a;
  } else {
    ans = cnt * a + n;
  }
  cout << ans << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));

signed main() {
  int N, A, B;
  cin >> N >> A >> B;
  int sum = 0;
  int cnt = 0;
  int i = 0;
  while (sum <= N) {
    if (i % 2 == 0) {
      sum += A;
      if (sum > N) {
        int num = sum - N;
        cnt += -num;
      }
      cnt += A;
    } else
      sum += B;
    i++;
  }
  cout << cnt;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));

signed main() {
  int N, A, B;
  cin >> N >> A >> B;
  int num = N / (A + B);
  int ans = num * A;
  int sa = N - num * (A + B);
  ans += min(sa, A);
  cout << ans;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  int set;
  set = n / (a + b);
  ans += set * a;
  ans += min(n - set * (a + b), a);
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  int set;
  set = n / (a + b);
  ans += set * a;
  ans += min(n - set * (a + b), a);
  cout << ans << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++) // n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N, A, B, C, D, E, F;
  cin >> N >> A >> B;
  C = (A + B);
  D = N / C;
  E = D * A;
  F = N % C;
  if (A == 0) {
    cout << 0 << endl;
  } else {
    if (F <= A) {
      cout << E + F << endl;
    } else {
      cout << E + A << endl;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++) // n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  long long int N, A, B, C, D, E, F;
  cin >> N >> A >> B;
  C = (A + B);
  D = N / C;
  E = D * A;
  F = N % C;
  if (A == 0) {
    cout << 0 << endl;
  } else {
    if (F <= A) {
      cout << E + F << endl;
    } else {
      cout << E + A << endl;
    }
  }
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vc = vector<char>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
#define rep(i, x, n) for (int i = x; i < n; i++)
#define all(x) x.begin(), x.end()

int main() {
  int n, a, b, ans, rem, rep;
  cin >> n >> a >> b;

  rep = n / (a + b);
  rem = n % (a + b);
  ans = rep * a;
  ans += min(rem, a);

  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vc = vector<char>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
#define rep(i, x, n) for (int i = x; i < n; i++)
#define all(x) x.begin(), x.end()

int main() {
  ll n, a, b, ans, rem, rep;
  cin >> n >> a >> b;

  rep = n / (a + b);
  rem = n % (a + b);
  ans = rep * a;
  ans += min(rem, a);

  cout << ans;
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;

  ll w = N / (A + B);
  ll x = w * A;
  ll rem = N % (w * (A + B));
  rem = rem < A ? rem : A;

  cout << x + rem << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;

  ll w = N / (A + B);
  ll x = w * A;
  ll rem = min(A, N % (A + B));

  cout << x + rem << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;

int n, a, b;

void solve() {
  if (n % (a + b) > a) {
    cout << n / (a + b) * a + a << endl;
  } else {
    cout << n / (a + b) * a + n % (a + b) << endl;
  }
}

int main() {
  cin >> n >> a >> b;
  solve();
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;

long long n, a, b;

void solve() {
  if (n % (a + b) > a) {
    cout << n / (a + b) * a + a << endl;
  } else {
    cout << n / (a + b) * a + n % (a + b) << endl;
  }
}

int main() {
  cin >> n >> a >> b;
  solve();
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
  int i = 0, j = 0, ans = 0;

  int n, a, b;
  cin >> n >> a >> b;

  j = n / (a + b);
  ans = a * j;
  for (i = 1; i <= a; i++) {
    if ((a + b) * j + i <= n)
      ans++;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
  int i = 0, j = 0, ans = 0;

  int n, a, b;
  cin >> n >> a >> b;

  j = n / (a + b);
  ans = a * j;

  if (a + (a + b) * j <= n)
    ans += a;
  else
    ans += n - (a + b) * j;

  cout << ans << endl;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b;
  c = n / (a + b);
  if (n - (a + b) * c >= a) {
    d = a * (c + 1);
  } else {
    d = a * c + n - c * (a + b);
  }
  cout << d << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  long long n, a, b, c, d;
  cin >> n >> a >> b;
  c = n / (a + b);
  if (n - (a + b) * c >= a) {
    d = a * (c + 1);
  } else {
    d = a * c + n - c * (a + b);
  }
  cout << d << endl;
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, a, b;
  cin >> n >> a >> b;

  int bc = 0;
  long long i = 0;
  while (i < n) {
    for (int d = 0; d < a; d++) {
      if (i < n) {
        bc += 1;
        i++;
      } else {
        cout << bc << endl;
        return 0;
      }
    }
    for (int d = 0; d < b; d++) {
      if (i < n) {
        i++;
      } else {
        cout << bc << endl;
        return 0;
      }
    }
  }
  cout << bc << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, a, b;
  cin >> n >> a >> b;

  long long p = a + b;
  long long w = n / p;
  long long m = n % p;
  long long x = a < m ? a : m;

  cout << (w * a + x) << endl;
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v) v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START                                                                  \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(0);
#define isOdd(n) (n & 1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n) ((n) ? (ll)(log10(n)) + 1 : 1)
#define mem(x, val) memset(x, val, sizeof(x)) // be careful
#define sz(x) (int)x.size()
#define MOD 1000000007
#define EPS 1e-7

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  START
  // freopen("test cases\\in.txt", "r", stdin) ;
  ll n, a, b;
  cin >> n >> a >> b;
  ll cnt = 1, sum;
  while (cnt * (a + b) < n)
    cnt++;
  sum = (cnt - 1) * a;
  n -= (cnt - 1) * (a + b);
  sum += min(n, a);
  cout << sum;
  return 0;
}


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

using namespace std;
using namespace __gnu_cxx;

#define all(v) v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START                                                                  \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(0);
#define isOdd(n) (n & 1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n) ((n) ? (ll)(log10(n)) + 1 : 1)
#define mem(x, val) memset(x, val, sizeof(x)) // be careful
#define sz(x) (int)x.size()
#define MOD 1000000007
#define EPS 1e-7

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  START
  // freopen("test cases\\in.txt", "r", stdin) ;
  ll n, a, b;
  cin >> n >> a >> b;
  ll cnt = 1, sum;
  cnt = n / (a + b) + (n % (a + b) != 0);
  sum = (cnt - 1) * a;
  n -= (cnt - 1) * (a + b);
  sum += min(n, a);
  cout << sum;
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b;
  cin >> n >> a >> b;

  cout << n / (a + b) * a + min(n % (a + b), a) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, a, b;
  cin >> n >> a >> b;

  cout << n / (a + b) * a + min(n % (a + b), a) << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  long N, A, B;
  cin >> N >> A >> B;
  long blue;
  blue = N / (A + B) * A;
  for (long i = 0; i < N % (A + B); ++i) {
    if (i < A)
      blue += 1;
  }
  cout << blue << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long N, A, B;
  cin >> N >> A >> B;
  long blue;
  blue = N / (A + B) * A;
  if (N % (A + B) >= A) {
    blue += A;
  } else if (N % (A + B) < A) {
    blue += N % (A + B);
  }
  cout << blue << endl;
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  vector<bool> line;
  while (line.size() < N) {
    for (int j = 0; j < A; j++) {
      line.push_back(true);
    }
    for (int j = 0; j < B; j++) {
      line.push_back(false);
    }
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (line.at(i))
      cnt++;
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  cout << N / (A + B) * A + min(N % (A + B), A) << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll n, a, b;
  cin >> n >> a >> b;
  ll total = 0;
  ll ans = 0;
  bool isBlue = true;
  while (n > total) {
    if (isBlue) {
      total += a;
      ans += a;
      isBlue = false;
    } else {
      total += b;
      isBlue = true;
    }
  }
  if (!isBlue)
    ans -= (total - n);
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll n, a, b;
  cin >> n >> a >> b;
  cout << (n / (a + b)) * a + min(a, n % (a + b)) << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int a, b, r, ans, rem;
  cin >> a >> b >> r;
  ans = a / (b + r) * b;
  rem = a % (b + r);
  ans += min(rem, b);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long long int a, b, r, ans, rem;
  cin >> a >> b >> r;
  ans = a / (b + r) * b;
  rem = a % (b + r);
  ans += min(rem, b);
  cout << ans << endl;
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {

  int N, A, B, t, s, ans;
  bool can;
  can = false;
  //  string S,A;

  cin >> N >> A >> B;

  t = N / (A + B);
  s = N - (A + B) * t;
  ans = t * A;
  if (s > A)
    ans += A;
  else
    ans += s;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {

  long N, A, B, t, s, ans;
  bool can;
  can = false;
  //  string S,A;

  cin >> N >> A >> B;

  t = N / (A + B);
  s = N - (A + B) * t;
  ans = t * A;
  if (s > A)
    ans += A;
  else
    ans += s;
  cout << ans << endl;
  return 0;
}
Problem p02754 (C++)

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

int main() {
  int n, a, b, o;
  cin >> n >> a >> b;
  o = n / (a + b) * a;
  if (n % (a + b) > a) {
    o = o + a;
  } else {
    o = o + (n % (a + b));
  }
  cout << o << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int64_t n, a, b, o;
  cin >> n >> a >> b;
  o = n / (a + b) * a;
  if (n % (a + b) > a) {
    o = o + a;
  } else {
    o = o + (n % (a + b));
  }
  cout << o << endl;
}
Problem p02754 (C++)

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

int main() {
  int N, A, B, x;
  cin >> N >> A >> B;
  x = N / (A + B) * A;
  if (N % (A + B) > A)
    x += A;
  else
    x += N % (A + B);
  cout << x << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, A, B, x;
  cin >> N >> A >> B;
  x = N / (A + B) * A;
  if (N % (A + B) > A)
    x += A;
  else
    x += N % (A + B);
  cout << x << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
int N, A, B, Z, count, D, sum, Q;
int main() {

  cin >> N >> A >> B;
  ::sum = A + B;

  D = N / ::sum;
  ::count += D * A;
  Z += D * ::sum;
  Q = N - Z;
  if (Q <= A) {
    ::count += Q;
  } else {
    ::count += A;
  }

  cout << ::count << endl;
}

Fixed submission:
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
long int N, A, B, Z, count, D, sum, Q;
int main() {

  cin >> N >> A >> B;
  ::sum = A + B;

  D = N / ::sum;
  ::count += D * A;
  Z += D * ::sum;
  Q = N - Z;
  if (Q <= A) {
    ::count += Q;
  } else {
    ::count += A;
  }

  cout << ::count << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep1(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

int main() {
  int N, A, B, C = 0, D, E;
  cin >> N >> A >> B;
  C = A + B;
  D = N / C;
  E = N - D * C;
  if (E > A)
    cout << A * D + A << endl;
  else
    cout << A * D + E << endl;
}

Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep1(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

int main() {
  long long int N, A, B, C = 0, D, E;
  cin >> N >> A >> B;
  C = A + B;
  D = N / C;
  E = N - D * C;
  if (E > A)
    cout << A * D + A << endl;
  else
    cout << A * D + E << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
/****************************************************
 *   Template for coding contests                    *
 *   Author    :    Sanjeev Sharma                   *
 *   Email     :    thedevelopersanjeev@gmail.com    *
 *****************************************************/
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse4")
#pragma comment(linker, "/stack:200000000")

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

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, a, b;
  cin >> n >> a >> b;
  long long ans = 0;
  long long cnt = 0;
  while (cnt <= n) {
    if (cnt + a <= n) {
      cnt += a;
      ans += a;
    } else {
      ans += (n - cnt);
      cnt += a;
    }
    cnt += b;
  }
  cout << ans;
  return 0;
}


Fixed submission:
/****************************************************
 *   Template for coding contests                    *
 *   Author    :    Sanjeev Sharma                   *
 *   Email     :    thedevelopersanjeev@gmail.com    *
 *****************************************************/
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse4")
#pragma comment(linker, "/stack:200000000")

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

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, a, b;
  cin >> n >> a >> b;
  cout << ((n / (a + b)) * a) + min(n % (a + b), a);
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip> //doubleの桁数指定
#include <iostream>
#include <string> //文字列

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++) // forの短縮
#define rep(i, n) REP(i, 0, n)                                 // REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; // 円周率

// 常設関数↓

// 最大公約数
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

// degree → radian
ll chg_DegRad(int deg) { return deg * PI / 180.0; }

// radian → degree
ll chg_RadDeg(int rad) { return rad * 180.0 / PI; }

// 提出コード↓

int n, a, b, c;
int main() {

  cin >> n >> a >> b;
  c = a + b;

  if ((n % c) > a) {
    cout << ((n / c) + 1) * a << endl;
  } else
    cout << ((n / c) * a) + (n % c) << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip> //doubleの桁数指定
#include <iostream>
#include <string> //文字列

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++) // forの短縮
#define rep(i, n) REP(i, 0, n)                                 // REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; // 円周率

// 常設関数↓

// 最大公約数
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

// degree → radian
ll chg_DegRad(int deg) { return deg * PI / 180.0; }

// radian → degree
ll chg_RadDeg(int rad) { return rad * 180.0 / PI; }

// 提出コード↓

ll n, a, b, c;

int main() {

  cin >> n >> a >> b;
  c = a + b;

  if ((n % c) > a) {
    cout << ((n / c) + 1) * a << endl;
  } else
    cout << ((n / c) * a) + (n % c) << endl;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if (N % (A + B) == 0)
    cout << N / (A + B) * A << endl;
  else
    cout << N / (A + B) * A + min(N % (A + B), A) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  if (N % (A + B) == 0)
    cout << N / (A + B) * A << endl;
  else
    cout << N / (A + B) * A + min(N % (A + B), A) << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
bool is_ok(ll x, ll y) {
  if (x == y)
    return true;
  else
    return false;
}
int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  int num = 0;
  int b_num = 0;
  for (ll i = 0; i < pow(10, 100); i++) {
    for (ll j = 0; j < a; j++) {
      b_num++;
      num++;
      if (is_ok(n, num)) {
        cout << b_num << endl;
        return 0;
      }
    }
    for (ll k = 0; k < b; k++) {
      num++;
      if (is_ok(n, num)) {
        cout << b_num << endl;
        return 0;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
bool is_ok(ll x, ll y) {
  if (x == y)
    return true;
  else
    return false;
}
int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll r_b = a + b;
  ll ans = (n / r_b) * a;
  if ((n % r_b) < a)
    ans += (n % r_b);
  else
    ans += a;
  cout << ans << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int maxn = 1e5 + 5;

long long N, A, B;

int main() {
#define LOCAL
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> N >> A >> B;
  if (A + B >= N) {
    if (A >= N)
      cout << N << endl;
    else
      cout << A << endl;
  } else {
    long long ans = N / (A + B) * A;
    long long mod = N % (A + B);
    if (mod <= A)
      ans += mod;
    else
      ans += A;
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int maxn = 1e5 + 5;

long long N, A, B;

int main() {
// #define LOCAL
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> N >> A >> B;
  if (A + B >= N) {
    if (A >= N)
      cout << N << endl;
    else
      cout << A << endl;
  } else {
    long long ans = N / (A + B) * A;
    long long mod = N % (A + B);
    if (mod <= A)
      ans += mod;
    else
      ans += A;
    cout << ans << endl;
  }
  return 0;
}