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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  long long n, a, b, cnt = 0;
  cin >> n >> a >> b;
  while (n >= a + b) {
    n -= a + b;
    cnt += a;
  }
  if (n >= a) {
    n -= a;
    cnt += a;
  } else
    cnt += n;
  cout << cnt;
  return 0;
}


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

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

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

  S = A + B;
  R = (N / S) * A;
  R += (N % S) > A ? A : N % S;

  cout << R << endl;
}


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

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

  S = A + B;
  R = (N / S) * A;
  R += (N % S) > A ? A : N % S;

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

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

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

  int counter = 0;
  while (N >= AB) {
    N -= AB;
    counter++;
  }

  if (N < A) {
    cout << counter * A + N << endl;
  } else {
    cout << (counter + 1) * A << 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++)

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

  ll counter = 0;
  counter = N / AB;
  N %= AB;

  if (N < A) {
    cout << counter * A + N << endl;
  } else {
    cout << (counter + 1) * A << endl;
  }
}
Problem p02754 (C++)

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

using namespace std;
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  cout << (N / (A + B)) * A + min(N % (A + B), A) << endl;

  return 0;
}


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

using namespace std;
int main() {
  long N, A, B;
  cin >> N >> A >> B;
  cout << (N / (A + B)) * A + min(N % (A + B), A) << endl;

  return 0;
}
Problem p02754 (Python)

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

x = []
cnt = 0
flag = True
while cnt < n:
    if flag:
        for j in range(a):
            if cnt + j >= n:
                break
            x.append(1)
        cnt += a
        flag = False
    else:
        for j in range(b):
            if cnt + j >= n:
                break
            x.append(0)
        cnt += b
        flag = True

cnt = 0
for i in range(n):
    if x[i] == 1:
        cnt += 1

print(cnt)


Fixed submission:
n, a, b = map(int, input().split())

ans = n // (a + b) * a
rem = n % (a + b)
print(ans + min(rem, a))
Problem p02754 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3
n, a, b = map(int, input().split())
s = "b" * a
r = "r" * b
ans = ""
for i in range(n):
    ans += s
    ans += r
    if len(ans) >= n:
        break
print(ans[:n].count("b"))


Fixed submission:
#!/usr/bin/env python3
n, a, b = map(int, input().split())
x = n // (a + b)
r = n % (a + b)
print(a * x + r) if r < a else print((a * (x + 1)))
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 rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

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

  ll N = 0;
  ll res = 0;
  while (N < n) {
    N += a;
    res += a;
    if (N >= n) {
      res -= N - n;
      break;
    }

    N += b;
  }

  cout << res << endl;

  return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

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

  ll res = n / (a + b) * a;
  res += min(n % (a + b), a);

  cout << res << endl;

  return 0;
}
Problem p02754 (C++)

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

int main() {
  int N, A, B, i, j, s, w;
  cin >> N >> A >> B;

  w = A + B;

  i = N / w;
  j = N % w;

  if (j >= A)
    j = A;

  s = i * A + j;
  cout << s << endl;
}

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

int main() {
  long long N, A, B, i, j, s, w;
  cin >> N >> A >> B;

  w = A + B;

  i = N / w;
  j = N % w;

  if (j >= A)
    j = A;

  s = i * A + j;
  cout << s << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>

using namespace std;

void A() {
  string S;
  cin >> S;

  if (S[0] == S[1] && S[1] == S[2]) {
    cout << "No" << endl;
    return;
  }

  cout << "Yes" << endl;
}

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

  long long int cntAll = 0, cntBlue = 0, cntRed = 0;
  while (true) {
    if (N <= cntAll)
      break;
    cntAll += A;
    ++cntBlue;

    if (N <= cntAll)
      break;
    cntAll += B;
    ++cntRed;
  }

  if (cntBlue == cntRed)
    cout << A * cntBlue << endl;
  else
    cout << N - B * cntRed << endl;
}

int main() {
  // A();
  B();

  return 0;
}

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

using namespace std;

void A() {
  string S;
  cin >> S;

  if (S[0] == S[1] && S[1] == S[2]) {
    cout << "No" << endl;
    return;
  }

  cout << "Yes" << endl;
}

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

  cout << N / (A + B) * A + min(A, N % (A + B)) << endl;
}

int main() {
  // A();
  B();

  return 0;
}
Problem p02754 (C++)

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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll i = 0;
  ll res = 0;
  while (i < n) {
    ll blue = 0;
    while (blue < a && i < n) {
      i++;
      blue++;
      res++;
    }
    ll red = 0;
    while (red < b && i < n) {
      i++;
      red++;
    }
  }
  cout << res << endl;
  return 0;
}


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

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

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

int main() {
  int num, b, r;
  int tmpRoop = 0;
  int tmpAmari = 0;
  int kekka = 0;

  cin >> num >> b >> r;

  tmpRoop = num / (b + r);
  tmpAmari = num % (b + r);

  if (tmpAmari == 0) {
    kekka = tmpRoop * b;
  } else if (tmpAmari > 0) {
    if (b - tmpAmari >= 0) {
      kekka = tmpRoop * b + tmpAmari;
    } else {
      kekka = tmpRoop * b + b;
    }
  }

  cout << kekka;
}


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

int main() {
  long long num, b, r;
  long long tmpRoop = 0;
  long long tmpAmari = 0;
  long long kekka = 0;

  cin >> num >> b >> r;

  tmpRoop = num / (b + r);
  tmpAmari = num % (b + r);

  if (tmpAmari == 0) {
    kekka = tmpRoop * b;
  } else if (tmpAmari > 0) {
    if (b - tmpAmari >= 0) {
      kekka = tmpRoop * b + tmpAmari;
    } else {
      kekka = tmpRoop * b + b;
    }
  }

  cout << kekka;
}
Problem p02754 (C++)

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

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

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

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

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

int main() {
  int N, A, B, C;
  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 (Python)

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

while n_count < n:
    for i in range(a):
        if n_count >= n:
            break
        a_count += 1
        n_count += 1
    n_count += b

print(a_count)


Fixed submission:
n, a, b = map(int, input().split())
ans = n // (a + b) * a
rem = n % (a + b)
ans += min(rem, a)
print(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;
  cout << (N / (A + B)) * A + min(N - N / (A + B) * (A + B), A) << 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(N - N / (A + B) * (A + B), A) << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <unordered_map>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[]) {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  while (n - (a + b) > 0) {
    n -= a + b;
    ans += a;
  }

  ans += min(a, n);

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <unordered_map>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[]) {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  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, ans, rem;
  cin >> n >> a >> b;
  ans = n / (a + b) * a;
  rem = n % (a + b);
  ans += min(rem, a);
  cout << ans << endl;

  return 0;
}

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

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

  return 0;
}
Problem p02754 (C++)

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

int main() {
  int N, A, B, i, temp = 0;
  int red = 0, blue = 0, nokori = 0;
  cin >> N >> A >> B;
  temp = N / (A + B);
  blue += temp * A;
  nokori = N - temp * (A + B);
  if (nokori <= A) {
    blue += nokori;
  } else {
    blue += A;
  }

  cout << blue << endl;
}

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

int main() {
  long long N, A, B, i, temp = 0;
  long long red = 0, blue = 0, nokori = 0;
  cin >> N >> A >> B;
  temp = N / (A + B);
  blue += temp * A;
  nokori = N - temp * (A + B);
  if (nokori <= A) {
    blue += nokori;
  } else {
    blue += A;
  }

  cout << blue << endl;
}
Problem p02754 (Python)

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

blue_count = 0
while n != 0:
    # 青
    if n > a:
        n -= a
        blue_count += a
    else:
        blue_count += n
        n = 0
    if n > b:
        n -= b
    else:
        n = 0

print(blue_count)


Fixed submission:
n, a, b = list(map(int, input().split(" ")))

blue_count = a * (n // (a + b))
n -= (a + b) * (n // (a + b))
if n >= a:
    blue_count += a
else:
    blue_count += n
print(blue_count)
Problem p02754 (Python)

Buggy submission (status: Runtime Error):
n, a, b = map(int, input().split(" "))
str = ("b" * a + "r" * b) * -(-n // (a + b))
print(str[0:n].count("b"))


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

Buggy submission (status: Runtime Error):
n, a, b = map(int, input().split().rstrip())
k = n // (a + b)
r = n % (a + b)
print(k * a + min(r, a))


Fixed submission:
n, a, b = map(int, input().rstrip().split())
k = n // (a + b)
r = n % (a + b)
print(k * a + min(r, a))
Problem p02754 (Python)

Buggy submission (status: Runtime Error):
N, A, B = map(int, input().split())
a = []

while len(a) != N:
    a.append("b" * A)
    a.append("a" * B)

a = "".join(a)

b = a[0:N]

c = b.count("b")
print(c)


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

Buggy submission (status: Time Limit Exceeded):
n, b, r = map(int, input().split())
x = []
bool = True
while bool:
    for i in range(b):
        if len(x) == n:
            bool = False
        else:
            x.append("b")
    for j in range(r):
        if len(x) == n:
            bool = False
        else:
            x.append("r")

print(x.count("b"))


Fixed submission:
n, b, r = map(int, input().split())
b1 = n // (b + r)
b2 = n % (b + r)
if b == 0:
    print(0)
elif r == 0:
    print(n)
elif b2 != 0 and b2 <= b:
    b1 = b1 * b + b2
    print(b1)
elif b2 != 0 and b2 > b:
    b1 = b1 * b + b
    print(b1)
elif n % (b + r) == 0:
    print(b1 * b)
Problem p02754 (C++)

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

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

  cin >> n >> a >> b;

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

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

  cout << ans;
}


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

int main() {
  long n, a, b, ans;

  cin >> n >> a >> b;

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, a, b, c;
  cin >> N >> a >> b;
  long long cnt = 0;
  if (N % (a + b) == 0) {
    cnt = N / (a + b);
    cout << a * cnt << endl;
  } else {
    cnt = N / (a + b);
    long long ans = cnt * a;
    for (long long i = cnt * (a + b) + 1; i <= N; ++i) {
      if (i % (a + b) <= a)
        ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, a, b, c;
  cin >> N >> a >> b;
  long long cnt = 0;
  if (N % (a + b) == 0) {
    cnt = N / (a + b);
    cout << a * cnt << endl;
  } else {
    cnt = N / (a + b);
    long long ans = cnt * a;
    ans += min(N - (cnt * (a + b) + 1) + 1, a);
    cout << ans << endl;
  }

  return 0;
}
Problem p02754 (C++)

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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  string x;
  for (ll i = 0; i < a; i++) {
    x += 'b';
  }
  for (ll i = 0; i < b; i++) {
    x += 'r';
  }
  ll tmp = n % (a + b);
  ll tasu;
  if (tmp > a) {
    tasu = a;
  } else if (tmp <= a) {
    tasu = tmp;
  }
  ll tmp2 = n / (a + b);

  ll ans = a * tmp2;
  cout << ans + tasu << endl;
  // cout << 7%8 << endl;//=7
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

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

  ll tmp = n % (a + b);
  ll tasu;
  if (tmp > a) {
    tasu = a;
  } else if (tmp <= a) {
    tasu = tmp;
  }
  ll tmp2 = n / (a + b);

  ll ans = a * tmp2;
  cout << ans + tasu << endl;
  // cout << 7%8 << endl;//=7
  return 0;
}
Problem p02754 (C++)

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

int main() {
  int n, a, b, r;
  cin >> n >> a >> b;
  r = (n / (a + b)) * a + (n % (a + b) < a ? n % (a + b) : a);
  cout << r;
}

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;           // 10^19 < 9223372036854775807
typedef unsigned long long ull; // 10^20 < 18446744073709551615

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())

#define MOD 1000000007

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

  ll ans = 0, i = 0, x = 0;
  vector<char> boll(N + 10);

  while (x++ < N) {
    REP(j, A) {
      if (i < N) {
        boll[i++] = 'b';
        ans++;
      }
    }
    REP(k, B) {
      if (i < N) {
        boll[i++] = 'r';
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;           // 10^19 < 9223372036854775807
typedef unsigned long long ull; // 10^20 < 18446744073709551615

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())

#define MOD 1000000007

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

  ll C;
  C = A + B;
  ll ans;
  ans = A * (N / C);
  ans += min(N % C, A);
  cout << ans << endl;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cstddef>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

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

  long long unsigned ans = 0;
  while (N >= (A + B)) {
    N -= A;
    N -= B;
    ans += A;
  }
  if (N >= A) {
    ans += A;
  } else {
    ans += N;
  }
  std::cout << ans << std::endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cstddef>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

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

  long long unsigned ans = 0;
  ans = A * (N / (A + B));
  N = N % (A + B);
  if (N >= A) {
    ans += A;
  } else {
    ans += N;
  }
  std::cout << ans << std::endl;
  return 0;
}
Problem p02754 (C++)

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

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

  cout << D * A + F << endl;

  return 0;
}

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

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

  cout << D * A + F << endl;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

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

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  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) + 1) * A << endl;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {

  ll n, i, j, k, l, a, b;
  cin >> n >> a >> b;
  if (a + b >= n) {
    if (a >= n)
      cout << n << endl;
    else
      cout << a << endl;
  } else {
    if (a == 0)
      cout << 0 << endl;
    else {
      k = n / b;
      cout << n - k * b << endl;
    }
  }
  return 0;
}


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

  ll n, i, j, k, l, a, b;
  cin >> n >> a >> b;
  ll ans = n / (a + b);
  ans *= a;
  k = n % (a + b);
  ans += min(a, k);
  cout << ans << endl;
  return 0;
}
Problem p02754 (C++)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, A, B;
  cin >> N >> A >> B;
  ll all_count = 0, ans = 0;
  while (all_count < N) {
    all_count += A + B;
    if (all_count >= N) {
      ans += min(A, N - (all_count - A - B));
    } else {
      ans += A;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = 0;
  ll q = N / (A + B);
  ans += A * q;
  ll rest = N - (A + B) * q;
  ans += min(rest, A);
  cout << ans << 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 < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
using lint = long long;
int main() {
  int N, A, B;
  int ac;
  int loops, additional;
  cin >> N >> A >> B;
  loops = N / (A + B);
  additional = N % (A + B);
  ac = loops * A;
  if (additional >= A) {
    ac += A;
  } else {
    ac += additional;
  }
  cou(ac);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
using lint = long long;
int main() {
  lint N, A, B;
  lint ac;
  lint loops, additional;
  cin >> N >> A >> B;
  loops = N / (A + B);
  additional = N % (A + B);
  ac = loops * A;
  if (additional >= A) {
    ac += A;
  } else {
    ac += additional;
  }
  cou(ac);
}
Problem p02754 (C++)

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

typedef long long ll;

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

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

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

typedef long long ll;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  cout << n / (a + b) * a + min(a, (n % (a + b)));
}
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;
typedef long long int ll;
const ll MOD = 1000000007;

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

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

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

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int N, A, B;
  int ans = 0, D = 0;
  cin >> N >> A >> B;
  D = N % (A + B);
  if (D > A) {
    D = A;
  }
  ans = N / (A + B) * A + D;
  cout << ans;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long int N, A, B;
  long long int ans = 0, D = 0;
  cin >> N >> A >> B;
  D = N % (A + B);
  if (D > A) {
    D = A;
  }
  ans = N / (A + B) * A + D;
  cout << ans;
}
Problem p02754 (C++)

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

int main() {
  long N, A, B, i, sum = 0, cnt = 0;
  cin >> N >> A >> B;
  vector<string> ball;
  while (sum <= N) {
    for (i = 0; i < A; ++i)
      ball.push_back("b");
    for (i = 0; i < B; ++i)
      ball.push_back("r");
    sum += A;
    sum += B;
  }
  for (i = 0; i < N; ++i) {
    if (ball.at(i) == "b")
      cnt++;
  }
  cout << cnt;
}


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

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

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


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

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

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

  sho = N / (A + B);
  amari = N % (A + B);
  if (amari - A >= 0)
    amari = A;
  cout << A * sho + amari << endl;
}


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

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

  sho = N / (A + B);
  amari = N % (A + B);
  if (amari - A >= 0)
    amari = A;
  cout << A * sho + amari << 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;
  long a = (N / (A + B)) * A;
  long b = N % (A + B);
  if (A <= b)
    b = A;
  cout << a + b << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long N, A, B;
  cin >> N >> A >> B;
  long a = (N / (A + B)) * A;
  long b = N % (A + B);
  if (A <= b)
    b = A;
  cout << a + b << endl;

  return 0;
}
Problem p02754 (C++)

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

int N, A, B;
int quotient, reminder, add, sum;

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

  quotient = N / (A + B);
  reminder = N % (A + B);

  add = reminder;

  if (reminder >= A) {
    add = A;
  }

  sum = quotient * A + add;

  cout << sum << endl;

  return 0;
}

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

long N, A, B;
long quotient, reminder, add, sum;

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

  quotient = N / (A + B);
  reminder = N % (A + B);

  add = reminder;

  if (reminder >= A) {
    add = A;
  }

  sum = quotient * A + add;

  cout << sum << endl;

  return 0;
}
Problem p02754 (C++)

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

using namespace std;

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

  cin >> n >> a >> b;

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

Fixed submission:
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  long long n;
  long long a;
  long long 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;
  cin >> N >> A >> B;
  cout << N / (A + B) * A + min(A, N % (A + B)) << "\n";
}

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

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

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

using namespace std;

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

  cout << N / (A + B) * A + min(N % (A + B), A);

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

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

  cout << N / (A + B) * A + min(N % (A + B), A);

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):

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

int main() {

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

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

  return 0;
}


Fixed submission:

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

int main() {

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

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

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rep(i, a, n) for (int i = a; i < n; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
signed main() {
  ios_base::sync_with_stdio(0);
  int TESTS = 1;
  // cin>>TESTS;
  while (TESTS--) {
    int n, a, b;
    cin >> n >> a >> b;
    int ans = (n / (a + b)) * b;
    ans += n % b;
    cout << ans;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rep(i, a, n) for (int i = a; i < n; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
signed main() {
  ios_base::sync_with_stdio(0);
  int TESTS = 1;
  // cin>>TESTS;
  while (TESTS--) {
    int n, a, b;
    cin >> n >> a >> b;
    int ans = (n / (a + b)) * a;
    if (a != 0)
      ans += min(a, n % (a + b));
    cout << ans;
  }
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
int main() {

  using namespace std;

  int n, r, b, sum, set, amari;
  int ans = 0;
  cin >> n >> b >> r;

  sum = r + b;

  set = n / sum;
  ans += b * set;

  amari = n % sum;

  if (amari >= b) {
    ans += b;
  } else {
    ans += amari;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
int main() {

  using namespace std;

  long n, r, b, sum, set, amari;
  long ans = 0;
  cin >> n >> b >> r;

  sum = r + b;

  set = n / sum;
  ans += b * set;

  amari = n % sum;

  if (amari >= b) {
    ans += b;
  } else {
    ans += amari;
  }

  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;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  ll ans = 0;
  ll diff = 0;

  while (n > 0) {
    diff = min(n, a);
    n -= diff;
    ans += diff;

    diff = min(n, b);
    n -= diff;
  }

  cout << ans << endl;

  return 0;
}


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++)

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

  ll initial = n / (a + b);

  ll ans = initial * a;
  n -= initial * (a + b);
  ll diff = 0;

  while (n > 0) {
    diff = min(n, a);
    n -= diff;
    ans += diff;

    diff = min(n, b);
    n -= diff;
  }

  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;
  cout << N / (A + B) * A + min(A, N % (A + B));
  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));
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ctoi(x) x - '0'
#define pshb(a)                                                                \
  cin >> x;                                                                    \
  a.push_back(x)
#define fr(i, n) for (ll i = 0; i < n; i++)
#define fast ios_base::sync_with_stdio(false);
#define Test                                                                   \
  ll q;                                                                        \
  cin >> q;                                                                    \
  while (q--)
#define ph push_back
#define f first
#define s second
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  ll cnt = a / (b + c);
  ll ans = cnt * b;
  cnt = a % (b + c);
  if (cnt > b)
    ans += b;
  else
    ans += cnt;
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ctoi(x) x - '0'
#define pshb(a)                                                                \
  cin >> x;                                                                    \
  a.push_back(x)
#define fr(i, n) for (ll i = 0; i < n; i++)
#define fast ios_base::sync_with_stdio(false);
#define Test                                                                   \
  ll q;                                                                        \
  cin >> q;                                                                    \
  while (q--)
#define ph push_back
#define f first
#define s second
using namespace std;
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll cnt = a / (b + c);
  ll ans = cnt * b;
  cnt = a % (b + c);
  if (cnt > b)
    ans += b;
  else
    ans += cnt;
  cout << ans;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  long long n, a, b;
  scanf("%lld %lld %lld", &n, &a, &b);
  long long r = n / (a * b) * a;
  n %= (a + b);
  if (n < a)
    r += n;
  else
    r += a;
  printf("%lld\n", r);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  long long n, a, b;
  scanf("%lld %lld %lld", &n, &a, &b);
  long long r = n / (a + b) * a;
  n %= (a + b);
  if (n < a)
    r += n;
  else
    r += a;
  printf("%lld\n", r);
  return 0;
}
Problem p02754 (C++)

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

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


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

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


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

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

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int main(void) {
  int N, B, R;
  cin >> N >> B >> R;
  ll ans = N / (B + R) * B;
  ans += min(B, N % (B + R));
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int main(void) {
  ll N, B, R;
  cin >> N >> B >> R;
  ll ans = N / (B + R) * B;
  ans += min(B, N % (B + R));
  cout << ans << endl;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}

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

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int i, N, A, B, j, k, ans;
  cin >> N >> A >> B;
  k = 0;
  k = N / (A + B);
  j = N % (A + B);
  i = k * (A + B);
  if (N - i > A) {
    ans = k * A + A;
  } else {
    ans = k * A + j;
  }
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long int i, N, A, j, k, ans, B;
  cin >> N >> A >> B;
  k = 0;
  k = N / (A + B);
  j = N % (A + B);
  i = k * (A + B);
  if (N - i > A) {
    ans = k * A + A;
  } else {
    ans = k * A + j;
  }
  cout << ans << endl;
}
Problem p02754 (C++)

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

using namespace std;

int main() {

  int n, a, b;

  cin >> n;
  cin >> a;
  cin >> b;

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

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {

  long long int n, a, b;

  cin >> n;
  cin >> a;
  cin >> b;

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

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long int ball(long long int n, long long int a, long long int b) {
  long long int x = 0, y = 0, z = 0;
  while (z <= n) {
    if (x % 2 == 0) {
      z += a;
      y += a;
    } else {
      z += b;
    }
    x++;
  }
  if (z > n && x % 2 != 0)
    y -= (z - n);
  return y;
}
int main() {
  long long int n, a, b, res;
  cin >> n >> a >> b;
  res = ball(n, a, b);
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long int ball(long long int n, long long int a, long long int b) {
  long long int x, y, z;
  x = n / (a + b);
  y = n % (a + b);
  z = x * a;
  if (y > a)
    z += a;
  else
    z += y;
  return z;
}
int main() {
  long long int n, a, b, res;
  cin >> n >> a >> b;
  res = ball(n, a, b);
  cout << res << 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 (A > N) {
    cout << N << endl;
  } else {
    int64_t ans = 0;
    int64_t x = N / (A + B);
    int64_t mod = N % (A + B);
    ans = x * A;
    if (mod < A) {
      ans += mod;
    } else {
      ans += A;
    }
    cout << ans << endl;
  }
  return 0;
}


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

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

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repto(i, n) for (int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

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


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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repto(i, n) for (int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

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

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <tuple>

#define INF INT_MAX >> 1
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, from, to) for (int i = (from); i < (int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name)                                                           \
  for (int i = 0; i < (int)(name.size()); i++)                                 \
    cin >> name[i];
#define voutput(name)                                                          \
  for (int i = 0; i < (int)(name.size()); i++)                                 \
    cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

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

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <tuple>

#define INF INT_MAX >> 1
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, from, to) for (int i = (from); i < (int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name)                                                           \
  for (int i = 0; i < (int)(name.size()); i++)                                 \
    cin >> name[i];
#define voutput(name)                                                          \
  for (int i = 0; i < (int)(name.size()); i++)                                 \
    cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

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