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

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
const ll mod = 1e9 + 7;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

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


Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
const ll mod = 1e9 + 7;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

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

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

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

  cin >> a >> b >> n;

  int max = 0;
  double temp = min(b - 1, n);
  for (double i = 0; i <= temp; i++) {
    int v = floor(a * i / b) - a * floor(i / b);
    if (max < v)
      max = v;
  }
  cout << max << endl;
}

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

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

  cin >> a >> b >> n;

  int max = 0;
  double temp = min(b - 1, n);
  // for (double i = 0; i <= temp; i++)
  // {
  int v = floor(a * temp / b) - a * floor(temp / b);
  //   if (max < v)
  //     max = v;
  // }
  cout << v << endl;
}
Problem p02696 (C++)

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

using namespace std;

int main() {
  ll a, b, n;
  scanf("%lld %lld %lld", &a, &b, &n);
  if (n % b == 0)
    b--;
  printf("%lld\n", a * n / b - a * (n / b));
}

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

using namespace std;

int main() {
  ll a, b, n;
  scanf("%lld %lld %lld", &a, &b, &n);
  if (b <= n)
    n = n / b * b - 1;
  printf("%lld\n", a * n / b - a * (n / b));
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <set>
#include <vector>

#define ll long long

using namespace std;

int main() {
  ll a, b, n;
  ll fx;
  ll res = 0;
  cin >> a >> b >> n;
  for (int x = 0; x <= (n < b ? n : b); ++x) {
    // cout << "x = " << x << ends;
    fx = floor(a * x / b) - a * floor(x / b);
    // cout << "f(x) = " << fx << endl;
    res = max(res, fx);
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <set>
#include <vector>

#define ll long long

using namespace std;

int main() {
  ll a, b, n;
  ll fx;
  ll res = 0;
  cin >> a >> b >> n;
  /*	for (int x = 0; x <= (n<b?n:b); ++x) {
                  cout << "x = " << x << ends;
                  fx = floor(a * x / b) - a * floor(x / b);
                  cout << "f(x) = " << fx << endl;
                  res = max(res, fx);
          }
          */
  if (n < b)
    fx = floor(a * n / b) - a * floor(n / b);
  else
    fx = floor(a * (b - 1) / b) - a * floor((b - 1) / b);
  cout << fx << endl;
  return 0;
}
Problem p02696 (C++)

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

long long a, b, n, maxn, m;

int main(void) {
  scanf("%lld%lld%lld", &a, &b, &n);
  for (int i = b - 1; i <= n; i++) {
    m = a * i / b - a * (i / b);
    maxn = max(maxn, m);
    i += b;
  }
  m = a * n / b - a * (n / b);
  maxn = max(maxn, m);

  printf("%lld", maxn);
  return 0;
}

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

long long a, b, n, maxn, m;

int main(void) {
  scanf("%lld%lld%lld", &a, &b, &n);
  if (b - 1 <= n)
    maxn = a * (b - 1) / b - a * ((b - 1) / b);
  m = a * n / b - a * (n / b);
  maxn = max(maxn, m);

  printf("%lld", maxn);
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Runtime Error):
// @prefix atcoder
// @description atcoder template

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int modinv(int a, int m) {
  int b = m, u = 1, v = 0;
  while (b) {
    int t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

int a, b, n;

signed main() {
  cin >> a >> b >> n;

  int res = 0;

  if (b > n) {
    cout << (a * n) / b - a * (n / b) << endl;
    return 0;
  }
  int i = n / (b - 1);
  res = max((a * (i * (b - 1))) / b - a * ((b * i - 1) / b), res);
  i--;
  res = max((a * (i * (b - 1))) / b - a * ((b * i - 1) / b), res);
  cout << res << endl;
  return 0;
}

Fixed submission:
// @prefix atcoder
// @description atcoder template

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int modinv(int a, int m) {
  int b = m, u = 1, v = 0;
  while (b) {
    int t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

int a, b, n;

signed main() {
  cin >> a >> b >> n;

  int res = 0;

  if (b > n) {
    cout << (a * n) / b - a * (n / b) << endl;
    return 0;
  }
  if (b != 1) {
    int i = n / (b - 1);
    res = max((a * (i * (b - 1))) / b - a * ((b * i - 1) / b), res);
    i--;
    res = max((a * (i * (b - 1))) / b - a * ((b * i - 1) / b), res);
  } else {
    res = 0;
  }
  cout << res << endl;
  return 0;
}
Problem p02696 (C++)

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

signed main() {
  int A, B, N;
  cin >> A >> B >> N;
  cout << N / (abs(A - B)) << endl;
}


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

signed main() {
  int A, B, N;
  cin >> A >> B >> N;
  if (B > N) {
    cout << (A * N) / B - (A * (N / B)) << endl;
    return 0;
  } else {
    int x = N - (N % B) - 1;
    cout << (A * x) / B - (A * (x / B)) << endl;
    return 0;
  }
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
/*我是萌新*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ll a, b, n;
  while (cin >> a >> b >> n) {
    ll maxn = -mod, k = 0;
    for (ll i = 1; i <= min(n, b); i++) {
      if (maxn < ((a * i) / b - a * (i / b))) {
        maxn = ((a * i) / b - a * (i / b));
        k = i;
      }
    }
    cout << maxn << '\n';
  }
}

Fixed submission:
/*我是萌新*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ll a, b, n;
  while (cin >> a >> b >> n) {
    ll maxn = -mod, k = 0;
    /*for(ll i=1;i<=min(n,b);i++)
    {
        if(maxn<((a*i)/b-a*(i/b)))
        {
            maxn=((a*i)/b-a*(i/b));
            k=i;
        }

    }*/
    cout << (a * min(n, b - 1)) / b - a * (min(n, b - 1) / b) << '\n';
  }
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
// author: zekigurbuz (Zeki Gurbuz) 2020
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

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

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define all(x) begin(x), end(x)

const int N = 1e5 + 10;
const int M = 1e9 + 7;

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

template <class T> void ckmin(T &a, T b) { a = min(a, b); }
template <class T> void ckmax(T &a, T b) { a = max(a, b); }

void precomp() {}

ll a, b, n;

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

void solve() {
  cin >> a >> b >> n;
  ll lo = 1L, hi = n;
  while (hi - lo > 1L) {
    ll left = lo + (hi - lo) / 3L, right = hi - (hi - lo) / 3L;
    if (f(left) < f(right))
      lo = left + 1;
    else
      hi = right;
  }
  ll cr = (lo + hi) / 2L;
  while (f(cr + 1L) > f(cr) && cr + 1L <= n)
    ++cr;
  while (f(cr - 1L) > f(cr) && cr - 1L >= 1L)
    --cr;
  cout << f(cr) << endl;
  // for (ll i = 1L; i <= n; i++) cout << i << " " << f(i) << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  precomp();
  int t = 1; // cin >> t;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}


Fixed submission:
// author: zekigurbuz (Zeki Gurbuz) 2020
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

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

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define all(x) begin(x), end(x)

const int N = 1e5 + 10;
const int M = 1e9 + 7;

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

template <class T> void ckmin(T &a, T b) { a = min(a, b); }
template <class T> void ckmax(T &a, T b) { a = max(a, b); }

void precomp() {}

ll a, b, n;

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

void solve() {
  cin >> a >> b >> n;
  cout << f(min(b - 1, n));
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  precomp();
  int t = 1; // cin >> t;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template <class T> void print(const T &t) { cout << t << endl; }
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;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll num = 0;
  for (ll i = n; i >= 1; i--) {
    if (ans > a * i / b) {
      break;
    }
    num = a * i / b - i / b * a;
    chmax(ans, num);
  }
  print(ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template <class T> void print(const T &t) { cout << t << endl; }
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;
}

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18, MOD = 1e9 + 7;
const int INT_INF = 1e9, INT_MOD = 1e9 + 7;
#define rep(i, N) for (int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;

signed main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll maxa = (a * n) / b, maxb = n / b;
  ll tmax = maxa - a * maxb;
  for (ll i = n;; i--) {
    if ((i + 1) % b == 0) {
      ll tmpa = (a * i) / b, tmpb = i / b;
      cout << max(tmax, tmpa - a * tmpb) << endl;
      break;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18, MOD = 1e9 + 7;
const int INT_INF = 1e9, INT_MOD = 1e9 + 7;
#define rep(i, N) for (int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;

signed main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll maxa = (a * n) / b, maxb = n / b;
  ll tmax = maxa - a * maxb;
  if (n % b == 0) {
    ll tmpa = (a * (n - 1)) / b, tmpb = (n - 1) / b;
    cout << tmpa - a * tmpb << endl;
  } else {
    ll tmp = (n / b) * b - 1;
    ll tmpa = (a * tmp) / b, tmpb = tmp / b;
    cout << max(tmpa - a * tmpb, tmax) << endl;
  }
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <iterator>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define fast                                                                   \
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger {
  template <typename T> debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;

int32_t main() {
  fast;
  int A, B, N;
  cin >> A >> B >> N;
  int res = floor(A * N / B) - A * floor(N / B);
  for (int i = N - 1; i >= N / 10; i--) {
    if (floor(A * i / B) - A * floor(i / B) > res) {
      res = floor(A * i / B) - A * floor(i / B);
    }
  }
  cout << res;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <iterator>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define fast                                                                   \
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger {
  template <typename T> debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;

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

  int res = A * min(N, B - 1) / B;
  cout << res << endl;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ll i;
  ll a, b, n;
  ll ans = 0;
  ll tmp, start;
  cin >> a >> b >> n;
  start = min(n, b - 1);
  for (i = start; i <= n; i += b) {
    tmp = (a * i) / b - a * (i / b);
    if (tmp > ans)
      ans = tmp;
  }

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


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ll i;
  ll a, b, n;
  ll ans = 0;
  ll tmp, start;
  cin >> a >> b >> n;
  start = min(n, b - 1);
  // for (i = start; i <= n; i += b) {
  // 	tmp = (a * i) / b - a * (i / b);
  // 	if (tmp > ans)
  // 		ans = tmp;
  // }
  if (n <= b - 1) {
    start = n;
    ans = (a * start) / b;
  } else {
    ll altans;
    start = n - (n % b + 1);
    altans = (a * n) / b - a * (n / b);
    ans = (a * start) / b - a * (start / b);
    ans = max(ans, altans);
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <math.h>    // sqrt
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
  ld A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  for (ll i = 1; i < N + 1; i++) {
    ll ansa = floor(A * i / B) - A * floor(i / B);
    if (ansa < ans) {
      break;
    }
    ans = ansa;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <math.h>    // sqrt
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
  ld A, B, N;
  cin >> A >> B >> N;
  ll x = min(B - 1, N);
  ll ans = floor(A * x / B) - A * floor(x / B);
  cout << ans << endl;
}
Problem p02696 (C++)

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

int main() {
  int a;
  int64_t b, n;
  cin >> a >> b >> n;
  int64_t p;
  if (n < b) {
    p = n;
  } else {
    p = b - 1;
  }
  int maximum = 0;
  for (int i = 1; i <= p; i++) {
    int64_t x = a * i / b - i / b * a;
    maximum = max((int)x, maximum);
  }
  cout << maximum << endl;
}

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

int main() {
  int a;
  int64_t b, n;
  cin >> a >> b >> n;
  int64_t p;
  if (n < b) {
    p = n;
  } else {
    p = b - 1;
  }
  cout << a * p / b << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main() {
  LLONG A, B, N;
  cin >> A >> B >> N;
  LLONG ans = 0;
  for (LLONG x = N - max(A, B); x <= N; ++x) {
    LLONG t1 = A * x / B;
    LLONG t2 = x / B;
    t2 *= A;
    ans = max(ans, t1 - t2);
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main() {
  LLONG A, B, N;
  cin >> A >> B >> N;
  LLONG x = min(B - 1, N);
  LLONG t1 = A * x / B;
  LLONG t2 = x / B;
  t2 *= A;
  cout << t1 - t2 << endl;
}
Problem p02696 (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 rrep(i, m, n) for (int i = (m); i < (n); i++)
#define fore(i, a) for (auto &i : a)
#define debug(a, b) cout << "debug : " << a << " , " << b << endl
using ll = long long;
const ll INF = 1LL << 60;
const ll mod = 1E9 + 7;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll M = 0;
  if (b < INF) {
    for (ll k = n; k >= max(n - b, (ll)0); k--) {
      ll kb = k / b;
      if (a * k / b - a * kb > M)
        M = a * k / b - a * kb;
    }
  }
  cout << M;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, m, n) for (int i = (m); i < (n); i++)
#define fore(i, a) for (auto &i : a)
#define debug(a, b) cout << "debug : " << a << " , " << b << endl
using ll = long long;
const ll INF = 1LL << 60;
const ll mod = 1E9 + 7;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  auto f = [&](ll x) {
    ll xb = x / b;
    return a * x / b - a * xb;
  };
  cout << max(f(n), f(n - 1 - n % b));
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for (ll i = 0; i < t; i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size()) cout << v[i] << " "
const double h = 1e-6;
const int MAX_ = 200005;
#define all(v) v.begin(), v.end()

inline ll mul(ll a, ll b) { return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b) {
  ll c = a - b;
  if (c < 0)
    c += MOD;
  return c;
}
inline ll add(ll a, ll b) {
  ll c = a + b;
  if (c > MOD)
    c -= MOD;
  return c;
}
ll sqr(ll x) { return x * x; }
//////////////////////*********CODE***********/////////////////////
//////////////////////////////////////////////////////////////////
ll val(ll a, ll b, ll mid) {
  ll res = (a * mid) / b - a * (mid / b);
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll l = 1, r = n;
  ll ans = 0;

  while (l < r) {
    ll mid = (l + r) / 2;
    ll lft = val(a, b, l);
    ll rgh = val(a, b, r);
    ll mm = val(a, b, mid);
    ans = max({ans, lft, rgh});
    if (mm >= lft) {
      l = mid + 1;
      ans = max(mm, ans);
    } else if (rgh <= mm) {
      r = mid - 1;
      ans = max(ans, mm);
    }
  }
  ll lf = val(a, b, l);
  ll rr = val(a, b, r);
  ans = max(ans, rr);
  ans = max(ans, lf);
  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for (ll i = 0; i < t; i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size()) cout << v[i] << " "
const double h = 1e-6;
const int MAX_ = 200005;
#define all(v) v.begin(), v.end()

inline ll mul(ll a, ll b) { return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b) {
  ll c = a - b;
  if (c < 0)
    c += MOD;
  return c;
}
inline ll add(ll a, ll b) {
  ll c = a + b;
  if (c > MOD)
    c -= MOD;
  return c;
}
ll sqr(ll x) { return x * x; }
//////////////////////*********CODE***********/////////////////////
//////////////////////////////////////////////////////////////////
ll val(ll a, ll b, ll mid) {
  ll res = (a * mid) / b - a * (mid / b);
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll go = min(b - 1, n);
  cout << val(a, b, go);

  return 0;
}
Problem p02696 (C++)

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

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

ll func(ll a, ll b, double x) {
  ll ans = (ll)(a * x / b) - a * (ll)(x / b);
  return ans;
}

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll mx = 0;
  for (int i = 1; i <= N; i++) {
    mx = max(mx, func(A, B, i));
  }
  cout << mx << endl;
  return 0;
}

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

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

ll func(ll a, ll b, double x) {
  ll ans = (ll)(a * x / b) - a * (ll)(x / b);
  return ans;
}

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  ll ans = (A * (x % B) - A * (x % B) % B) / B;
  cout << ans << endl;
  return 0;
}
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>;

const ll INF = 1e18;
const int MX = 2005;

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

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>;

const ll INF = 1e18;
const int MX = 2005;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = min(n, b - 1) * a / 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 cost = 0;
  rep(x, n + 1) cost = max(cost, ll(floor(a * x / b) - a * floor(x / b)));
  cout << cost << 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 = n;
  if (n >= b - 1)
    x = b - 1;
  ll ans = floor(a * x / b) - a * floor(x / b);
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++)

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll flag = -inf;

  for (ll i = 1; i <= n; i++) {
    ll res = (a * i) / b;
    ll ans = a * (i / b);
    flag = max(res - ans, flag);
  }
  cout << flag << endl;
  return 0;
}

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll flag = -inf;

  /*for(ll i=1;i<=n;i++){

     flag = max(res-ans,flag);

  }
  */
  if (n < b) {
    cout << (a * n) / b << endl;
    return 0;
  } else {
    flag = max(a * (b - 1) / b, flag);

    flag = max(flag, (a * n) / b - a * (n / b));
  }
  cout << flag << endl;
  return 0;
}
Problem p02696 (C++)

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

int main() {
  long long int a, b, n;
  cin >> a >> b >> n;
  long long int ans = INT_MIN;
  if (n < b) {
    ans = (a * n) / b;
  } else {
    long long int x = b - 1;
    long long int t;
    while (x <= n) {
      t = (a * x) / b - a * (x / b);
      ans = max(ans, t);
      x = x + b;
    }
  }
  cout << ans;
  return 0;
}

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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};
const double PI = 3.14159265358979323846;

int main() {

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

  ll ans = 0;

  if (n < b) {
    ans = (a * n) / b - a * (n / b);
    cout << ans << endl;
  } else {
    ll cnt = n / b;
    ll num = 0;
    for (ll i = (cnt / 2); i < cnt; i++) {
      num = b * (i + 1) - 1;
      ans = max(ans, (a * num) / b - a * (num / b));
    }
    cout << ans << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};
const double PI = 3.14159265358979323846;

int main() {

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

  ll ans = 0;

  if (n < b) {
    ans = (a * n) / b - a * (n / b);
    cout << ans << endl;
  } else {
    ll cnt = n / b;
    ll num = 0;
    for (ll i = (cnt - 1); i < cnt; i++) {
      num = b * (i + 1) - 1;
      ans = max(ans, (a * num) / b - a * (num / b));
    }
    cout << ans << endl;
  }

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int A;
  ull B, N;
  cin >> A >> B >> N;
  ull max_x = 0;
  for (ull x = 1; x <= min(N, B); x++) {
    max_x = max(max_x, ull((A * x) / B) - (ull(x / B)) * A);
  }
  cout << max_x << endl;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  cout << A * min(B - 1, N) / B << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define INF INT_MAX / 3
#define REP(i, n) for (int i = 0; i < n; i++)

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

  ll answer = 0;
  for (ll i = 1; i <= N; i++) {
    answer = max((A * i) / B - A * (i / B), answer);
  }
  cout << answer << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define INF INT_MAX / 3
#define REP(i, n) for (int i = 0; i < n; i++)

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

  ll answer = 0;
  if (N >= B - 1) {
    answer = (A * (B - 1)) / B;
  } else {
    answer = (A * N) / B;
  }
  cout << answer << endl;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define pb push_back
#define boostup                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
typedef long long int ll;
using namespace std;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll x = 0;
  for (x = 0; x <= n; x++) {
    ll d;
    d = floor((a * x) / b) - a * floor(x / b);
    if (d > ans) {
      ans = d;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define boostup                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
typedef long long int ll;
using namespace std;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = -10000000000000;
  ll x = min(n, b - 1);
  ll d;
  d = floor((a * x) / b) - a * floor(x / b);
  cout << d << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define roop(i, n) for (int i = 0; i < n; i++)
#define DIV 1000000007

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
  float x = 1;
  while (n > 0) { // 全てのbitが捨てられるまで
    if (n & 1) {  // 一番右のbitが１のとき
      x *= a;
    }
    a *= a;
    n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
  }
  return x;
}

ll combination(ll n, ll r) {
  if (n < 0 || r < 0 || r > n)
    return -1;

  if (n - r < r)
    r = n - r;
  if (r == 0)
    return 1;
  if (r == 1)
    return n;

  vector<ll> num(r);
  vector<ll> den(r);

  for (ll i = 0; i < r; i++) {
    num[i] = n - r + i + 1;
    den[i] = i + 1;
  }

  for (ll p = 2; p <= r; p++) {
    ll pivot = den[p - 1];
    if (pivot > 1) {
      ll offset = (n - r) % p;
      for (ll k = p - 1; k < r; k += p) {
        num[k - offset] /= pivot;
        den[k] /= pivot;
      }
    }
  }
  ll result = 1;
  for (ll k = 0; k < r; k++) {
    if (num[k] > 1)
      result *= num[k];
  }
  return result;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll max = 0;
  for (ll x = 0; x <= n; x++) {
    ll colc = floor((a * x) / b) - a * floor(x / b);
    if (max <= colc) {
      max = colc;
    }
  }
  cout << max << endl;
  return 0;
}

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

#define roop(i, n) for (int i = 0; i < n; i++)
#define DIV 1000000007

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
  float x = 1;
  while (n > 0) { // 全てのbitが捨てられるまで
    if (n & 1) {  // 一番右のbitが１のとき
      x *= a;
    }
    a *= a;
    n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
  }
  return x;
}

ll combination(ll n, ll r) {
  if (n < 0 || r < 0 || r > n)
    return -1;

  if (n - r < r)
    r = n - r;
  if (r == 0)
    return 1;
  if (r == 1)
    return n;

  vector<ll> num(r);
  vector<ll> den(r);

  for (ll i = 0; i < r; i++) {
    num[i] = n - r + i + 1;
    den[i] = i + 1;
  }

  for (ll p = 2; p <= r; p++) {
    ll pivot = den[p - 1];
    if (pivot > 1) {
      ll offset = (n - r) % p;
      for (ll k = p - 1; k < r; k += p) {
        num[k - offset] /= pivot;
        den[k] /= pivot;
      }
    }
  }
  ll result = 1;
  for (ll k = 0; k < r; k++) {
    if (num[k] > 1)
      result *= num[k];
  }
  return result;
}

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

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

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

  const double dB = (double)B;
  const double dAB = A / dB;

  unsigned long long x = 0;
  unsigned long long max = 0;
  for (int i = 0; x < N; ++i) {
    x = B * (i + 1) - 1;
    x = x > N ? N : x;

    const unsigned long long result =
        (unsigned long long)(x * dAB) - A * (unsigned long long)(x / dB);

    if (result > max)
      max = result;
  }

  std::cout << max << std::endl;

  return 0;
}


Fixed submission:
#include <iostream>

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

  const double dB = (double)B;
  const double dAB = A / dB;

  unsigned long long x = 0;
  unsigned long long max = 0;
  for (int i = 0; x < N; ++i) {
    x = B * (i + 1) - 1;
    x = x > N ? N : x;

    const unsigned long long result =
        (unsigned long long)(x * dAB) - A * (unsigned long long)(x / dB);

    if (result > max)
      max = result;
    else
      break;
  }

  std::cout << max << std::endl;

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, n, ans = 0;
  cin >> a >> b >> n;
  for (int x = 0; x <= n; x++) {
    long long left = a * x / b, right = x / b;
    ans = max(ans, left - a * right);
    if (right != 0) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, n, ans = 0;
  cin >> a >> b >> n;
  if (n < b)
    ans = a * n / b;
  else
    ans = a * (b - 1) / b;
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  vector<ll> A(n, -1);
  ll ans = -1;
  A[0] = 0;
  rep2(i, 1, n) {
    A[i] = (a * i) / b - a * (i / b);
    ans = max(ans, A[i]);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long int
#define M 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2 * acos(0.0)
#define F first
#define S second
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
const int INF = 1e18L + 5;
const int LG = 20;
const int N = 1e5 + 9;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
int power(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y % 2 == 1)
      res = (res * x) % M;
    x = (x * x) % M;
    y = y / 2;
  }
  return res;
}
bool isvowel(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' ||
      c == 'E' || c == 'I' || c == 'O' || c == 'U')
    return true;
  return false;
}
int32_t main() {
  // cout.precision(15);
  // cout.setf(ios::fixed,ios::floatfield);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int T = 1;
  // cin>>T;
  while (T--) {
    int i = 0, a, b, n, x;
    cin >> a >> b >> n;
    x = b - 1;
    i = n / (x * b);
    x = max(x, i * x);
    x = min(x, n);
    cout << (a * (x) / b - a * ((x) / b)) << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long int
#define M 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2 * acos(0.0)
#define F first
#define S second
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
const int INF = 1e18L + 5;
const int LG = 20;
const int N = 1e5 + 9;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
int power(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y % 2 == 1)
      res = (res * x) % M;
    x = (x * x) % M;
    y = y / 2;
  }
  return res;
}
bool isvowel(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' ||
      c == 'E' || c == 'I' || c == 'O' || c == 'U')
    return true;
  return false;
}
int32_t main() {
  // cout.precision(15);
  // cout.setf(ios::fixed,ios::floatfield);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int T = 1;
  // cin>>T;
  while (T--) {
    int i = 0, a, b, n, x;
    cin >> a >> b >> n;
    x = b - 1;
    if (x != 0)
      i = n / (x * b);
    x = max(x, i * x);
    x = min(x, n);
    cout << (a * (x) / b - a * ((x) / b)) << 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++)
typedef long long ll;
using namespace std;

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

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, ll(floor((a * i) / b) - a * floor(i / b)));
  }

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


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

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

  ll x = n < b ? n : b - 1;
  ll ans = floor((a * x) / b) - a * floor(x / b);

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

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

int main() {
  int A;
  int64_t B, N;
  cin >> A >> B >> N;
  int ans = 0;
  for (int64_t i = 1; i <= min(B, N); ++i) {
    int x = floor(A * i / B) - A * floor(i / B);
    if (x > ans) {
      ans = x;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int A;
  int64_t B, N;
  cin >> A >> B >> N;
  cout << floor(A * min(B - 1, N) / B) - A * floor(min(B - 1, N) / B) << endl;
  return 0;
}