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

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

// Shortening code
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

// Macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = a; i >= b; i--)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // Your code
  ll a, b, n;
  cin >> a >> b >> n;
  ll max_val = 0;
  for (ll i = 0; i <= n; i++) {
    max_val = max(max_val, (ll)(floor(a * i / b) - a * floor(i / b)));
  }
  cout << max_val;
  return 0;
}

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

// Shortening code
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

// Macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = a; i >= b; i--)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // Your code
  ll a, b, n;
  cin >> a >> b >> n;
  ll ind = min(b - 1, n);
  cout << floor(a * ind / b);
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  for (ll x = b - 1; x <= n; x += b) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }
  ans = max(ans, (a * n) / b - a * (n / b));
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (b == 1) {
    cout << ans << endl;
    return 0;
  }
  for (ll x = b - 1; x <= n; x += b) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }
  ans = max(ans, (a * n) / b - a * (n / b));
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t A, B, N;
  cin >> A >> B >> N;
  int64_t max_val = INT64_MIN;
  for (int64_t x = 0; x < B && x <= N; ++x) {
    const int64_t val = (A * x) / B - A * (x / B);
    if (val > max_val) {
      max_val = val;
    }
  }
  cout << max_val << endl;

  return 0;
}


Fixed submission:
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t A, B, N;
  cin >> A >> B >> N;
  int64_t max_val = (A * min(B - 1, N)) / B;
  cout << max_val << endl;

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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;
}
ll INF = 1 << 25;
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll X = -1 * INF;
  for (int i = 0; i <= N; i++) {
    ll Y = (ll)(A * i / B) - (ll)A * (i / B);
    chmax(X, Y);
  }
  cout << X << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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;
}
ll INF = 1 << 25;
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  // ll X = -1*INF;
  // for (int i=0;i<=N;i++) {
  //     ll Y = (ll)(A*i/B)-(ll)A*(i/B);
  //     // cout << i << " " << Y << endl;
  //     chmax(X, Y);
  // }
  // cout << X << endl;
  ll Z = min(B - 1, N);
  cout << (ll)(A * Z / B) - (ll)A * (Z / B) << 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++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define deb(x) cerr << #x << ": " << x << '\n';
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main() {
  ios;
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0, best = 0;
  rep1(x, 1e8 + 9e7) {
    if (x > N)
      break;
    ans = ((A * x) / B) - (A * (x / B));
    best = max(best, ans);
  }
  cout << best;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define deb(x) cerr << #x << ": " << x << '\n';
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main() {
  ios;
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0, max = min(B - 1, N);
  ans = ((A * max) / B) - (A * (max / B));
  cout << ans;
  return 0;
}
Problem p02696 (C++)

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll prev = 0;
  int flag = 0;
  for (ll x = 1; x < n + 1; x++) {
    prev = ans;
    ans = floor(a * x / b) - (a * floor(x / b));
    if (ans != 0)
      flag = 1;
    else if (flag == 1) {
      cout << prev << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

Buggy submission (status: Time Limit Exceeded):
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
  long long int a, b, n, v, i, max, tmp;
  scanf("%lld %lld %lld", &a, &b, &n);
  max = 0;
  for (i = 1; i <= n && i <= b * 2; i++) {
    v = floor(a * i * 1.00 / b) - a * floor(i / b);
    if (v > max)
      max = v;
  }
  printf("%lld\n", max);
  return 0;
}


Fixed submission:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
  long long int a, b, n, v, i, max, tmp;
  scanf("%lld %lld %lld", &a, &b, &n);
  max = 0;
  if (n < b) {
    max = floor(a * n * 1.00 / b);
  } else {
    max = floor(a * (b - 1) * 1.00 / b);
  }
  printf("%lld\n", max);
  return 0;
}
Problem p02696 (C++)

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

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

  long long int output, num;
  output = 0;

  if (N > B) {
    N = B;
  }

  for (int i = 1; i <= N; i++) {
    num = floor((A * i) / B) - A * floor(i / B);
    if (num >= output) {
      output = num;
    }
  }
  cout << output << endl;
  return 0;
}

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

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

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

Buggy submission (status: Time Limit Exceeded):
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
using namespace std;
typedef long long ll;

void Main() {
  ll a, b, n;
  cin >> a >> b >> n;
  int max = -1;
  ll t = 0;
  for (ll x = 1; x <= n; ++x) {
    t = floor(a * x / b) - a * floor(x / b);
    if (t > max) {
      max = t;
    }
  }
  cout << max << endl;
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Fixed submission:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
using namespace std;
typedef long long ll;

void Main() {
  ll a, b, n;
  cin >> a >> b >> n;
  int max = 0;

  if (b > n) {
    max = floor(a * n / b) - a * floor(n / b);
  } else {
    n = b - 1;
    max = floor(a * n / b) - a * floor(n / b);
  }
  cout << max << endl;
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}
Problem p02696 (C++)

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

ll a, b, n;

ll f(ll x) {
  ll A = floor(a * x / b);
  // cout << A << endl;
  ll B = floor(x / b);
  return A - a * B;
}

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


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

ll a, b, n;

ll f(ll x) {
  ll A = floor(a * x / b);
  // cout << A << endl;
  ll B = floor(x / b);
  return A - a * B;
}

int main() {
  cin >> a >> b >> n;
  ll ans = 0;
  if (b - 1 <= n) {
    ans = f(b - 1);
  } else {
    ans = f(n);
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++)

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

int f(long long a, long long b, long long x) {
  long long s = a * x / b;
  long long t = a * (x / b);
  return s - t;
}
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long ans = 0;
  for (long long i = n / 2; i <= n; i++) {
    if (ans < f(a, b, i))
      ans = f(a, b, i);
  }
  cout << ans << endl;
}

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

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

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

long long A, B, N;

long long dif(long long x) {
  long long a = A * x;
  a /= B;
  long long b = x / B;
  b *= A;
  return a - b;
}

long long bi(long long mi, long long ma, long long target) {
  if (ma - mi == 1) {
    return dif(ma);
  }

  long long mid = (ma + mi) / 2;
  long long midValue = dif(mid);
  if (midValue >= target) {
    return bi(mi, mid, target);
  } else {
    return bi(mid, ma, target);
  }
}

int main() {
  cin >> A >> B >> N;
  long long valueN = dif(N);
  long long x = N / B;
  x *= B;
  x -= 1;
  if (x < 0) {
    x = 0;
  }
  long long valueLastEdge = dif(x);
  long long target = max(valueN, valueLastEdge);
  cout << bi(0, min(N, B - 1), target);
}

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

long long A, B, N;

long long dif(long long x) {
  long long a = A * x;
  a /= B;
  long long b = x / B;
  b *= A;
  return a - b;
}

long long bi(long long mi, long long ma, long long target) {
  if (ma - mi == 1 || ma - mi == 0) {
    return dif(ma);
  }

  long long mid = (ma + mi) / 2;
  long long midValue = dif(mid);
  if (midValue >= target) {
    return bi(mi, mid, target);
  } else {
    return bi(mid, ma, target);
  }
}

int main() {
  cin >> A >> B >> N;
  long long valueN = dif(N);
  long long x = N / B;
  x *= B;
  x -= 1;
  if (x < 0) {
    x = 0;
  }
  long long valueLastEdge = dif(x);
  long long target = max(valueN, valueLastEdge);
  cout << bi(0, min(N, B - 1), target);
}
Problem p02696 (C++)

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n, k) ((((n) % (k)) + (k)) % (k))
#define forn(i, n) for (int i = 0; i < n; i++)
#define forr(i, a, b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

ll a, b, x, n, res;

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

  cin >> a >> b >> n;

  for (int x = max(1ll, n - int(2e6)); x <= n; x++) {
    res = max(res, (a * x) / b - a * (x / b));
  }
  cout << res << endl;

  return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n, k) ((((n) % (k)) + (k)) % (k))
#define forn(i, n) for (int i = 0; i < n; i++)
#define forr(i, a, b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

ll a, b, x, n, res;

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

  cin >> a >> b >> n;

  ll x = n - n % b - 1;
  if (x < 1)
    x = n;

  cout << (a * x) / b - a * (x / b) << 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 < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7, INF = 1e9;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = (ll)(floor(a * n) / b) - (ll)(a * floor(n / b));
  for (ll i = n; i >= b - 1; i--) {
    if (i > n)
      break;
    ans = max(ans, (ll)(floor(a * i) / b) - (ll)(a * floor(i / b)));
  }
  cout << ans << endl;
  system("pause");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7, INF = 1e9;

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

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

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

  while (i <= n && (i / b) < 1) {
    long long int tmp = floor(a * i / b);
    res = max(res, tmp);
    ++i;
  }

  cout << res << endl;
}

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

int main() {
  long long int a, b, n;
  long long int res = 0;
  cin >> a >> b >> n;
  long long int i = min(n, b - 1);
  res = floor(a * i / b);
  /*
     while (i<=n && (i/b)<1){
         long long int tmp=floor(a*i/b);
         res=max(res,tmp);
         ++i;
     }
  */
  cout << res << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
/**
 * D - Floor Function
 * https://atcoder.jp/contests/abc165/tasks/abc165_d
 */
#include <bits/stdc++.h>
using namespace std;

long long A, B, N;

long long calc(long long x) {
  long long floor1 = A * x / B;
  long long floor2 = x / B;
  return floor1 - A * floor2;
}

int main() {
  // 整数 A, B, N が与えられます。
  cin >> A >> B >> N;
  // N 以下の非負整数 x に対する
  // floor(Ax/B)−A×floor(x/B)の最大値を求めてください。
  // ただし、floor(t)とは、実数 t 以下の最大の整数のことを表します。

  long long maxNum = 0;
  for (long long x = 0; x <= N; x++) {
    long long c = calc(x);
    if (maxNum < c) {
      maxNum = c;
    }
  }

  cout << maxNum;
}


Fixed submission:
/**
 * D - Floor Function
 * https://atcoder.jp/contests/abc165/tasks/abc165_d
 */
#include <bits/stdc++.h>
using namespace std;

long long A, B, N;

long long calc(long long x) {
  long long floor1 = A * x / B;
  long long floor2 = x / B;
  return floor1 - A * floor2;
}

int main() {
  // 整数 A, B, N が与えられます。
  cin >> A >> B >> N;
  // N 以下の非負整数 x に対する
  // floor(Ax/B)−A×floor(x/B)の最大値を求めてください。
  // ただし、floor(t)とは、実数 t 以下の最大の整数のことを表します。

  long long keisu = N / B;
  long long maxNum1 = calc(B * keisu - 1);
  long long maxNum2 = calc(N);
  cout << (maxNum1 > maxNum2 ? maxNum1 : maxNum2);
}
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 (int i = 0; i <= N; i++) {
    ll num = (A * i / B) - A * (i / B);
    Ans = max(Ans, num);
  }
  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 ans;
  if (N < B)
    ans = (A * N / B);
  else
    ans = (A * (B - 1) / B);
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++)

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll sum = 0, prevSum = -1;
  for (ll x = 1; x <= n; x++) {
    sum = floor((a * x) / b) - a * floor(x / b);
    // cout<<x<<" "<<sum<<" "<<prevSum<<endl;
    if (prevSum == -1) {
      prevSum = sum;
    } else {
      if (sum < prevSum) {
        break;
      }
      prevSum = sum;
    }
  }
  // cout<<sum<<" "<<prevSum<<endl;
  cout << prevSum << endl;
  return 0;
}


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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18 + 1;
const ll DIV = 1000000007;
// #define TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef TEST
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
#endif
  ll A, B, N;
  cin >> A >> B >> N;
  ll max_num = 0;
  if (N / B == 0) {
    ll x = N;
    ll ax_b = (A * x) / B;
    ll x_b = x / B;
    max_num = max(max_num, ax_b - A * x_b);
  } else {
    for (size_t i = 1; i <= N / B; i++) {
      // ll ax_b = (A * i)/B;
      // ll x_b = i / B;
      ll x = i * B - 1;
      ll ax_b = (A * x) / B;
      ll x_b = x / B;
      max_num = max(max_num, ax_b - A * x_b);
    }
  }
  cout << max_num << endl;
#ifdef TEST
  end = chrono::system_clock::now();
  cerr << static_cast<double>(
              chrono::duration_cast<chrono::microseconds>(end - start).count() /
              1000.0)
       << "[ms]" << endl;
#endif
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18 + 1;
const ll DIV = 1000000007;
// #define TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef TEST
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
#endif
  ll A, B, N;
  cin >> A >> B >> N;
  ll max_num = 0;
  ll x = min(B - 1, N);
  ll ax_b = (A * x) / B;
  ll x_b = x / B;
  cout << ax_b - A * x_b << endl;
#ifdef TEST
  end = chrono::system_clock::now();
  cerr << static_cast<double>(
              chrono::duration_cast<chrono::microseconds>(end - start).count() /
              1000.0)
       << "[ms]" << endl;
#endif
  return 0;
}
Problem p02696 (C++)

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

int main() {
  long long n, a, b;
  cin >> a >> b >> n;
  if (b > n) {
    cout << a * n / b << endl;
    return 0;
  }

  long long y = n / b;
  priority_queue<long long> pq;
  for (int i = 1; i < y + 1; i++) {
    pq.push(b * i - 1);
  }
  pq.push(n);
  long long max = 0;
  while (!pq.empty()) {
    long long mae = a * pq.top() / b;
    long long ushi = pq.top() / b;
    if (max < mae - ushi * a)
      max = mae - ushi * a;
    pq.pop();
  }

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


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

int main() {
  long long n, a, b;
  cin >> a >> b >> n;
  if (b > n) {
    cout << a * n / b << endl;
    return 0;
  }

  cout << a * (b - 1) / b << endl;
  return 0;
}
Problem p02696 (C++)

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

#define all(v) v.begin(), v.end()
typedef long long ll;

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

  ll res = 0;
  for (int i = 0; i <= n; i++) {
    ll tmp = floor(a * i / b) - a * floor(i / b);
    res = max(res, tmp);
  }
  cout << res << endl;
}


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

#define all(v) v.begin(), v.end()
typedef long long ll;

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

  ll x = n;
  if (b <= n)
    x = b - 1 ? b - 1 : 1;
  ll res = floor(a * x / b) - a * floor(x / b);
  cout << res << endl;
}
Problem p02696 (C++)

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

#define ll long long

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

  ll max = 0;
  for (ll x = 0; x <= N; x++) {
    if (max < (A * x / B) / 1 - A * ((x / B) / 1)) {
      max = (A * x / B) / 1 - A * ((x / B) / 1);
    }
  }
  cout << max << endl;
}

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

#define ll long long

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

  ll max = 0;
  if (B > N) {
    max = (A * N / B) / 1 - A * ((N / B) / 1);
  } else {
    max = (A * (B - 1) / B) / 1 - A * (((B - 1) / B) / 1);
  }
  cout << max << 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 < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long ans = 0;
  long long NN = min(B, N);
  for (int i = 0; i <= NN; i++) {
    long long C = A * i;
    long long D = C / B;
    long long E = i / B;
    ans = max(ans, D - A * E);
  }
  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++)
#define all(v) v.begin(), v.end()
int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long ans = 0;
  long long NN = min(B - 1, N);
  long long C = A * NN;
  long long D = C / B;
  long long E = NN / B;
  ans = D - A * E;
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
// #pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
// #pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i += 1)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i -= 1)
#define endl '\n'
#define N 1000000007 // prime modulo value
#define C 1000000001
#define M 998244353
#define all(x) x.begin(), x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y) {
  ll res = 1;

  x = x;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
double dist(ll x1, ll y1, ll x2, ll y2) {
  double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll a, b, n;
  cin >> a >> b >> n;
  ll maxi = 0;
  f(i, 0, n + 1) {
    ll ta = floor((a * i) / b);
    ll tb = floor(i / b);
    maxi = max(maxi, ta - (a * tb));
  }
  cout << maxi;
  return 0;
}

Fixed submission:
// #pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
// #pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i += 1)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i -= 1)
#define endl '\n'
#define N 1000000007 // prime modulo value
#define C 1000000001
#define M 998244353
#define all(x) x.begin(), x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y) {
  ll res = 1;

  x = x;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
double dist(ll x1, ll y1, ll x2, ll y2) {
  double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = (a * min(n, b - 1)) / b;
  cout << ans;
  return 0;
}
Problem p02696 (C++)

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll max = 0;
  ll ans = 0;
  ll lol = 0;
  for (int i = 0; i <= n; i++) {
    ans = (a * i) / b - a * (i / b);
    if (ans > max) {
      max = ans;
    }
  }
  cout << max << endl;
  return 0;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll max = 0;
  ll ans = 0;
  ll lol = 0;
  ll x = min(b - 1, n);
  max = (a * x) / b - a * (x / b);
  cout << max << endl;
  return 0;
}
Problem p02696 (C++)

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

#define GO                                                                     \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

int32_t main() {
  GO;
  int a, b, n;
  cin >> a >> b >> n;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    int value = (a * i) / b - a * (i / b);
    ans = max(ans, value);
  }
  cout << ans << endl;
  return 0;
}

//!

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

#define GO                                                                     \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

int32_t main() {
  GO;
  int a, b, n;
  cin >> a >> b >> n;
  int ans = 0;
  int val = (b / n) * n;
  int i = val - 1;
  if (i >= 0 && i <= n)
    ans = max(ans, (a * i) / b - a * (i / b));
  i = (n / b) * b;
  i--;
  if (i >= 0 && i <= n)
    ans = max(ans, (a * i) / b - a * (i / b));
  i = n;
  ans = max(ans, (a * i) / b - a * (i / b));
  cout << ans << endl;
  return 0;
}

//!
Problem p02696 (C++)

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

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

  cin >> a >> b >> n;
  long long maxi = 0;
  for (int i = 0; i <= n; i++) {
    maxi = max(maxi, (i % b));
  }

  cout << a * maxi / b << endl;
}

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\n'
#define AC                                                                     \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(NULL);
using namespace std;
const int M = 1e9 + 7;
const int N = 2 * 1e5;

ll ans = 0;

int main() {
  AC ll a, b, n;
  cin >> a >> b >> n;
  ll x = 1;
  while (x < b && x <= n) {
    ans = max(ans, (ll)floor((double)(a * x) / b));
    x++;
  }
  if (x <= n) {
    x = min(n, 2 * b - 1);
    ll test = floor((double)(a * x) / b) - a * (x / b);
    ans = max(ans, test);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\n'
#define AC                                                                     \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(NULL);
using namespace std;
const int M = 1e9 + 7;
const int N = 2 * 1e5;

ll ans = 0;

int main() {
  AC ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(b - 1, n);
  ans = max(ans, (ll)floor((double)(a * x) / b));

  x = min(n, 2 * b - 1);
  ll test = floor((double)(a * x) / b) - a * (x / b);
  ans = max(ans, test);

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

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

int main() {
  ll A, B, N;
  std::cin >> A, B, N;
  ll maxX = std::min(B - 1, N);

  std::cout << A * (maxX) / B;

  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;

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

  ll maxX = std::min<ll>(B - 1, N);

  std::cout << A * (maxX) / B;

  return 0;
}
Problem p02696 (C++)

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

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

  if (N < B) {
    long long ans = A * N / B;
    std::cout << ans << std::endl;
  } else {
    long long max = 0;
    for (long long i = A - 1; i < A * B; i += A) {
      long long tmp = A * i / B - A * (long long)(i / B);
      max = max < tmp ? tmp : max;
    }
    std::cout << max << std::endl;
  }

  return 0;
}


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

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

  if (N < B) {
    long long ans = A * N / B;
    std::cout << ans << std::endl;
  } else {
    long long x = B - 1;
    long long ans = A * x / B - A * (long long)(x / B);
    std::cout << ans << std::endl;
  }

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
long long n, m, i, j, k, a, b;
int main() {
  scanf("%lld%lld%lld", &a, &b, &n);
  for (i = 0; i <= n; i++) {
    if (a * i / b - a * (i / b) > m) {
      m = a * i / b - a * (i / b);
      k = i;
    }
  }
  printf("%lld\n", m);
  return 0;
}

Fixed submission:
#include <stdio.h>
long long n, m, i, j, k, a, b;
int main() {
  scanf("%lld%lld%lld", &a, &b, &n);
  if (n >= b)
    n = b - 1;
  printf("%lld\n", a * n / b - a * (n / b));
  return 0;
}
Problem p02696 (C++)

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

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

  cin >> A >> B >> N;

  ll c = 0;

  for (ll i = 0; i <= N; i++) {
    c = max(c, (A * i) / B - A * (i / B));
  }

  cout << c;
  return 0;
}

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

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

  cin >> A >> B >> N;

  ll c = 0;

  if (B <= N) {
    c = (A * (B - 1)) / B - A * ((B - 1) / B);
  } else {
    c = (A * N) / B - A * (N / B);
  }

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

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

inline void up(ll &x, ll y) { x < y ? x = y : 0; }

int main() {
  ll a, b, n, ans = 0;
  std::cin >> a >> b >> n;
  for (ll x = 1; x <= n; ++x)
    up(ans, (a * x) / b - a * (x / b));
  std::cout << ans << '\n';
  return 0;
}


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

inline void up(ll &x, ll y) { x < y ? x = y : 0; }

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

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

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


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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, mn, flag, sum, cnt;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  for (ll i = 1; i <= n; i++) {

    flag = floor(a * i / b) - a * floor(i / b);
    if (flag >= mx)
      mx = flag;
    else
      break;
  }
  cout << mx << endl;
}


Fixed submission:
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, mn, flag, sum, cnt;

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long)1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char *variable_name, T &&value) {
  cout << variable_name << ": " << value << endl;
}
template <typename T1, typename... T2>
void __f(const char *names, T1 &&arg1, T2 &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

const ll N = 5e5 + 5;
ll *v;
ll a, b, n;

void solve() {
  cin >> a >> b >> n;
  ll mult = 1;
  ll _max = 0, val, x = min(n, mult * b - 1);
  while (x <= n) {
    double t1 = (a * x) / b, t2 = x / b;
    val = floor(t1) - (a * floor(t2));
    // trace(x, val);
    _max = max(_max, val);
    mult++;
    x = mult * b - 1;
  }
  cout << _max;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cout << "\n\nBLAH BLAH BLAH\n\n";
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long)1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char *variable_name, T &&value) {
  cout << variable_name << ": " << value << endl;
}
template <typename T1, typename... T2>
void __f(const char *names, T1 &&arg1, T2 &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

const ll N = 5e5 + 5;
ll *v;
ll a, b, n;

void solve() {
  cin >> a >> b >> n;
  ll _max = 0, val, x;
  if (b > n)
    x = n;
  else if (b == n)
    x = n - 1;
  else
    x = b - 1;
  double t1 = (a * x) / b, t2 = x / b;
  val = floor(t1) - (a * floor(t2));
  // trace(x, val);
  _max = max(_max, val);
  cout << _max;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cout << "\n\nBLAH BLAH BLAH\n\n";
  // cin >> t;
  while (t--) {
    solve();
  }
  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 < (N); i++)
#define repo(i, N) for (int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
// #define num 1000000007
#define pi acos(-1.0)
// cout << fixed << setprecision (20);   小数点以下2０桁まで
// intの最大値2147483647 ≒ 2×10^9
// long longの最大値9223372036854775807 ≒ 9×10^18
// オーバーフローに注意 long long　にする
//'1'+=16;      で大文字Aに
//'大文字'+=32;  で小文字に
// string s = to_string(int数);
// int n = stoi(string文字列);

int main() {

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

  long long ans = -10000;
  repo(i, min(b + 1, n + 1)) {
    long long z = (a * i) / b - a * (i / b);
    ans = max(ans, z);
  }

  cout << ans << endl;
}


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

int main() {

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

  int ans;

  if (b - 1 <= n)
    ans = a * (b - 1) / b;

  else
    ans = (a * n) / b;

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

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

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

  int ans = 0;
  repa(i, 1, 1000000000) {
    int tmp = floor(a * i / b) - a * floor(i / b);
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

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

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

  int x = min(b - 1, n);
  cout << (a * x) / b - a * (x / b) << endl;
}
Problem p02696 (C++)

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

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

  long long ans = (a * (n) / b) - a * ((n) / b);

  for (long long int i = 0; i <= n / (b - 1); i++) {
    long long sum1 = (a * ((b - 1) * i)) / b;
    long long sum2 = a * (((b - 1) * i) / b);
    ans = max(ans, sum1 - sum2);
  }
  cout << ans << endl;
}

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

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

  long long ans = (a * n / b) - a * (n / b);
  if (b - 1 <= n) {
    ans = max(ans, (a * (b - 1) / b) - a * ((b - 1) / b));
  }
  cout << ans << endl;
}
Problem p02696 (C++)

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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define f(i, j, k) for (int i = j; i < k; i++)
using namespace std;
int main() {
  long long a, b, c, ans = 0, j;
  cin >> a >> b >> c;
  j = c / b;

  f(i, 1, j + 1) {
    if (ans < floor(a * (b * i - 1) / b) - a * floor((b * i - 1) / b)) {
      ans = floor(a * (b * i - 1) / b) - a * floor((b * i - 1) / b);
    }
    if (ans == a - 1 - a / b) {
      cout << a - 1 - a / b << endl;
      return 0;
    }
  }
  if (ans < floor(a * c / b) - a * floor(c / b)) {
    ans = floor(a * c / b) - a * floor(c / b);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define f(i, j, k) for (int i = j; i < k; i++)
using namespace std;
int main() {
  long long a, b, c, ans = 0, j;
  cin >> a >> b >> c;
  j = c / b;
  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }
  f(i, 1, j + 1) {
    if (ans < floor(a * (b * i - 1) / b) - a * floor((b * i - 1) / b)) {
      ans = floor(a * (b * i - 1) / b) - a * floor((b * i - 1) / b);
    }
    if (ans == a - 1 - a / b) {
      cout << a - 1 - a / b << endl;
      return 0;
    }
  }
  if (ans < floor(a * c / b) - a * floor(c / b)) {
    ans = floor(a * c / b) - a * floor(c / 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##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c)                                                            \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\n"

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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long lint;

using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lint a, b, n, max = -1;
  cin >> a >> b >> n;
  if (b - 1 <= n) {
    lint mod = n % b;
    lint num = n - mod - 1;
    max = floor(a * num * 1.0 / b) - a * floor(num * 1.0 / b);
  } else {
    for (lint i = n; 1 <= i; i--) {
      lint tmp = floor(a * i * 1.0 / b) - a * floor(i * 1.0 / b);
      chmax(max, tmp);
      if (i % b == b - 1)
        break;
    }
  }
  cout << max << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c)                                                            \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\n"

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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long lint;

using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lint a, b, n, max = -1;
  cin >> a >> b >> n;
  if (b - 1 <= n) {
    lint mod = n % b;
    lint num = n - mod - 1;
    max = floor(a * num * 1.0 / b) - a * floor(num * 1.0 / b);
  } else {
    max = floor(a * n * 1.0 / b) - a * floor(n * 1.0 / b);
  }
  cout << max << endl;
}
Problem p02696 (C++)

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll cnt = 0;
  while (true) {
    ans = max((ll)(a * n / b) - a * (ll)(n / b), ans);
    n--;
    cnt++;
    if (cnt == 1000000000 || n == 0)
      break;
  }
  cout << ans << "\n";
  return 0;
}


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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  n = min(n, b - 1);
  cout << (a * n - a * n % b) / b - a * (n - n % b) / b;

  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;
  cin >> a >> b >> n;
  long long x = 0, y = min(b - 1, n);
  vector<int> ans;
  while (((a * x) / b) - (a * (x / b)) < a && x <= y) {
    ans.push_back(((a * x) / b) - (a * (x / b)));
    x++;
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  cout << ans.at(0) << endl;
  return 0;
}


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