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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
template <typename T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

int in() {
  int x;
  scanf("%d", &x);
  return x;
}
ll lin() {
  ll x;
  scanf("%lld", &x);
  return x;
}
#define INF 1LL << 60

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

  ll length = 0, ans = 0;

  for (ll i = 0; length < N; i++) {
    if (i % 2 == 0)
      length += A;
    else
      length += B;
    if (length < N && i % 2 == 0)
      ans += A;
    else if (i % 2 == 0)
      ans += N - (length - A);
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
template <typename T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

int in() {
  int x;
  scanf("%d", &x);
  return x;
}
ll lin() {
  ll x;
  scanf("%lld", &x);
  return x;
}
#define INF 1LL << 60

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

  ll duplicate = floor(double(N) / double(A + B)), mod = N % (A + B), ans;
  // cerr << "duplicate = " << duplicate << endl;
  ans += duplicate * A;
  ans += min(mod, A);

  cout << ans << endl;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, a, b, mod, div;
  cin >> n >> a >> b;
  div = n / (a + b);
  mod = n % (a + b);
  if (mod > a) {
    mod = a;
  }
  cout << mod + a * div;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long n, a, b, mod, div;
  cin >> n >> a >> b;
  div = n / (a + b);
  mod = n % (a + b);
  if (mod > a) {
    mod = a;
  }
  cout << mod + a * div;
  return 0;
}
Problem p02754 (C++)

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

template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
const int INF = 1e9;
template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}

signed 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;
#define int long long
template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
const int INF = 1e9;
template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}

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

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  int N, A, B, rest;
  cin >> N >> A >> B;
  rest = N % (A + B);
  if (rest > A)
    rest = A;
  N = (N / (A + B)) * A;
  cout << rest + N;
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  long long N, A, B, rest;
  cin >> N >> A >> B;
  rest = N % (A + B);
  if (rest > A)
    rest = A;
  N = (N / (A + B)) * A;
  cout << rest + N;
}
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;
  bool ok = true;
  int64_t i = 0;
  int64_t ans = 0;
  while (ok) {
    if ((A + B) + i < N) {
      ans += A;
      i += (A + B);
    } else if ((i + A) < N) {
      ans += A;
      ok = false;
    } else {
      ans += (N - i);
      ok = false;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  int64_t i = (A + B) * (N / (A + B));
  int64_t ans = A * (N / (A + B));
  if ((i + A) < N) {
    ans += A;
  } else {
    ans += (N - i);
  }
  cout << ans << 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);
  cout << X * A + min(N % (A + B), A) << endl;
  return 0;
}

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);
  cout << X * A + min(N % (A + B), A) << 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;
}


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 + A << endl;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A, B;
  int k, l, p;
  cin >> N >> A >> B;
  k = N / (A + B);
  l = N - (A + B) * k;
  if (l < A) {
    p = l + k * A;
  } else {
    p = A + k * A;
  }
  cout << p << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, A, B;
  int64_t k, l, p;
  cin >> N >> A >> B;
  k = N / (A + B);
  l = N - (A + B) * k;
  if (l < A) {
    p = l + k * A;
  } else {
    p = A + k * A;
  }
  cout << p << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A, B;
  int count, ama;
  cin >> N >> A >> B;

  count = N / (A + B);
  ama = N % (A + B);
  if (ama > A > 0) {
    ama = A;
  }

  cout << count * A + ama << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N, A, B;
  long long int count, ama;
  cin >> N >> A >> B;

  count = N / (A + B);
  ama = N % (A + B);
  if (ama > A > 0) {
    ama = A;
  }

  cout << count * A + ama << endl;
}
Problem p02754 (C++)

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

using namespace std;

int main() {
  long n, a, b;
  cin >> n >> a >> b;
  long m = a + b;
  long r = n % m;
  long ans = (a / m) * a + min(r, a);
  return ans;
}

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

using namespace std;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  cout << n / (a + b) * a + min(n % (a + b), a);
}


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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

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

  ll ans = 0;
  ll cnt = n;

  while (cnt > 0) {
    ans += a;
    cnt -= a;
    if (cnt <= 0) {
      ans += cnt;
      break;
    }
    cnt -= b;
    if (cnt <= 0) {
      break;
    }
  }

  dunk(ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main() {
  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 n, a, b;
  cin >> n >> a >> b;
  cout << (n / (a + b)) * a + min(n % (a + b), a);
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  unsigned 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 <iostream>
using namespace std;

int main() {

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

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

  return 0;
}

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

int main() {

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

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

  return 0;
}
Problem p02754 (C++)

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

int main() {

  long long int N, A, B;
  cin >> N >> A >> B;

  long long count = 0;
  bool turn = true;
  while (N) {
    if (turn) {
      if (N > A) {
        count += A;
        N -= A;
      } else {
        count += N;
        N = 0;
      }
      turn = false;
    } else {
      if (N > B)
        N -= B;
      else
        N = 0;
      turn = true;
    }
  }

  cout << count << "\n";

  return 0;
}

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

int main() {

  long long int N, A, B;
  cin >> N >> A >> B;

  long long int fixedcount = (N / (A + B)) * A;
  long long int remainder = (N % (A + B));
  if (remainder < A)
    cout << (fixedcount + remainder) << "\n";
  else
    cout << (fixedcount + A) << "\n";

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; }
int main(int argc, char *argv[]) {
  ll n, a, b;
  cin >> n >> a >> b;
  string r;
  ll ans = 0;
  rep(i, n) {
    rep(j, a) {
      ans++;
      r.append("b");
      if (r.size() >= n)
        goto fin;
    }
    rep(k, b) {
      r.append("r");
      if (r.size() >= n)
        goto fin;
    }
  }
fin:
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; }
int main(int argc, char *argv[]) {
  ll n, a, b;
  cin >> n >> a >> b;
  if ((n - n / (a + b) * (a + b)) > a)
    cout << n / (a + b) * a + a << endl;
  else
    cout << n / (a + b) * a + n - n / (a + b) * (a + b) << endl;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)

int main() {

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


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)

int main() {

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
using namespace std;

int main() {
  int N, A, B, tmp, r, ans;

  cin >> N >> A >> B;

  tmp = N / (A + B);
  r = N % (A + B);

  if (A <= r) {
    ans = (tmp + 1) * A;
  } else {
    ans = tmp * A + r;
  }

  cout << ans;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
using namespace std;

int main() {
  long long int N, A, B, tmp, r, ans;

  cin >> N >> A >> B;

  tmp = N / (A + B);
  r = N % (A + B);

  if (A <= r) {
    ans = (tmp + 1) * A;
  } else {
    ans = tmp * A + r;
  }

  cout << ans;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
static const double pi = 3.141592653589793;
typedef pair<int64_t, int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int64_t a, b, c;
  cin >> a >> b >> c;
  int64_t i = 0;
  int64_t sum = 0;
  int64_t r = b;

  while (i < a) {
    if (r != 0) {
      r--;
      sum = sum + 1;
      i++;
    }
    if (r == 0) {
      r = b;
      i = i + c;
    }
  }
  cout << sum;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
static const double pi = 3.141592653589793;
typedef pair<int64_t, int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int64_t a, b, c;
  cin >> a >> b >> c;
  int64_t count = a / (b + c);
  if (a - count * (b + c) > b)
    cout << (count + 1) * b;
  else
    cout << count * b + a - count * (b + c);
}
Problem p02754 (C++)

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

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair<int, int>
#define mp(a, b) make_pair(a, b)

inline int read() {
  int x = 0, neg = 1;
  char op = getchar();
  while (!isdigit(op)) {
    if (op == '-')
      neg = -1;
    op = getchar();
  }
  while (isdigit(op)) {
    x = 10 * x + op - '0';
    op = getchar();
  }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10)
    print(x / 10);
  putchar(x % 10 + '0');
}

int n, blue, red;

int main() {
  // freopen("in.txt","r",stdin);
  cin >> n >> blue >> red;
  cout << n / (blue + red) * blue + min(n % (blue + red), blue) << endl;
  return 0;
}


Fixed submission:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair<int, int>
#define mp(a, b) make_pair(a, b)

inline int read() {
  int x = 0, neg = 1;
  char op = getchar();
  while (!isdigit(op)) {
    if (op == '-')
      neg = -1;
    op = getchar();
  }
  while (isdigit(op)) {
    x = 10 * x + op - '0';
    op = getchar();
  }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10)
    print(x / 10);
  putchar(x % 10 + '0');
}

ll n, blue, red;

int main() {
  // freopen("in.txt","r",stdin);
  cin >> n >> blue >> red;
  cout << n / (blue + red) * blue + min(n % (blue + red), blue) << endl;
  return 0;
}
Problem p02754 (C++)

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

int main() {

  int n, a, b;
  int ans, amariblue;
  cin >> n >> a >> b;
  ans = n / (a + b) * a;
  amariblue = min(n % (a + b), a);
  ans += amariblue;

  cout << ans << endl;

  return 0;
}

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

int main() {

  long long int n, a, b;
  long long int ans, amariblue;
  cin >> n >> a >> b;
  ans = n / (a + b) * a;
  amariblue = min(n % (a + b), a);
  ans += amariblue;

  cout << ans << endl;

  return 0;
}
Problem p02754 (C++)

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

int main() {
  int n, a, b;
  int q, r;
  int sum = 0;
  std::cin >> n >> a >> b;
  q = (n / (a + b));
  r = (n % (a + b));
  sum = q * a;
  if (r >= a)
    sum += a;
  else
    sum += r;
  std::cout << sum << std::endl;

  return 0;
}

Fixed submission:
#include <iostream>

int main() {
  long long n, a, b;
  long long q, r;
  long long sum = 0;
  std::cin >> n >> a >> b;
  q = (n / (a + b));
  r = (n % (a + b));
  sum = q * a;
  if (r >= a)
    sum += a;
  else
    sum += r;
  std::cout << sum << std::endl;

  return 0;
}
Problem p02754 (C++)

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

using namespace std;

int main(void) {
  int n, a, b, set, res;

  cin >> n >> a >> b;

  set = n / (a + b);
  res = set * a;
  n -= set * (a + b);
  if (n > a) {
    res += a;
  } else {
    res += n;
  }

  cout << res << endl;

  return 0;
}


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

using namespace std;

int main(void) {
  unsigned long long n, a, b, set, res;

  cin >> n >> a >> b;

  set = n / (a + b);
  res = set * a;
  n -= set * (a + b);
  if (n > a) {
    res += a;
  } else {
    res += n;
  }

  cout << res << endl;

  return 0;
}
Problem p02754 (C++)

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

using namespace std;

int main(void) {
  int n, a, b, r, ans;
  cin >> n >> a >> b;

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

  cout << ans;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

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

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

  cout << ans;

  return 0;
}
Problem p02754 (C++)

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

int main() {
  int n, a, b, c, d, e, f;
  string s;
  cin >> n >> a >> b;
  c = a + b;
  d = n % c;
  e = n / c;
  if (d > a) {
    e = e + 1;
    f = e * a;
    cout << f;
  } else {
    f = e * a;
    f = f + d;
    cout << f;
  }
}

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

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

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

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


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

int main() {
  long long n, a, b;
  long long q, r;
  cin >> n >> a >> b;
  q = n / (a + b);
  r = n % (a + b);
  if (r > a)
    cout << a * q + a << endl;
  else
    cout << a * q + r << 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;
  cout << N / (A + B) * A + min(A, N % (A + B)) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  cout << N / (A + B) * A + min(A, N % (A + B)) << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  long long int in, blue, red, ans = 0;
  cin >> in >> blue >> red;
  if (blue == 0) {
    cout << 0 << endl;
    return (0);
  }
  while (1) {
    if (in <= 0)
      break;
    if (in - blue <= 0) {
      ans += in;
      break;
    }
    ans += blue;
    in -= (blue + red);
  }
  cout << ans << endl;
  return (0);
}

Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  long long int in, blue, red, ans = 0;
  cin >> in >> blue >> red;
  if (blue == 0) {
    cout << 0 << endl;
    return (0);
  }
  ans = in / (blue + red) * blue;
  ans += in % (blue + red) > blue ? blue : in % (blue + red);
  cout << ans << endl;
  return (0);
}
Problem p02754 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = (int)(a); (i) < (int)(b); i++)
typedef long long ll;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

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

  ll ans = 0;
  if (a == 0) {
    ans = 0;
    cout << ans << endl;
    return ans;
  }
  if (b == 0) {
    ans = n;
    cout << ans << endl;
    return ans;
  }

  ll total = 0;
  rep(i, n) {
    total += (i % 2 == 0) ? a : b;
    //   cout << ans << " " << total << endl;
    if (i % 2 == 0)
      ans += a;
    if (total >= n) {
      if (i % 2 == 0) {
        ans -= total - n;
        break;
      } else {
        break;
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = (int)(a); (i) < (int)(b); i++)
typedef long long ll;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

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

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

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

using namespace std;

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

Fixed submission:
#include <iostream>

using namespace std;

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

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

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

  r = N % (A + B);
  blues = (N / (A + B)) * A;
  blues += min(A, r);
  cout << blues << endl;
  return 0;
}


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

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

  r = N % (A + B);
  blues = (N / (A + B)) * A;
  blues += min(A, r);
  cout << blues << endl;
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)

int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;

// --------------------------------------
int n, a, b;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a >> b;

  ll ans = 0;

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


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)

int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;

// --------------------------------------
ll n, a, b;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a >> b;

  ll ans = 0;

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

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, r, b;
  cin >> n >> b >> r;
  if (n % (r + b) == 0) {

    cout << (n / (r + b)) * b << endl;
  } else {
    if (n % (b + r) >= b) {

      cout << n / (b + r) * b + b << endl;
    } else if (n % (b + r) < b) {
      cout << n / (b + r) * b + n % (b + r) << endl;
    }
  }
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long n, r, b;
  cin >> n >> b >> r;
  if (n % (r + b) == 0) {

    cout << (n / (r + b)) * b << endl;
  } else {
    if (n % (b + r) >= b) {

      cout << n / (b + r) * b + b << endl;
    } else if (n % (b + r) < b) {
      cout << n / (b + r) * b + n % (b + r) << endl;
    }
  }
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return (0)
#define rep(i, n) for (int(i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for (int(i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for (auto &(e) : (elem))
#define FAST                                                                   \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
using ll = long long;
using ull = unsigned long long;

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

  ll ab = n / (a + b);
  ll aab = n % (a + b);

  ll ans = a * ab;
  if (aab <= a) {
    ans += aab;
  } else {
    ans += (aab / a) * a;
  }

  println(ans);
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return (0)
#define rep(i, n) for (int(i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for (int(i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for (auto &(e) : (elem))
#define FAST                                                                   \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
using ll = long long;
using ull = unsigned long long;

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

  ll ab = n / (a + b);
  ll aab = n % (a + b);

  ll ans = a * ab;
  ans += min(aab, a);

  println(ans);
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll inf = 1e6 + 5;
vector<int> freq(5);
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll total = b * (a / (b + c));
  ll left = a % (b + c);
  for (int i = 0; i < left; i++) {
    if (i < b) {
      total++;
    }
  }
  cout << total;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll inf = 1e6 + 5;
vector<int> freq(5);
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll total = b * (a / (b + c));
  ll left = a % (b + c);
  total += min(left, b);
  cout << total;
}
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() {
  long long int n, a, b;
  cin >> n >> a >> b;
  cout << (n / (a + b) * a + min(n % (a + b), a)) << endl;
}
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(A, N % (A + B)) << endl;
  return 0;
}


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

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

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); i++)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); i++)
#define FORR(i, a, b)                                                          \
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))
#define ALL(v) (v).begin(), (v).end()

#define DEBUG(x) cerr << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                                                           \
  cerr << #v << ": ";                                                          \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", ";                             \
  cerr << endl

ll n, a, b;

int main() {
  cin >> n >> a >> b;
  ll ans = 0;
  ll total = 0;
  while (total < n) {
    ll addblue = min(a, n - total);
    total += addblue;
    ans += addblue;
    ll addred = min(b, n - total);
    total += addred;
  }
  printf("%lld\n", ans);
  return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); i++)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); i++)
#define FORR(i, a, b)                                                          \
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))
#define ALL(v) (v).begin(), (v).end()

#define DEBUG(x) cerr << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                                                           \
  cerr << #v << ": ";                                                          \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", ";                             \
  cerr << endl

ll n, a, b;

int main() {
  cin >> n >> a >> b;
  ll ans = 0;
  ll total = 0;
  ll unit = a + b;
  ll unitcount = n / unit;
  ans += unitcount * a;
  total += unitcount * (a + b);
  while (total < n) {
    ll addblue = min(a, n - total);
    total += addblue;
    ans += addblue;
    ll addred = min(b, n - total);
    total += addred;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int zong, ans = 0, h, l, now, yu, c;
  cin >> zong >> l >> h;
  yu = zong % (h + l);
  now = zong / (h + l);
  ans = now * l;
  if (yu <= l) {
    ans += yu;
  } else {
    ans += l;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long int zong, ans = 0, h, l, now, yu, c;
  cin >> zong >> l >> h;
  yu = zong % (h + l);
  now = zong / (h + l);
  ans = now * l;
  if (yu <= l) {
    ans += yu;
  } else {
    ans += l;
  }
  cout << ans << endl;
  return 0;
}
Problem p02754 (C++)

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

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

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

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

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

int main() {
  int n, a, b;
  /*入力*/
  cin >> n >> a >> b;
  long c = a + b;
  long ans = a * (n / c);
  int rest = n % c;
  ans += min(rest, a);
  cout << ans << endl;
  return 0;
}


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

int main() {
  long long n, blue, red;
  cin >> n >> blue >> red;
  /**/
  long long rest = n % (blue + red);
  long long count = (n - rest) / (blue + red);
  long long ans = blue * count + min(rest, blue);
  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;
  cin >> n >> a >> b;
  if (n % (a + b) >= a)
    cout << (n / (a + b)) * a + a << endl;
  else
    cout << n - (n / (a + b)) * b << endl;
  return 0;
}

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 + a << endl;
  else
    cout << n - (n / (a + b)) * b << endl;
  return 0;
}
Problem p02754 (C++)

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

int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  long long ans = 0, num = 0;
  while (true) {
    rep(i, a) {
      ans++;
      num++;
      if (num == n) {
        cout << ans << endl;
        return 0;
      }
    }
    rep(i, b) {
      num++;
      if (num == n) {
        cout << ans << endl;
        return 0;
      }
    }
  }
}

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

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

Buggy submission (status: Runtime Error):
n, a, b = [int(i) for i in input().split()]
if a == 0:
    print(0)
else:
    x = (n // (a + b)) + 1
    balls = []
    for i in range(x):
        balls += list("b" * a) + list("r" * b)
    ans = 0
    for i in range(n):
        if balls[i] == "b":
            ans += 1
    print(ans)


Fixed submission:
n, a, b = [int(i) for i in input().split()]
ans = (n // (a + b)) * a
rem = n % (a + b)
ans += min(rem, a)
print(ans)
Problem p02754 (Python)

Buggy submission (status: Time Limit Exceeded):
n, a, b = map(int, input().split())
ans = []
while True:
    for _ in range(a):
        ans.append("b")
    if len(ans) >= n:
        break
    for _ in range(b):
        ans.append("r")
    if len(ans) >= n:
        break
print(ans[:n].count("b"))


Fixed submission:
n, a, b = map(int, input().split())
ans = (n // (a + b)) * a
if n % (a + b) > a:
    print(ans + a)
else:
    print(ans + n % (a + b))
Problem p02754 (Python)

Buggy submission (status: Time Limit Exceeded):
n, a, b = map(int, input().split())

acnt = 0
bcnt = 0
while True:
    acnt += a
    if acnt + bcnt >= n:
        acnt -= (acnt + bcnt) - n
        break
    bcnt += b
    if acnt + bcnt >= n:
        break
print(acnt)


Fixed submission:
n, a, b = map(int, input().split())
amari = n % (a + b)
sho = n // (a + b)
if n <= a:
    print(n)
elif amari == 0:
    print(a * sho)
elif amari < a:
    print(a * sho + amari)
else:
    print(a * sho + a)
Problem p02754 (Python)

Buggy submission (status: Runtime Error):
n, a, b = map(int, input().split())
s = "a" * a + "b" * b
S = s * (int(n / (a + b)) + 1)
print(S[:n].count("a"))


Fixed submission:
n, a, b = map(int, input().split())
if a == 0:
    print(0)
elif n <= a:
    print(n)
else:
    r = int(n / (a + b))
    if n % (a + b) < a:
        print(n - r * b)
    else:
        print(a * (r + 1))
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  // std::stack<int> stack;
  long long n, a, b;
  cin >> n >> a >> b;
  long long ans = 0;
  long long cnt = 0;
  while (cnt < n) {
    if (n - cnt < a) {
      ans += n - cnt;
      cnt += a;
      break;
    } else {
      ans += a;
      cnt += a;
    }
    cnt += b;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  // std::stack<int> stack;
  long long n, a, b;
  cin >> n >> a >> b;
  long long ans = 0;
  long long cy = n / (a + b);
  ans += cy * a;
  long long yo = n % (a + b);
  ans += min(yo, a);
  cout << ans << endl;
  return 0;
}
Problem p02754 (C++)

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

using namespace std;

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


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef unsigned long long ll;

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

  ll s = 0;
  ll bl = 0;

  bool blue = 1;

  while (s < n) {
    if (blue) {
      s += a;
      bl += a;
    } else {
      s += b;
    }
    blue = !blue;
  }
  if (!blue) {
    cout << bl - (s - n) << endl;
  } else {
    cout << bl << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef unsigned long long ll;

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

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

int main(void) {
  long long int n = 0, a = 0, b = 0;
  long long int cnt = 0, ans = 0, num = 0;

  scanf("%lld%lld%lld", &n, &a, &b);

  cnt = n / (a + b);
  num = (a + b) * cnt;
  ans = a * cnt;
  //    printf("cnt:%lld num:%lld ans:%lld\n", cnt, num, ans);

  long long int tmp = 1;
  while (num < n) {
    if (tmp <= a) {
      ans++;
    }
    num++;
    tmp++;
  }

  printf("%lld\n", ans);

  return 0;
}


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

int main(void) {
  long long int n = 0, a = 0, b = 0;
  long long int cnt = 0, ans = 0, num = 0;

  scanf("%lld%lld%lld", &n, &a, &b);

  cnt = n / (a + b);
  num = (a + b) * cnt;
  ans = a * cnt;
  //    printf("cnt:%lld num:%lld ans:%lld\n", cnt, num, ans);

  long long int tmp = 1;
  if ((n - num) < a) {
    ans += n - num;
  } else {
    ans += a;
  }

  printf("%lld\n", ans);

  return 0;
}
Problem p02754 (Python)

Buggy submission (status: Time Limit Exceeded):
N, A, B = map(int, input().split())

ans = 0

while N > 0:
    red = min(N, A)
    ans += red
    N -= red
    blue = min(N, B)
    N -= blue
print(ans)


Fixed submission:
N, A, B = map(int, input().split())

rep = N // (A + B)
ans = A * rep
diff = N - (A + B) * rep
ans += min(diff, A)
print(ans)
Problem p02754 (C++)

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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  long long line = 0, ans = 0;
  while (line + A + B <= N) {
    line += A + B;
    ans += A;
  }
  if (line + A <= N) {
    ans += A;
  } else {
    ans += N - line;
  }
  cout << ans << endl;
}

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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  long long line = 0, ans = 0;
  long long tmp;
  tmp = N / (A + B);
  line = (A + B) * tmp;
  ans = A * tmp;
  if (line + A <= N) {
    ans += A;
  } else {
    ans += N - line;
  }
  cout << ans << endl;
}
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 X = A + B;
  long long c = N / X;
  long long z = N % (X * c);
  long long g;
  if (z <= A)
    g = z;
  if (z > A)
    g = A;
  long long ans = A * c + g;
  cout << ans << 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 X = A + B;
  long long c = N / X;
  long long z;
  if (c != 0)
    z = N % (X * c);
  else {
    z = 0;
    if (N < A)
      cout << N << endl;
    else {
      cout << A << endl;
    }
    return 0;
  }
  long long g;
  if (z <= A)
    g = z;
  if (z > A)
    g = A;
  long long ans = A * c + g;
  cout << ans << endl;
  return 0;
}
Problem p02754 (C++)

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


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll int n, a, b;
  cin >> n >> a >> b;
  ll int temp = a * (n / (a + b));
  n = n % (a + b);
  if (n < a) {
    temp += n;
  } else {
    temp += a;
  }
  if (a == 0) {
    cout << "0";
    return 0;
  } else {
    cout << temp;
  }
  return 0;
}
Problem p02754 (C++)

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

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


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

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

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

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

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

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

Buggy submission (status: Runtime Error):
#include <iostream>
#define MIN(a, b) ((a > b) ? b : a)
using namespace std;

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

Fixed submission:
#include <iostream>
#define MIN(a, b) ((a > b) ? b : a)
using namespace std;

int main() {
  long 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, i, sum = 0, c;
  cin >> n >> a >> b;
  c = n / (a + b);
  sum = a * c + sum;
  c = n % (a + b);
  if (c <= a)
    sum = sum + c;
  else
    sum = sum + a;
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, b, i, sum = 0, c;
  cin >> n >> a >> b;
  c = n / (a + b);
  sum = a * c + sum;
  c = n % (a + b);
  if (c <= a)
    sum = sum + c;
  else
    sum = sum + a;
  cout << sum << endl;
  return 0;
}