prithivMLmods/Coder-Stat huggingface dataset:
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 RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);

int main() {

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

  ll ans = 0;
  while (true) {
    if (n > a + b) {
      n -= a + b;
      ans += a;
    } else if (n > a) {
      ans += a;
      break;
    } else {
      ans += n;
      break;
    }
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);

int main() {

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

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

  if (n >= a)
    ans += a;
  else
    ans += n;

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (long long i = 0; i < n; i++)

typedef long long ll;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;

const ll INF = ll(1e18) + 1;

//--------------------------------------------------

ulli gcd(ulli a, ulli b) { return (b <= 0) ? a : gcd(b, a % b); }

ulli lcm(ulli a, ulli b) { return a * b / gcd(a, b); }

//---------------------------------------------------

void Main() {
  ll n, b, r, ans = 0;
  cin >> n >> b >> r;
  rep(i, n) {
    if ((i + 1) % (b + r) < b)
      ans++;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Main();

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (long long i = 0; i < n; i++)

typedef long long ll;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;

const ll INF = ll(1e18) + 1;

//--------------------------------------------------

ulli gcd(ulli a, ulli b) { return (b <= 0) ? a : gcd(b, a % b); }

ulli lcm(ulli a, ulli b) { return a * b / gcd(a, b); }

//---------------------------------------------------

void Main() {
  ll n, b, r, ans = 0;
  cin >> n >> b >> r;
  ll sum = b + r;
  ans += (n / sum) * b;
  ll surplus = n % sum;
  if (surplus <= b)
    ans += surplus;
  else
    ans += b;
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Main();

  return 0;
}
Problem p02754 (C++)

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

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = 0;
  ll cur = 0;
  while (true) {
    // add A
    if (cur + A <= N) {
      cur += A;
      ans += A;
    } else {
      ans += N - cur;
      break;
    }

    // add B
    if (cur + B <= N) {
      cur += B;
    } else {
      break;
    }
  }
  cout << ans << endl;
}

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

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll times = floor(N / (A + B));
  ll rem = N - times * (A + B);
  cout << times * A + min(A, rem) << endl;
}
Problem p02754 (C++)

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

int main() {
  long long n, a, b;
  long long res = 0, mod = 0;
  cin >> n >> a >> b;

  if (a + b == 0) {
    cout << res << endl;
    return 0;
  }

  res = (n / (a + b)) * a;
  if (n % (a + b) > 0 && a > 0)
    for (long long i = 0; i < a && i < n % (a + b); i++)
      res++;

  cout << res << endl;
  return 0;
}

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

int main() {
  long long n, a, b;
  long long res = 0, mod = 0;
  cin >> n >> a >> b;

  if (a + b == 0) {
    cout << res << endl;
    return 0;
  }

  res = (long long)(n / (a + b)) * a;
  if (n % (a + b) > 0 && a > 0) {
    if (n % (a + b) >= a) {
      res += a;
    } else {
      res += n % (a + b);
    }
  }

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

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

#define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // 	freopen("input.txt", "r", stdin);
  // 	freopen("output.txt", "w", stdout);
  // #endif
}

int main() {
  c_p_c();

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

  ll ans = 0;
  while (n > 0) {
    if (n >= a)
      ans += a;
    else
      ans += n;
    n -= (a + b);
  }

  cout << ans << endl;
  return 0;
}

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

#define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // 	freopen("input.txt", "r", stdin);
  // 	freopen("output.txt", "w", stdout);
  // #endif
}

int main() {
  c_p_c();

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

  ll ans = (n / (a + b)) * a;
  ll rem = n % (a + b);
  if (rem >= a)
    ans += a;
  else
    ans += rem;

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

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

using namespace std;

int main() {
  int ans;
  int aa;
  int n, a, b;
  cin >> n >> a >> b;
  aa = n % (a + b);
  if (aa > a)
    aa = a;
  ans = ((n / (a + b)) * a) + aa;

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main() {
  long int ans;
  long int aa;
  long int n, a, b;
  cin >> n >> a >> b;
  aa = n % (a + b);
  if (aa > a)
    aa = a;
  ans = ((n / (a + b)) * a) + aa;

  cout << ans << endl;

  return 0;
}
Problem p02754 (C++)

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

#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)

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

  return 0;
}

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

#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)

int main() {
  unsigned long int n, a, b, k = 0;
  cin >> n >> a >> b;
  k = std::min(n % (a + b), a);
  cout << (n / (a + b)) * a + k;

  return 0;
}
Problem p02754 (C++)

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

int syc(long long i, long long Min, long Max) {
  if (Min <= i && i <= Max) {
    return 1;
  } else {
    exit(1);
    // return 0;
  }
}

int main() {
  long long n, a, b; // a=blue
  long long x, y;    // x=blue
  cin >> n >> a >> b;
  syc(n, 1, 10000000);
  syc(a + b, 0, 10000000);
  long long ans = 0;

  x = n / (a + b);
  y = n % (a + b);
  if (y > a) {
    y = a;
  }

  ans = x * a + y;
  cout << ans << endl;
  return 0;
}


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

int syc(long long i, long long Min, long Max) {
  if (Min <= i && i <= Max) {
    return 1;
  } else {
    exit(1);
    // return 0;
  }
}

int main() {
  long long n, a, b; // a=blue
  long long x, y;    // x=blue
  cin >> n >> a >> b;
  // syc(n,1,1000000000000000000);
  // syc(a+b,0,1000000000000000000);
  if (n < 0 || a < 0 || b < 0)
    exit(1);
  long long ans = 0;

  x = n / (a + b);
  y = n % (a + b);
  if (y > a) {
    y = a;
  }

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

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

int main(void) {

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

  long long int AB = A + B;

  long long int answer = (N / AB) * A;

  // 先頭から何個チェックする？
  long long int check_num = N % AB;

  // 文字列の作成
  std::string str;
  for (long long int i = 0; i < A; i++) {
    str.push_back('b');
  }
  for (long long int i = 0; i < B; i++) {
    str.push_back('r');
  }

  // 確認用
  // cout << str << endl;

  for (long long int i = 0; i < check_num; i++) {
    if (str[i] == 'b') {
      answer++;
    }
  }

  cout << answer;

  return 0;
}

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

int main(void) {

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

  long long int AB = A + B;

  long long int answer = (N / AB) * A;

  // 先頭から何個チェックする？
  long long int check_num = N % AB;

  if (A > check_num) {
    answer += check_num;
  } else {
    answer += A;
  }

  cout << answer;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  int n, a, b, ans, zentai, kaisu, amari;
  cin >> n >> a >> b;
  zentai = a + b;
  kaisu = n / zentai;
  ans = a * kaisu;
  amari = n - kaisu * zentai;
  if (amari < a) {
    ans = ans + amari;
  } else {
    ans = ans + a;
  }
  cout << ans << endl;
}

Fixed submission:
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  long long int n, a, b, ans, zentai, kaisu, amari;
  cin >> n >> a >> b;
  zentai = a + b;
  kaisu = n / zentai;
  ans = a * kaisu;
  amari = n - kaisu * zentai;
  if (amari < a) {
    ans = ans + amari;
  } else {
    ans = ans + a;
  }
  cout << ans << endl;
}
Problem p02754 (C++)

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

#define whole(f, x, ...)                                                       \
  ([&](decltype((x)) whole) {                                                  \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  })(x)
#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, a, b) for (int i = a; i < b; ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main() {
  lint N, A, B;
  lint out = 0;
  cin >> N >> A >> B;
  ;
  // string S;
  // cin >> S;
  // vector<int> a(N);
  lint AB = A + B;
  lint NAB = N / AB;
  lint NAB2 = N % AB;
  out = A * NAB;
  REP(i, NAB2) {
    if (i < A)
      ++out;
  }
  cout << out;
  return 0;
}

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

#define whole(f, x, ...)                                                       \
  ([&](decltype((x)) whole) {                                                  \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  })(x)
#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, a, b) for (int i = a; i < b; ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main() {
  lint N, A, B;
  lint out = 0;
  cin >> N >> A >> B;
  ;
  // string S;
  // cin >> S;
  // vector<int> a(N);
  lint AB = A + B;
  lint NAB = N / AB;
  lint NAB2 = N % AB;
  out = A * NAB;
  if (NAB2 > A) {
    out += A;
  } else {
    out += NAB2;
  }
  cout << out;
  return 0;
}
Problem p02754 (C++)

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

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


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

int main() {
  typedef long long ll;
  ll 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>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ll n, a, b;
  while (cin >> n >> a >> b) {
    ll s = 0, cnt = 0;
    if (a == 0)
      cout << "0" << endl;
    else {
      while (s < n) {
        ll aa = a, bb = b;
        while (s < n && aa > 0) {
          cnt++;
          aa--;
          s += 1;
        }
        while (s < n && bb > 0) {
          bb--;
          s += 1;
        }
      }
      cout << cnt << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ll n, a, b;
  while (cin >> n >> a >> b) {
    ll rslt = n / (a + b) * a;
    ll r = n % (a + b);
    cout << rslt + min(r, a) << endl;
  }
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
namespace FAST_IO {
template <typename T> void read(T &a) {
  a = 0;
  int f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') {
      f = -1;
    }
    c = getchar();
  }
  while (isdigit(c)) {
    a = a * 10 + c - '0';
    c = getchar();
  }
  a = a * f;
}
template <typename T> void write(T a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a > 9) {
    write(a / 10);
  }
  putchar(a % 10 + '0');
}
template <typename T> void writeln(T a) {
  write(a);
  puts("");
}
} // namespace FAST_IO
int n, a, b;
int main() {
  cin >> n >> a >> b;
  cout << (n / (a + b) * a) + min(a, n % (a + b));
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
namespace FAST_IO {
template <typename T> void read(T &a) {
  a = 0;
  int f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') {
      f = -1;
    }
    c = getchar();
  }
  while (isdigit(c)) {
    a = a * 10 + c - '0';
    c = getchar();
  }
  a = a * f;
}
template <typename T> void write(T a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a > 9) {
    write(a / 10);
  }
  putchar(a % 10 + '0');
}
template <typename T> void writeln(T a) {
  write(a);
  puts("");
}
} // namespace FAST_IO
long long n, a, b;
int main() {
  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>
using namespace std;
const int INF = 999999999;

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int INF = 999999999;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main() {
  string s, u;
  int n, a, b, ans;
  cin >> n >> a >> b;
  ans = a * (n / (a + b));
  if (n % (a + b) >= a)
    ans += a;
  else
    ans += n % (a + b);

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1 << 30;
const ll MOD = 1000000007;

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

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

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

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

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

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

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

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

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

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

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

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

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

using namespace std;

int main() {
  int64_t n, a, b, ans = 0;
  cin >> n >> a >> b;
  ans += n / (a + b) * a;
  for (int i = 0; i < n % (a + b); i++) {
    if (i < a)
      ans++;
  }
  cout << ans;
  return 0;
}

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

using namespace std;

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

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

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


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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

int main() {
  fastio;
  int64_t N, A, B;
  cin >> N >> A >> B;
  int64_t total = 0;
  int64_t blue = 0;

  while (total < N) {
    if (total + A >= N) {
      blue += N - total;
      break;
    }
    total += (A + B);
    blue += A;
  }

  cout << blue << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

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

  auto blue = (N / (A + B)) * A;
  auto total = (N / (A + B)) * (A + B);

  while (total < N) {
    if (total + A >= N) {
      blue += N - total;
      break;
    }
    total += (A + B);
    blue += A;
  }

  cout << blue << endl;

  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const ll mod = 1000000000 + 7; // 10^9

// bool is_integer(double x){
//     return floor(x) == x;
// }

// vector<int> bitsearch(int n, int bit) {
//     for (int i = 0; i < n; i++)
//     {
//         vector<int> S(n);
//         if(bit & (1 << i)){
//             S.push_back(i);
//         }
//     }
// }./

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


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const ll mod = 1000000000 + 7; // 10^9

// bool is_integer(double x){
//     return floor(x) == x;
// }

// vector<int> bitsearch(int n, int bit) {
//     for (int i = 0; i < n; i++)
//     {
//         vector<int> S(n);
//         if(bit & (1 << i)){
//             S.push_back(i);
//         }
//     }
// }./

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll b_c = 0;
  b_c = N / (A + B);
  N -= b_c * (A + B);
  ll ans = 0;
  if (N > A) {
    ans += A;
  } else {
    ans += N;
  }
  ans += b_c * A;
  cout << ans << endl;
}
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 int count = 0;
  while (N != 0 && N >= A + B) {
    count = count + A;
    N = N - (A + B);
  }
  if (N != 0 && N < A + B && N <= A) {
    count = count + N;
  } else if (N != 0 && N < A + B && N > A) {
    count = count + A;
  }
  cout << count << endl;
  return 0;
}

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

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

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

  x = n / (a + b);
  ans = x * a + min(n - x * (a + b), a);

  cout << ans << endl;
  return 0;
}

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

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

  x = n / (a + b);
  ans = x * a + min(n - x * (a + b), a);

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

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

using namespace std;

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


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

using namespace std;

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

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

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  long long n, a, b;
  cin >> n >> a >> b;
  long long div;
  long long remain;
  div = n / (a + b);
  remain = n % (a + b);
  long long blue;
  blue = div * a;
  for (long long i(0); i < remain; i++) {
    if (i < a) {
      blue++;
    }
  }
  cout << blue << endl;
  return 0;
}

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll count_blue_balls = 0;
  if (a > 0) {
    for (ll i = 0; i < n; i++) {
      if (i < a || i >= b + a)
        count_blue_balls += 1;
    }
  }
  cout << count_blue_balls << endl;
  return 0;
}

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

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

using namespace std;

int n, x, y, ans;

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> x >> y;
  ans = (n / (x + y)) * x;
  n %= (x + y);
  ans += min(x, n);
  cout << ans;
}


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

using namespace std;

long long n, x, y, ans;

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> x >> y;
  ans = (n / (x + y)) * x;
  n %= (x + y);
  ans += min(x, n);
  cout << ans;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int solve() {
  long long n, a, b;
  cin >> n >> a >> b;
  long long ans = 0;
  while (n >= a) {
    ans += a;
    n -= a + b;
  }
  ans += max(0ll, n);
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int solve() {
  long long n, a, b;
  cin >> n >> a >> b;
  long long remain = max(0ll, n - n / (a + b) * (a + b));
  long long ans = n / (a + b) * a + (remain >= a ? a : remain);

  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}
Problem p02754 (C++)

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

using namespace std;

int main() {
  long long n, a, b, sum = 0;
  cin >> n >> a >> b;
  long long c = n / (a + b), d = n % (a + b);
  string s;
  for (int i = 1; i <= d; i++) {
    if (i <= a)
      sum++;
  }
  sum += a * c;
  cout << sum;
  return 0;
}

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

using namespace std;

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

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

#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr)
#define rep(i, x, y)                                                           \
  for (decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y));              \
       i += 1 - 2 * ((x) > (y)))
#define trav(i, a) for (auto &(i) : (a))
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define clr(a, x) memset((a), (x), sizeof(a)) // array (0,-1)
#define dbg(x)                                                                 \
  cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() {
  cerr << "cpu time : " << double(clock()) / CLOCKS_PER_SEC << "\n";
  return;
}
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int, int>;

void solve() {

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

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

  cout << ans << "\n";
  return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main() {

  fast_io;
  int t = 1;
  // cin >> t;

  while (t--) {
    solve();
  }

  cpuTime();
  return 0;
}


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

#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr)
#define rep(i, x, y)                                                           \
  for (decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y));              \
       i += 1 - 2 * ((x) > (y)))
#define trav(i, a) for (auto &(i) : (a))
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define clr(a, x) memset((a), (x), sizeof(a)) // array (0,-1)
#define dbg(x)                                                                 \
  cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() {
  cerr << "cpu time : " << double(clock()) / CLOCKS_PER_SEC << "\n";
  return;
}
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int, int>;

void solve() {

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

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

  cout << ans << "\n";
  return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main() {

  fast_io;
  int t = 1;
  // cin >> t;

  while (t--) {
    solve();
  }

  cpuTime();
  return 0;
}
Problem p02754 (C++)

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

using namespace std;
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << ((n / (a + b)) * a) + min(n % (a + b), a);

  return 0;
}


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 % (a + b), a);

  return 0;
}
Problem p02754 (C++)

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

  int n, a, b, c, d, out;

  cin >> n >> a >> b;

  d = n % (a + b);
  c = (n - d) / (a + b);

  if (d < a) {
    out = c * a + d;
  } else {
    out = c * a + a;
  }

  cout << out;
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {

  long int n, a, b, c, d, out;

  cin >> n >> a >> b;

  d = n % (a + b);
  c = (n - d) / (a + b);

  if (d < a) {
    out = c * a + d;
  } else {
    out = c * a + a;
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int n, a, b, cnt = 0, mod = 0;
  cin >> n >> a >> b;
  cnt = n / (a + b);
  mod = n % (a + b);
  if (mod >= a)
    mod = a;
  cout << a * cnt + mod << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll n, a, b, cnt = 0, mod = 0;
  cin >> n >> a >> b;
  cnt = n / (a + b);
  mod = n % (a + b);
  if (mod >= a)
    mod = a;
  cout << a * cnt + mod << endl;

  return 0;
}
Problem p02754 (C++)

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

int main() {
  int N, A, B, n;
  cin >> N >> A >> B;
  n = N / (A + B);

  if (N % (A + B) <= A) {
    cout << n * A + N % (A + B);
  } else {
    cout << n * A + A;
  }
  return 0;
}

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

int main() {
  long long N, A, B, n;
  cin >> N;
  cin >> A;
  cin >> B;
  n = N / (A + B);

  if (N % (A + B) <= A) {
    cout << n * A + N % (A + B);
  } else {
    cout << n * A + A;
  }
  return 0;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define MAX 200005

using namespace std;

ll a[MAX];

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


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define MAX 200005

using namespace std;

ll a[MAX];

int main() {
  //    ios_base::sync_with_stdio(false);
  //    cin.tie(0);
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  ans = n / (a + b);
  ans *= a;
  n %= (a + b);
  if (n >= a) {
    ans += a;
  } else {
    ans += n;
  }
  cout << ans << endl;
  return 0;
}
Problem p02754 (C++)

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

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


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

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, r, b;
  cin >> n >> b >> r;
  cout << n / (r + b) * b + min(n % (r + b), b) << endl;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, r, b;
  cin >> n >> b >> r;
  cout << n / (r + b) * b + min(n % (r + b), b) << endl;
}
Problem p02754 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define float long double
#define ll long long
#define int long long
#define vl vector<ll>
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define all(x) x.begin(), x.end()
#define alr(x) x.rbegin(), x.rend()
#define endl '\n'
#define cnl cout << endl;
#define pi 3.141592653589793238
#define ms(x, v) ((x), v, sizeof((x)))
#define MAXN 100009
#define CASET                                                                  \
  int ___T;                                                                    \
  scanf("%lld", &___T);                                                        \
  for (int cs = 1; cs <= ___T; cs++)
template <class T> bool umin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool umax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 200 * 1000 + 9;
const int inf = 1e18;
const int mod = 1e9 + 7;
int i, j, k;
void solve() {
  int n, b, r;
  cin >> n >> b >> r;
  int sum = 0;
  int bl = 0;
  i = 1;
  while (sum < n) {
    if (i % 2)
      sum = sum + b, bl = bl + b;
    else
      sum = sum + r;
    i++;
  }
  if (sum > n) {
    if (i % 2 == 0) {
      int x = sum - n;
      bl = bl - x;
    }
  }
  cout << bl << endl;

  return;
}
signed main() {

  // CASET
  solve();

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define float long double
#define ll long long
#define int long long
#define vl vector<ll>
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define all(x) x.begin(), x.end()
#define alr(x) x.rbegin(), x.rend()
#define endl '\n'
#define cnl cout << endl;
#define pi 3.141592653589793238
#define ms(x, v) ((x), v, sizeof((x)))
#define MAXN 100009
#define CASET                                                                  \
  int ___T;                                                                    \
  scanf("%lld", &___T);                                                        \
  for (int cs = 1; cs <= ___T; cs++)
template <class T> bool umin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool umax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 200 * 1000 + 9;
const int inf = 1e18;
const int mod = 1e9 + 7;
int i, j, k;
void solve() {
  int n, b, r;
  cin >> n >> b >> r;
  int sum = 0;
  int bl = 0;
  i = 1;
  int no = (n / (b + r));
  int rem = n % (b + r);
  cout << (no * b + min(rem, b)) << endl;

  return;
}
signed main() {

  // CASET
  solve();

  return 0;
}
Problem p02754 (C++)

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

int main() {
  long long a, b, n;
  cin >> n >> a >> b;
  long long cnt_b = 0, cnt_r = 0, cnt = 0;
  for (long long i = 0; i < pow(10, 100); i++) {
    for (int j = 0; j < a; j++) {
      cnt_b++;
      cnt++;
      if (cnt == n) {
        break;
      }
    }
    if (cnt == n) {
      break;
    }
    for (int k = 0; k < b; k++) {
      cnt_r++;
      cnt++;
      if (cnt == n) {
        break;
      }
    }
    if (cnt == n) {
      break;
    }
  }
  cout << cnt_b << endl;
}


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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

void solve() {
  int64_t n, a, b;
  cin >> n >> a >> b;
  if (a == 0) {
    cout << 0;
    return;
  }

  int64_t c = a + b;
  int64_t x = 1;
  while (true) {
    if (x * c == n) {
      cout << x * a;
      return;
    } else if (x * c > n) {
      x--;
      break;
    } else {
      x++;
    }
  }
  int64_t result = x * a;
  int64_t rem = n - x * c;
  if (a <= rem)
    result += a;
  if (a > rem)
    result += rem;
  cout << result;
}

int main() {
  solve();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

void solve() {
  int64_t n, a, b;
  cin >> n >> a >> b;
  if (a == 0) {
    cout << 0;
    return;
  }

  int64_t c = a + b;
  int64_t x = n / c;
  if (x * c == n) {
    cout << x * a;
    return;
  }
  int64_t result = x * a;
  int64_t rem = n - x * c;
  if (a <= rem)
    result += a;
  if (a > rem)
    result += rem;
  cout << result;
}

int main() {
  solve();
  return 0;
}
Problem p02754 (C++)

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

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

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 % (a + b), a);
}
Problem p02754 (C++)

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

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

  x = n / (a + b);
  y = n - x * (a + b);

  if (y >= a)
    y = a;

  else
    y = y;

  cout << x * a + y << endl;
  return 0;
}

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

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

  x = n / (a + b);
  y = n - x * (a + b);

  if (y >= a)
    y = a;

  else
    y = y;

  cout << x * a + y << 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(N % (A + B), A)) << endl;
}

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < (N); i++)
#define repo(i, N) for (int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
// #define num 1000000007
#define pi acos(-1.0)
// cout << fixed << setprecision (20);   小数点以下2０桁まで
// intの最大値2147483647 ≒ 2×10^9
// long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
// string s = to_string(int数);
// int n = stoi(string文字列);

int main() {
  int 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;
#define rep(i, N) for (int i = 0; i < (N); i++)
#define repo(i, N) for (int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
// #define num 1000000007
#define pi acos(-1.0)
// cout << fixed << setprecision (20);   小数点以下2０桁まで
// intの最大値2147483647 ≒ 2×10^9
// long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
// string s = to_string(int数);
// int n = stoi(string文字列);

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

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

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

int main() {
  int64_t N, A, B, count, s, t;
  cin >> N >> A >> B;
  s = N / (A + B);
  t = N - (A + B) * s;
  if (t < A) {
    count = s * A + t;
  } else {
    count = s * A + A;
  }
  cout << count << endl;
}
Problem p02754 (C++)

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

using namespace std;
using ll = long long;

// container util
#define SORT(c) sort((c).begin(), (c).end())

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

const int INF = 1e9;

int main(void) {

  ll N, A, B;
  cin >> N >> A >> B;

  ll ans = 0;
  ll sum = 0;
  while (sum < N) {
    if (sum + A <= N) {
      sum += A;
      ans += A;
    } else if (sum + A > N) {
      ans += N - sum;
      break;
    }
    if (sum + B <= N) {
      sum += B;
    } else if (sum + B > N) {
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

// container util
#define SORT(c) sort((c).begin(), (c).end())

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

const int INF = 1e9;

int main(void) {

  ll N, A, B;
  cin >> N >> A >> B;

  ll ans = 0;
  ans = (N / (A + B)) * A + min(A, N % (A + B));

  cout << ans << endl;

  return 0;
}
Problem p02754 (C++)

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

#define REP(i, n, N) for (ll i = (n); i < (N); i++)
// #define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl

using namespace std;
typedef long long ll;

const long long MOD = 1e9 + 7;

int main() {

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

  ll count = 0;
  ll ans = 0;

  while (count <= n) {
    ans += a;
    count += a + b;
  }

  if (count - n > b) {
    ans -= count - n - b;
  }

  p(ans);

  return 0;
}

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

#define REP(i, n, N) for (ll i = (n); i < (N); i++)
// #define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl

using namespace std;
typedef long long ll;

const long long MOD = 1e9 + 7;

int main() {

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

  ll count = 0;
  ll ans = 0;

  //    while(count <= n){
  //        ans += a;
  //        count += a + b;
  //    }

  ll time;
  time = (n / (a + b)) + 1;
  ans = a * time;
  count = (a + b) * time;

  if (count - n > b) {
    ans -= count - n - b;
  }

  p(ans);

  return 0;
}
Problem p02754 (C++)

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

int main() {

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

  return 0;
}

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 % (a + b), a) << endl;

  return 0;
}