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

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

#define rep2(x, fr, to) for (int x = (fr); x < (to); x++)
#define rep(x, to) for (int x = 0; x < (to); x++)
#define repr(x, fr, to) for (int x = (fr); x >= (to); x--)
#define all(c) c.begin(), c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<ll> VL;
const int MD = 1e9 + 7;
void dbg() { cerr << "\n"; }
template <class F, class... S> void dbg(const F &f, const S &...s) {
  cerr << f << ": ";
  dbg(s...);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m, q;
  cin >> n >> m >> q;
  VL a(n), b(n), c(n), d(n);
  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }

  VI ks(n);
  auto rec = [&](auto rec, int z, int pi) {
    ll ans = 0;
    if (z == n) {
      ll sm = 0;
      rep(i, q) {
        if (ks[b[i]] - ks[a[i]] == c[i])
          sm += d[i];
      }
      return sm;
    }

    rep2(i, pi, m) {
      ks[z] = i;
      ans = max(ans, rec(rec, z + 1, i));
    }
    return ans;
  };
  cout << rec(rec, 0, 0) << "\n";
  return 0;
}


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

#define rep2(x, fr, to) for (int x = (fr); x < (to); x++)
#define rep(x, to) for (int x = 0; x < (to); x++)
#define repr(x, fr, to) for (int x = (fr); x >= (to); x--)
#define all(c) c.begin(), c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<ll> VL;
const int MD = 1e9 + 7;
void dbg() { cerr << "\n"; }
template <class F, class... S> void dbg(const F &f, const S &...s) {
  cerr << f << ": ";
  dbg(s...);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m, q;
  cin >> n >> m >> q;
  VL a(q), b(q), c(q), d(q);
  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }

  VI ks(n);
  auto rec = [&](auto rec, int z, int pi) {
    ll ans = 0;
    if (z == n) {
      ll sm = 0;
      rep(i, q) {
        if (ks[b[i]] - ks[a[i]] == c[i])
          sm += d[i];
      }
      return sm;
    }

    rep2(i, pi, m) {
      ks[z] = i;
      ans = max(ans, rec(rec, z + 1, i));
    }
    return ans;
  };
  cout << rec(rec, 0, 0) << "\n";
  return 0;
}
Problem p02696 (Python)

Buggy submission (status: Time Limit Exceeded):
A, B, N = map(int, input().split())
c = 0
t = -10
if N > 100000000:
    for i in range(100000000, N + 1):
        a = (i * A) // B - A * (i // B)
        c = max(c, a)
        if t > a or i > 1100000000:
            print(c)
            break
        t = a
    else:
        print(c)
else:
    for i in range(N + 1):
        a = (i * A) // B - A * (i // B)
        c = max(c, a)
        if t > a or i > 100000000:
            print(c)
            break
        t = a
    else:
        print(c)


Fixed submission:
A, B, N = map(int, input().split())
X = min(N, B - 1)
print(A * X // B - A * (X // B))
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define REP(i, d, n) for (long long i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() { // 言語変えろ言語変えろ言語変えろ言語変えろ言語変えろ

  ll a, b, n;
  cin >> a >> b >> n;
  ll max = -999999;
  ll ans;

  rep(i, n) {
    if (n - i < b) {
      ans = n - i;
      break;
    }
  }

  max = ans * a / b - a * (ans / b);

  cout << max << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define REP(i, d, n) for (long long i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() { // 言語変えろ言語変えろ言語変えろ言語変えろ言語変えろ

  ll a, b, n;
  cin >> a >> b >> n;
  ll max = -999999;
  ll ans;

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

  max = ans * a / b - a * (ans / b);

  cout << max << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll max = 0;
  for (ll i = 0; i <= min(b - 1, n); i++) {
    if ((a * i) / b > max) {
      max = (a * i) / b;
    }
  }
  cout << max;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  cout << a * min(n, b - 1) / b;
  return 0;
}
Problem p02696 (C++)

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

using ll = long long;
using namespace std;

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

  vector<long double> ans(n, 0);

  for (int i = 1; i <= n; i++)
    ans[i - 1] = floor(a * i / b) - a * floor(i / b);

  sort(ans.begin(), ans.end());

  cout << floor(ans[n - 1]) << endl;
}

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

using ll = long long;
using namespace std;

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

  if (b > n)
    cout << floor(a * n / b) << endl;
  else
    cout << floor(a * (b - 1) / b) << endl;
}
Problem p02696 (C++)

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

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  ll max_val = -1;
  rep(x, n + 1) {
    ll val = floor(a * x / b) - a * floor(x / b);
    chmax(max_val, val);
  }
  cout << max_val << endl;
  return 0;
}

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

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  auto f = [&](ll x) { return (ll)floor(a * x / (double)b); };

  ll ans = f(min(b - 1, n));
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++)

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

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long z = floor(a / b) - a * floor(1 / b);
  for (int i = 2; i <= n; i++) {
    int z1 = floor(a * i / b) - a * floor(i / b);
    if (z1 > z)
      z = z1;
  }
  cout << z << endl;
}

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

int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  if (c >= b)
    c = b - 1;
  cout << floor(a * c / b) - a * floor(c / b) << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
// ABC165D -

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

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

  long long int ans = N * A / B - N / B * A;
  for (long long int i = B - 1; i <= N; i += B) {
    if ((i * A / B - i / B * A) >= ans) {
      ans = i * A / B - i / B * A;
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
// ABC165D -

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

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

  long long int ans = 0;
  if (N >= B - 1) {
    ans = A * (B - 1) / B;
  } else {
    ans = A * N / B;
  }

  cout << ans << endl;

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define lson node << 1, st, mid
#define rson node << 1 | 1, mid + 1, ed
#define mem(a, x) memset(a, x, sizeof(a))
#define me(a) memset(a, 0, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x & (-x)
#define up(i, x, y) for (long long i = x; i < y; i++)
#define down(i, x, y) for (long long i = x; i >= y; i--)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const ll N = 1e3 + 5;
const double pi = acos(-1.0);
const double eps = 1e-9;
using namespace std;

int main() {
  // in;
  // out;
  ll a, b, n;
  cin >> a >> b >> n;
  ll x, y;
  x = (ll)floor(n * a * 1.0 / b) - a * floor(n * 1.0 / b);
  y = (ll)floor((n - 1) * a * 1.0 / b) - a * floor((n - 1) * 1.0 / b);
  ll res = max(x, y);
  ll cnt = -100;
  if (n <= 1000000001)
    cout << res << endl;
  else {
    for (int i = 2; i <= 1000000000; i++) {
      ll z = floor((n - i) * a * 1.0 / b) - a * floor((n - i) * 1.0 / b);
      cnt = max(cnt, z);
    }
    for (int i = 1; i <= 1000000000; i++) {
      ll z = floor(i * a * 1.0 / b) - a * floor(i * 1.0 / b);
      cnt = max(cnt, z);
    }
    cout << max(res, cnt) << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define lson node << 1, st, mid
#define rson node << 1 | 1, mid + 1, ed
#define mem(a, x) memset(a, x, sizeof(a))
#define me(a) memset(a, 0, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x & (-x)
#define up(i, x, y) for (long long i = x; i < y; i++)
#define down(i, x, y) for (long long i = x; i >= y; i--)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const ll N = 1e3 + 5;
const double pi = acos(-1.0);
const double eps = 1e-9;
using namespace std;

int main() {
  // in;
  // out;
  ll a, b, n;
  cin >> a >> b >> n;
  ll x;
  if (b - 1 <= n)
    x = (ll)floor((b - 1) * a * 1.0 / b) - a * floor((b - 1) * 1.0 / b);
  else
    x = (ll)floor(n * a * 1.0 / b) - a * floor(n * 1.0 / b);
  cout << x << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
// 失敗するからこそ
// そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
#ifdef DAIJOBU
#include "/home/v-o_o-v/deb.h"
#define deb(x...)                                                              \
  cerr << "[" << #x << "] = [";                                                \
  _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif

using namespace std;

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lint;
typedef double ld;

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

  lint a, b, n;
  cin >> a >> b >> n;
  lint ans = 0;
  for (int i = 1; i <= min(b, n); i++) {
    lint now = (a * i) / b - a * (i / b);
    ans = max(ans, now);
  }
  cout << ans;
  return 0;
}
// Write Here


Fixed submission:
// 失敗するからこそ
// そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
#ifdef DAIJOBU
#include "/home/v-o_o-v/deb.h"
#define deb(x...)                                                              \
  cerr << "[" << #x << "] = [";                                                \
  _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif

using namespace std;

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lint;
typedef double ld;

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

  lint a, b, n;
  cin >> a >> b >> n;
  // lint ans = 0;
  lint ans = (a * (min(b - 1, n))) / b - a * ((min(b - 1, n)) / b);
  // for(int i = 1; i <= n; i++){
  // 	lint now = (a * i) / b - a * (i / b);
  // 	deb(now);
  // 	ans = max(ans, now);
  // }
  cout << ans;
  return 0;
}
// Write Here
Problem p02696 (C++)

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

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll, ll>> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i > (b); --i)
const int MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll a, b, n, ans = 0;
  cin >> a >> b >> n;
  for (ll i = b - 1; i <= n; i += b) {
    ll tmp = ((a * i) / b) - a * (i / b);
    ans = max(ans, tmp);
  }
  if (ans == 0) {
    for (ll i = n; i <= n; i += b) {
      ll tmp = ((a * i) / b) - a * (i / b);
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll, ll>> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i > (b); --i)
const int MOD = 1000000007;
const int MAX = 510000;

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

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

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i >= (b); --i)
#define SIZE(a) int((a).size())
#define out(a) cout << (a) << endl;
const int INF = INT_MAX;
const int MAX = 510000;
const ll MOD = 1L << 32;
ll fac[MAX], finv[MAX], inv[MAX];

int main() {
  ll a, b, n, ans = 0;
  cin >> a >> b >> n;
  ans = max(ans, ((n * a) / b) - (a * (n / b)));
  if (n % b < b - 1) {
    rep(i, 0, n / b) {
      ll tmp = (i + 1) * b - 1;
      ans = max(ans, ((tmp * a) / b) - (a * (tmp / b)));
    }
  } else {
    rep(i, 0, n / b + 1) {
      ll tmp = (i + 1) * b - 1;
      ans = max(ans, ((tmp * a) / b) - (a * (tmp / b)));
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i >= (b); --i)
#define SIZE(a) int((a).size())
#define out(a) cout << (a) << endl;
const int INF = INT_MAX;
const int MAX = 510000;
const ll MOD = 1L << 32;
ll fac[MAX], finv[MAX], inv[MAX];

int main() {
  ll a, b, n, ans = 0;
  cin >> a >> b >> n;
  ans = max(ans, ((n * a) / b) - (a * (n / b)));
  if (n % b < b - 1) {
    ll tmp = ((n / b)) * b - 1;
    ans = max(ans, ((tmp * a) / b) - (a * (tmp / b)));
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (long long i = 0; i < (long long)c; i++)
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long ans = 0;
  long long t;
  rep(x, n + 1) {
    t = floor(a * x / b) - a * floor(x / b);
    ans = max(t, ans);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (long long i = 0; i < (long long)c; i++)
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long ans = 0;
  long long t;
  /*	rep(x,n+1){
                  t=floor(a*x/b)-a*floor(x/b);
                  ans = max(t,ans);
          }
  */
  t = min(n, b - 1);
  ans = floor(a * t / b);
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++)

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

using namespace std;

int main() {
  long long a, b, n, max;
  cin >> a >> b >> n;
  max = a / b - (1 / b) * a;
  for (long long i = 2; i <= n; i++) {
    if (((a * i) / b - (i / b) * a) > max) {
      max = (a * i) / b - (i / b) * a;
    }
  }
  cout << max << endl;

  return 0;
}


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

using namespace std;

int main() {
  long long a, b, n, max;
  cin >> a >> b >> n;
  if (a < b) {
    if ((b - 1) < n) {
      max = (a * (b - 1)) / b;
    } else {
      max = (a * n) / b;
    }
  } else {
    max = (a * n) / b - a * (n / b);
    long long temp = (n / b) * b - 1;
    temp = (a * temp) / b - a * (temp / b);
    if (temp > max) {
      max = temp;
    }
  }
  cout << max << endl;

  return 0;
}
Problem p02696 (C++)

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

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  long long int A, B, x;
  cin >> A >> B >> x;
  long long int ans = 0;
  // ans = max(ans, (A*x)/B - A*(x/B));
  // if (B<=1000000){
  //     for (int i=1; i<=A; i++){
  //         ans = max(ans, (A*x)/B - A*(x/B));
  //     }
  //     cout<<ans;
  // }
  // else{
  for (int i = B; i <= B + x && i < 100000000000; i++) {
    ans = max(ans, (A * i) / B - A * (i / B));
  }
  cout << ans;
  // }

  return 0;
}


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

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

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

  long long int m = min(B - 1, N);
  cout << (A * m) / B - A * (m / B);

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
No matter how long a night, dawn will always break.

Simular saying ... The darkest hour is just before the dawn.
 ***************************************   ************************8
**********************************
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define endl '\n'
#define sz(x) (int)(x).size()
#define fo(i, l, u) for (i = l; i < u; i++)
#define rfo(i, l, u) for (i = l; i >= u; i--)
#define allfo(s) for (auto it = (s).begin(); it != (s).end(); it++)
#define _init(b) memset(b, -1, sizeof(b))
#define _init0(b) memset(b, 0, sizeof(b))
#define MOD 1000000007
#define hell 998244353
#define output(x) cout << (x ? "YES" : "NO") << endl;

int gcd(int a, int b) {
  if (a > b)
    swap(a, b);
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
bool mod(double a, double b) { return a / b - floor(a / b); }

int f(int a, int b, int l, int r) {
  if (l > r)
    return 0;
  if (l / b == r / b) {
    return (a * r) / b - a * (r / b);
  }
  int mid = l + (r - l) / 2;
  return max(f(a, b, l, mid), f(a, b, mid + 1, r));
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, x, k, a, b;
  cin >> a >> b >> x;
  cout << f(a, b, 1, x);

  return 0;
}

Fixed submission:
/*
No matter how long a night, dawn will always break.

Simular saying ... The darkest hour is just before the dawn.
 ***************************************   ************************8
**********************************
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define endl '\n'
#define sz(x) (int)(x).size()
#define fo(i, l, u) for (i = l; i < u; i++)
#define rfo(i, l, u) for (i = l; i >= u; i--)
#define allfo(s) for (auto it = (s).begin(); it != (s).end(); it++)
#define _init(b) memset(b, -1, sizeof(b))
#define _init0(b) memset(b, 0, sizeof(b))
#define MOD 1000000007
#define hell 998244353
#define output(x) cout << (x ? "YES" : "NO") << endl;

int gcd(int a, int b) {
  if (a > b)
    swap(a, b);
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
bool mod(double a, double b) { return a / b - floor(a / b); }

int f(int a, int b, int l, int r) {
  if (l > r)
    return 0;
  if (l / b == r / b) {
    return (a * r) / b - a * (r / b);
  }
  int mid = l + (r - l) / 2;
  return max(f(a, b, l, mid), f(a, b, mid + 1, r));
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, x, k, a, b;
  cin >> a >> b >> x;
  if (b < x) {
    cout << (a * (b - 1)) / b << endl;
    return 0;
  }
  cout << f(a, b, 1, x);

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define int long long

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rep1(i, n) for (int i = 1; i <= (int)n; ++i)
#define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = n; i >= 1; --i)
#define range(i, l, r) for (int i = l; i < (int)r; ++i)
#define rrange(i, l, r) for (int i = (int)r - 1; i >= (int)l; --i)
#define unless(a) if (!(a))
#define all(a) begin(a), end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi = vector<int>;
using pii = pair<int, int>;

bool chmin(int &a, int b) { return a > b ? (a = b, true) : false; }
bool chmax(int &a, int b) { return a < b ? (a = b, true) : false; }
int read() {
  int a;
  scanf("%lld", &a);
  return a;
}
constexpr int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); }

int f(int a, int b) { return a / b; }

signed main() {
  int A, B, N;
  cin >> A >> B >> N;
  int mx = 0;
  range(i, 0, 1000 * A) {
    if (N - i >= 0)
      chmax(mx, f(A * (N - i), B) - A * f(N - i, B));
  }
  printf("%lld\n", mx);
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define int long long

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rep1(i, n) for (int i = 1; i <= (int)n; ++i)
#define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = n; i >= 1; --i)
#define range(i, l, r) for (int i = l; i < (int)r; ++i)
#define rrange(i, l, r) for (int i = (int)r - 1; i >= (int)l; --i)
#define unless(a) if (!(a))
#define all(a) begin(a), end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi = vector<int>;
using pii = pair<int, int>;

bool chmin(int &a, int b) { return a > b ? (a = b, true) : false; }
bool chmax(int &a, int b) { return a < b ? (a = b, true) : false; }
int read() {
  int a;
  scanf("%lld", &a);
  return a;
}
constexpr int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); }

int f(int a, int b) { return a / b; }

signed main() {
  int A, B, N;
  cin >> A >> B >> N;
  int m = min(B - 1, N);

  cout << A * m / B - A * (m / B) << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define pb push_back
#define mp make_pair
#define F .first
#define S .second
using ll = long long;
using ld = long double;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int main() {
  ll a, b, n, ans = 0;
  cin >> a >> b >> n;
  ll c = GCD(a, b);
  ll d = n * c / (GCD(n, c));
  rep(i, max((ll)0, d - a), min(n, d + a) + 1) ans =
      max(ans, (a * i) / b - a * (i / b));
  rep(i, 0, min(n, b)) ans = max(ans, (a * i) / b - a * (i / b));
  ll aa = min((ll)n, b - 1);
  ll bb = max((ll)0, b - 10000000);
  irep(i, aa, bb) ans = max(ans, (a * i) / b - a * (i / b));
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define pb push_back
#define mp make_pair
#define F .first
#define S .second
using ll = long long;
using ld = long double;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int main() {
  ll a, b, n, ans = 0;
  cin >> a >> b >> n;
  ll c = GCD(a, b);
  ll d = n * c / (GCD(n, c));
  rep(i, max((ll)0, d - a), min(n, d + a) + 1) ans =
      max(ans, (a * i) / b - a * (i / b));
  // rep(i,0,min(n,b))ans=max(ans,(a*i)/b-a*(i/b));
  ll aa = min((ll)n, b - 1);
  ll bb = max((ll)0, b - 10000000);
  irep(i, aa, bb) ans = max(ans, (a * i) / b - a * (i / b));
  cout << ans;
}
Problem p02696 (C++)

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

using namespace std;
typedef long long ll;

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

ll solve(ll &a, ll &b, ll &x) {
  ll res = (int)(a * x / b) - a * (int)(x / b);
  return res;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = b / a + 1;
  ll ans = 0;
  for (ll i = x; i <= min(b, n); i++) {
    ans = max(ans, solve(a, b, i));
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

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

ll solve(ll &a, ll &b, ll &x) {
  ll res = (int)(a * x / b) - a * (int)(x / b);
  return res;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  // ll x = b / a + 1;
  // ll y = min(n, b);
  // cout << max(solve(a, b, x), solve(a, b, y)) << endl;

  ll a_ = 0;
  if (b <= n)
    a_ = b - 1;
  else
    a_ = n;
  cout << solve(a, b, a_) << endl;

  // ll ans = 0;
  // for (ll i = x; i <= min(b, n); i ++) {
  //   ans = max(ans, solve(a, b, i));
  // }
  // cout << ans << endl;

  // ll x = n;
  // if (a < b) {
  //   if (b <= x) {
  //     ll u = b - 1;
  //     cout << solve(a, b, u) << endl;
  //   } else cout << solve(a, b, n) << endl;
  // } else {
  //   if (b <= x) {
  //     ll y = b - 1;
  //     if (solve(a, b, x) < solve(a, b, y)) cout << solve(a, b, y) << endl;
  //     else cout << solve(a, b, x) << endl;
  //   }
  //   else cout << solve(a, b, x) << endl;
  // }
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll a, b, n;
int main() {
  cin >> a >> b >> n;
  ll x;
  ll ans;
  if (n < b) {
    ans = (a * n) / b - a * (n / b);
    cout << ans;
    return 0;
  } else if (n == b) {
    x = n - 1;
    ans = (a * n) / b - a * (n / b);
    ll ans1 = (a * x) / b - a * (x / b);
    ans = max(ans, ans1);
    cout << ans;
  } else {
    ll maxn = (a * n) / b - a * (n / b);
    ll tmp;
    ll num = n / b;
    for (ll i = num; i >= 1; i--) {
      ll mul = i * b - 1;
      tmp = (a * mul) / b - a * (mul / b);
      maxn = max(maxn, tmp);
    }
    ans = maxn;
    cout << ans;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll a, b, n;
int main() {
  cin >> a >> b >> n;
  ll x;
  ll ans;
  if (n < b) {
    ans = (a * n) / b - a * (n / b);
    cout << ans;
    return 0;
  } else if (n == b) {
    x = n - 1;
    ans = (a * n) / b - a * (n / b);
    ll ans1 = (a * x) / b - a * (x / b);
    ans = max(ans, ans1);
    cout << ans;
  } else {
    ll maxn = (a * n) / b - a * (n / b);
    ll tmp;
    ll num = n / b;
    ll mod = 1e7;
    if (num > mod) {
      for (ll i = 1; i <= mod; i++) {
        ll mul = i * b - 1;
        tmp = (a * mul) / b - a * (mul / b);
        maxn = max(maxn, tmp);
      }
    } else {
      for (ll i = num; i >= 1; i--) {
        ll mul = i * b - 1;
        tmp = (a * mul) / b - a * (mul / b);
        maxn = max(maxn, tmp);
      }
    }
    ans = maxn;
    cout << ans;
  }
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<long long int>
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long int, long long int>>
#define boost                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main() {
  boost;
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (b > n)
    ans = (a * n) / b;
  else {
    ll x = n / (b - 1);
    x *= (b - 1);
    ans = (a * x) / b - a * (x / b);
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<long long int>
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long int, long long int>>
#define boost                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main() {
  boost;
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (b == 1)
    ans = 0;
  else if (b > n)
    ans = (a * n) / b;
  else {
    ll x = n / (b - 1);
    x *= (b - 1);
    ans = (a * x) / b - a * (x / b);
  }
  cout << ans;
}
Problem p02696 (C++)

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll k = min(b, n);
  rep(i, k + 1) { ans = max(ans, (a * i) / b - a * (i / b)); }
  cout << ans << endl;
  return 0;
}

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll k = min(b - 1, n);
  ans = max(ans, (a * k) / b - a * (k / b));
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 10000007      // 10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  // os << '{';
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, x, ans = 0, count = 0;
  cin >> a >> b >> n;
  set<lli> g;
  vector<lli> f(n + 1);
  cout << a * min(n, b - 1) / b << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 10000007      // 10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  // os << '{';
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, x, ans = 0, count = 0;
  cin >> a >> b >> n;
  cout << a * min(n, b - 1) / b << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 // 10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  ll ans = 0LL;
  ll tmp;
  for (i = n; i >= n / b; i--) {
    tmp = floor((a * i) / b) - a * (floor(i / b));
    ans = max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 // 10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  ll x = n;
  if (n >= b - 1)
    x = b - 1;
  ll ans = a * x / b - a * (x / b);
  cout << ans << endl;

  return 0;
}
Problem p02696 (C++)

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

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

  if (n < b) {
    x = n;
  } else if (n == b) {
    x = b - 1;
  } else {
    x = b;
    while (n > (x + b))
      x += b;
    x--;
  }
  ans = ((a * x) / b) - a * (x / b);

  cout << ans << endl;
}


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

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

  if (n < b) {
    x = n;
  } else if (n == b) {
    x = b - 1;
  } else {
    x = (n / b) * b - 1;
  }
  ans = ((a * x) / b) - a * (x / b);

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
template <class T> struct rge {
  T b, e;
};
template <class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  template <class T> debug &operator<<(T x) {
    cerr << boolalpha << x;
    return *this;
  }
  template <class B, class C> debug &operator<<(pair<B, C> x) {
    return *this << "(" << x.first << ", " << x.second << ")";
  }
  template <class T> debug &operator<<(rge<T> x) {
    *this << "[";
    for (auto it = x.b; it != x.e; it++) {
      *this << ", " + 2 * (it == x.b) << *it;
    }
    return *this << "]";
  }
  template <class T> debug &operator<<(vector<T> x) {
    return *this << range(x.begin(), x.end());
  }
#else
  template <class T> debug &operator<<(const T &) { return *this; }
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;
ll a, b, n;

ll f(ll x) { return (a * x) / b - a * (x / b); }

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

  cin >> a >> b >> n;
  ll ans = 0;
  for (ll x = 0; x <= n;) {
    ll lo = x, hi = n;
    while (lo < hi) {
      ll mid = lo + (hi - lo + 1) / 2;
      if ((a * x) / b == (a * mid) / b) {
        lo = mid;
      } else {
        hi = mid - 1;
      }
    }
    //$ debug() nav(x);
    ans = max(ans, f(x));
    x = lo + 1;
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <class T> struct rge {
  T b, e;
};
template <class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  template <class T> debug &operator<<(T x) {
    cerr << boolalpha << x;
    return *this;
  }
  template <class B, class C> debug &operator<<(pair<B, C> x) {
    return *this << "(" << x.first << ", " << x.second << ")";
  }
  template <class T> debug &operator<<(rge<T> x) {
    *this << "[";
    for (auto it = x.b; it != x.e; it++) {
      *this << ", " + 2 * (it == x.b) << *it;
    }
    return *this << "]";
  }
  template <class T> debug &operator<<(vector<T> x) {
    return *this << range(x.begin(), x.end());
  }
#else
  template <class T> debug &operator<<(const T &) { return *this; }
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;
ll a, b, n;

ll f(ll x) { return (a * x) / b - a * (x / b); }

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

  cin >> a >> b >> n;
  ll x = b * (n / b) - 1;
  cout << max(f(n), f(x)) << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i, n) for (int i = 0; i < n; i++)
#define fp(i, k, n) for (int i = k; i <= n; i++)
#define fr(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define pii pair<int, int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n'
#define F first
#define S second
#define all(a) a.begin(), a.end()
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

void solve() {
  int a, b, n;
  cin >> a >> b >> n;
  int ans = 0;
  int x = 0;
  fr(i, n, 0) {
    int res = ((a * i) / b) - (a * (i / b));
    ans = max(res, ans);
    x++;
    if (x == 100000000)
      break;
  }
  x = 0;
  fp(i, 0, n) {
    int res = ((a * i) / b) - (a * (i / b));
    ans = max(res, ans);
    x++;
    if (x == 100000000)
      break;
  }
  cout << ans << '\n';
  return;
}

signed main() {
  FAST int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}

Fixed submission:
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i, n) for (int i = 0; i < n; i++)
#define fp(i, k, n) for (int i = k; i <= n; i++)
#define fr(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define pii pair<int, int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n'
#define F first
#define S second
#define all(a) a.begin(), a.end()
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

void solve() {
  int a, b, n;
  cin >> a >> b >> n;
  int ans = 0;
  int x = 0;
  x = min(n, b - 1);
  cout << (a * x) / b << '\n';
  return;
}

signed main() {
  FAST int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02696 (C++)

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

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

  ll max = 0;
  for (ll i = N; i >= 0; i--) {
    ll tmp = floor((A * i) / B) - A * floor(i / B);
    if (tmp > max) {
      max = tmp;
    }
  }

  cout << max << endl;
  return 0;
}

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

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

  ll max = 0;
  /*
  for(ll i = N; i > 0; i--){
      if()
      ll tmp = floor((A * i)/B) - A*floor(i/B);
      if(tmp > max){
          max = tmp;
      }
  }
  */
  ll tmp = floor((A * N) / B) - A * floor(N / B);
  if (tmp > max) {
    max = tmp;
  }

  if (N >= (B - 1)) {
    ll tmp2 = 0;
    tmp2 = floor((A * (B - 1)) / B) - A * floor((B - 1) / B);

    if (tmp2 > max) {
      max = tmp2;
    }
  }

  cout << max << endl;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
// g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  if (B > N) {
    cout << (A * N) / B << endl;
    return 0;
  } else {
    /*
    for(int i = B-1;i <= N;i+=B){
      ll tmp;
      tmp = (A*i)/B - A*(i/B);
      ans = max(ans,tmp);
    }*/

    ll i = B - 1;
    while (i <= N) {
      ll tmp = 0;
      tmp = (A * i) / B - A * (i / B);
      ans = max(ans, tmp);
      i += B;
    }
  }
  cout << ans << endl;
}


Fixed submission:
// g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  if (B > N) {
    cout << (A * N) / B << endl;
    return 0;
  } else {
    /*
    for(int i = B-1;i <= N;i+=B){
      ll tmp;
      tmp = (A*i)/B - A*(i/B);
      ans = max(ans,tmp);
    }*/

    ll i = B - 1;
    // while(i <= N){
    ll tmp = 0;
    tmp = (A * i) / B - A * (i / B);
    ans = max(ans, tmp);
    //  i += B;
    //}
  }
  cout << ans << endl;
}
Problem p02696 (C++)

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

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

  // 全探索
  ll ans = 0;
  for (ll x = 0; x <= n; ++x) {
    ll fst = a * x / b;
    ll scd = x / b;
    scd *= a;
    ll flr = fst - scd;
    ans = max(ans, flr);
  }
  cout << ans << endl;
  return 0;
}

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

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

  ll x = min(b - 1, n);
  int ans = int(a * x / b) - a * int(x / b);
  // // 全探索
  // ll ans = 0;
  // for(ll x = 0; x <= n; ++x) {
  //     ll fst = a * x / b;
  //     ll scd = x / b;
  //     scd *= a;
  //     ll flr = fst - scd;
  //     ans = max(ans, flr);
  // }
  cout << ans << endl;
  return 0;
}