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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
const ll MOD = 998244353;
// const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL << 50);
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}

int main() {
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  if (x == N) {
    cout << (A * x) / B - A * (x / B) << endl;
    return 0;
  }
  ll ans = (A * x) / B - A * (x / B);
  while (x <= N && (A * x) % B == (A * (B - 1)) % B) {
    chmax(ans, (A * x) / B - A * (x / B));
    x += B;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
const ll MOD = 998244353;
// const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL << 50);
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}

int main() {
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  if (x == N) {
    cout << (A * x) / B - A * (x / B) << endl;
    return 0;
  }
  ll ans = (A * x) / B - A * (x / B);
  x += B;
  while (x <= N && (A * x) % B != (A * (B - 1)) % B) {
    chmax(ans, (A * x) / B - A * (x / B));
    x += B;
  }
  cout << ans << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long A, B, M, x, maxim = -1;
int main() {
  cin >> A >> B >> M;
  if (M < B) {
    x = M;
    cout << A * x / B << '\n';
  } else {
    x = B - 1;
    while (x < M) {
      maxim = max(A * x / B - A * (x / B), maxim);
      x += B;
    }
    x = M;
    maxim = max(A * x / B - A * (x / B), maxim);
    cout << maxim << '\n';
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long A, B, M, x, maxim = -1;
int main() {
  cin >> A >> B >> M;
  if (M < B) {
    x = M;
    cout << A * x / B << '\n';
  } else {
    x = B - 1;
    maxim = max(A * x / B - A * (x / B), maxim);
    long long coe = ((M + 1) / B) - 1;
    x = coe * B - 1;
    maxim = max(A * x / B - A * (x / B), maxim);
    x = M;
    maxim = max(A * x / B - A * (x / B), maxim);
    cout << maxim << '\n';
  }
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  ll m = -1;
  for (int i = 1; i <= n; i++) {
    if (i > b) {
      cout << m << endl;
      return 0;
    }
    ll num = (a * i) / b - a * (i / b);
    m = max(m, num);
  }
  cout << m << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  ll flag = min(b - 1, n);
  ll i = flag;
  ll num = (a * i) / b - a * (i / b);
  cout << num << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long int
using namespace std;
signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  int maxi = INT_MIN;

  for (int x = 1; x <= n; x++) {
    int t = floor((a * x) / b) - a * floor(x / b);
    maxi = max(t, maxi);
  }
  cout << maxi;
}


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

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

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

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

  return 0;
}


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

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

  cout << (a * min(n, (b - 1))) / b;

  return 0;
}
Problem p02696 (C++)

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

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

  int64_t max_xB = 0; // A(x%B)のmax
  for (int i = 0; i < N; i++) {
    int x = i + 1;
    max_xB = max(max_xB, x % B);
  }

  printf("%ld\n", (-A * max_xB % B + A * max_xB) / B);
  return 0;
}

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

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

  int64_t x = 0;
  if (N < B - 1)
    x = N;
  else
    x = B - 1;
  printf("%ld\n", (-A * (x % B) % B + A * (x % B)) / B);
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define f(i, a, b) for (int i = a; i <= b; i++)
inline ll read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
#define d read()
ll a, b, n;
ll mx, num;
int main() {
  //	while(1){
  //		mx=num=0;
  //		a=d,b=d,n=d;
  //	//if(a>b)swap(a,b);
  //	f(i,1,n){
  //		ll
  //k=floor((double)a*(double)i/(double)b)-a*floor((double)i/(double)b);
  //		if(k>mx)mx=k;
  //	}
  //	f(i,1,n)
  //		if(floor((double)a*(double)i/(double)b)-a*floor((double)i/(double)b)==mx)cout<<i<<"
  //"; 	cout<<endl;
  //	}
  scanf("%lld%lld%lld", &a, &b, &n);
  if (a >= b) {
    f(i, 1, n) {
      ll x = a * i / b - a * (i / b);
      if (x > mx)
        mx = x;
    }
    cout << mx;
    return 0;
  }
  if (b - b / a <= n) {
    cout << a * (b - b / a) / b - a * ((b - b / a) / b);
    return 0;
  }
  cout << a * n / b - a * (n / b);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define f(i, a, b) for (int i = a; i <= b; i++)
inline ll read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
#define d read()
ll a, b, n;
ll mx, num;
int main() {
  //	while(1){
  //		mx=num=0;
  //		a=d,b=d,n=d;
  //	//if(a>b)swap(a,b);
  //	f(i,1,n){
  //		ll
  //k=floor((double)a*(double)i/(double)b)-a*floor((double)i/(double)b);
  //		if(k>mx)mx=k;
  //	}
  //	f(i,1,n)
  //		if(floor((double)a*(double)i/(double)b)-a*floor((double)i/(double)b)==mx)cout<<i<<"
  //"; 	cout<<endl;
  //	}
  scanf("%lld%lld%lld", &a, &b, &n);
  if (a >= b) {
    if (b - 1 <= n)
      cout << a * (b - 1) / b - a * ((b - 1) / b);
    else
      cout << a * n / b - a * (n / b);
    return 0;
  }
  if (b - b / a <= n) {
    cout << a * (b - b / a) / b - a * ((b - b / a) / b);
    return 0;
  }
  cout << a * n / b - a * (n / b);
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h> //Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &a) {
  for (const A &it : a)
    out << it << " ";
  return out;
}
template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) {
  return in >> a.first >> a.second;
}
template <class A> istream &operator>>(istream &in, vector<A> &a) {
  for (A &i : a)
    in >> i;
  return in;
}
ifstream cinn("input.txt");
ofstream coutt("output.txt");

int a, b, n;

int ff(int x) { return (a * x) / b - a * (x / b); }

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

signed main() {
  FASTER;
  cin >> a >> b >> n;
  cout << f(0, n);
}


Fixed submission:
#include <bits/stdc++.h> //Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &a) {
  for (const A &it : a)
    out << it << " ";
  return out;
}
template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) {
  return in >> a.first >> a.second;
}
template <class A> istream &operator>>(istream &in, vector<A> &a) {
  for (A &i : a)
    in >> i;
  return in;
}
ifstream cinn("input.txt");
ofstream coutt("output.txt");

int a, b, n;

int ff(int x) { return (a * x) / b - a * (x / b); }

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

signed main() {
  FASTER;
  cin >> a >> b >> n;
  n = min(b, n);
  cout << f(0, n);
}
Problem p02696 (C++)

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

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

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

  long long ans = 0;
  for (long long i = N; 0 <= i; --i) {
    long long buf = (floor(A * i / B) - A * floor(i / B));
    ans = max(ans, buf);
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

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

  long long ans = 0;
  long long x = min(N, B - 1);
  ans = floor((A * x) / 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++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;

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

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

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

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

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

  int ans = 0;
  for (double x = 1; x <= n; x++) {
    int g = ans;
    ans = floor(a * x / b) - a * floor(x / b);
    ans = max(ans, g);
  }
  cout << ans << endl;
}


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

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

  long long ans = 0, x = n;
  if (n >= b - 1)
    x = b - 1;
  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>
#define ll long long int
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //	cout<<fixed<<setprecision(10);
  ll a, b, n;
  cin >> a >> b >> n;
  ll x, y, z;
  x = min(b - 1, n);
  ll ans = 0;
  ll ans1;
  while (x <= n) {
    ans1 = ((a * x) / b) - a * (x / b);
    ans = max(ans, ans1);
    x += 1;
    x += b;
    x -= 1;
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //	cout<<fixed<<setprecision(10);
  ll a, b, n;
  cin >> a >> b >> n;
  ll m = (n / b) * b - 1;
  ll ans1 = ((a * m) / b) - a * (m / b);
  ll ans = ((a * n) / b) - a * (n / b);
  cout << max(ans, ans1);
  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;

  // xはBの倍数-1だけ試す
  long long x = B - 1;
  int i = 1;
  int ans = 0;

  if (B > N) {
    ans = (A * N) / B - A * (x / B);

    cout << ans << endl;

    return 0;
  }

  while (x <= N) {

    int TRY;

    TRY = (A * x) / B - A * (x / B);

    ans = max(ans, TRY);

    i++;

    x = B * i - 1;
  }

  cout << ans << endl;

  return 0;
}

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

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

  if (B == 1) { // B = 1の時は計算しない
    cout << 0 << endl;
    return 0;
  }

  // xはBの倍数-1だけ試す
  long long x = B - 1;
  int i = 1;
  int ans = 0;

  if (B > N) {
    ans = (A * N) / B - A * (x / B);

    cout << ans << endl;

    return 0;
  }

  while (x <= N) {

    int TRY;

    TRY = (A * x) / B - A * (x / B);

    ans = max(ans, TRY);

    i++;

    x = B * i - 1;
  }

  cout << ans << endl;

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

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

  long long x = 0;
  long long ans = 0;

  if (b > n) {
    x = n;
    ans = a * x / b;
  } else {
    double M = 0;
    for (int i = 1; i < b; i++) {
      double num = (double)i / (double)b;
      if (M < num) {
        M = num;
        x = i;
      }
    }
    ans = (int)((double)a * M);
  }

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

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

  long long x = 0;
  long long ans = 0;

  if (b > n) {
    x = n;
    ans = a * x / b;
  } else {

    ans = (int)((double)a * (double)(b - 1) / (double)b);
  }

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

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

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
#define vll vector<ll>

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

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

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

  ll a, b, n, mv = 0, v;
  cin >> a >> b >> n;

  REP(i, min(b, n) + 1) {
    v = f(a, b, i);
    mv = max(v, mv);
    if (mv != 0 && v == 0)
      break;
  }

  cout << mv << endl;

  return 0;
}

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

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
#define vll vector<ll>

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

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

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

  ll a, b, n, mv = 0, v;
  cin >> a >> b >> n;

  if (b <= n)
    cout << f(a, b, b - 1) << endl;
  else
    cout << f(a, b, n) << endl;

  return 0;
}
Problem p02696 (C++)

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

using namespace std;
const int INF = 1e9 + 5;
typedef long long ll;
const int MOD = 1e9 + 7;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll maxi = INT_MIN;
  int j = 1;
  if (j > 100000000)
    j = 100000000;
  for (ll i = j; i <= n; i++) {
    maxi = max(maxi, ((a * i) / b) - a * (i / b));
  }
  cout << maxi << endl;

  return 0;
}


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

using namespace std;
const int INF = 1e9 + 5;
typedef long long ll;
const int MOD = 1e9 + 7;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  // ll maxi=INT_MIN;
  ll ans;
  if (b <= n)
    ans = (a * (b - 1)) / b;
  else
    ans = (a * n) / b;
  cout << ans << endl;

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
/**
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 *  Institute : Pandit Deendayal Petroleum University
 **/
#include <bits/stdc++.h>

using namespace std;

#define start_cooking int main()
#define food_is_ready return 0;
#define main_ingredient_added                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

start_cooking {
  main_ingredient_added
      // start with your recipe
      long long a,
      b, n;
  cin >> a >> b >> n;
  long long i, ans = 0;
  for (i = b - 1; i < n + 1; i += b)
    ans = max(ans, (a * i) / b - a * (i / b));
  i = n;
  ans = max(ans, (a * i) / b - a * (i / b));
  cout << ans;
  food_is_ready
}

Fixed submission:
/**
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 *  Institute : Pandit Deendayal Petroleum University
 **/
#include <bits/stdc++.h>

using namespace std;

#define start_cooking int main()
#define food_is_ready return 0;
#define main_ingredient_added                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

start_cooking {
  main_ingredient_added
      // start with your recipe
      long long a,
      b, n;
  cin >> a >> b >> n;
  long long k;
  k = min(n, b - 1);
  cout << (a * k) / b - a * (k / b);
  food_is_ready
}
Problem p02696 (C++)

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

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

  int64_t starter = N / B;
  starter *= B;
  if (starter == 0)
    starter = B;
  int64_t max_num = 0;
  for (int64_t x = B; x <= N; x += B) {
    int64_t calcx = x - 1;
    int64_t first = A * calcx / B;
    int64_t second = calcx / B;

    int64_t result = first - A * second;
    if (max_num < result)
      max_num = result;
  }
  int64_t calcx = N;
  int64_t first = A * calcx / B;
  int64_t second = calcx / B;

  int64_t result = first - A * second;
  if (max_num < result)
    max_num = result;

  std::cout << max_num;
}

Fixed submission:
#include <iostream>

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

  int64_t starter = N / B;
  starter *= B;
  if (starter == 0)
    starter = B;
  int64_t max_num = 0;
  for (int64_t x = starter; x <= N; x += B) {
    int64_t calcx = x - 1;
    int64_t first = A * calcx / B;
    int64_t second = calcx / B;

    int64_t result = first - A * second;
    if (max_num < result)
      max_num = result;
  }
  int64_t calcx = N;
  int64_t first = A * calcx / B;
  int64_t second = calcx / B;

  int64_t result = first - A * second;
  if (max_num < result)
    max_num = result;

  std::cout << max_num;
}
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++)
const int INF = 1001001001;

int main() {
  long long int a, b, n;
  cin >> a >> b >> n;
  int ans = 0;
  if (b < n)
    n = b;
  for (int x = 1; x <= n; x++) {
    long double x1 = a * x / b;
    long double x2 = x / b;
    int answ = floor(x1) - a * floor(x2);
    if (ans < answ)
      ans = answ;
  }

  cout << ans << endl;
}

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

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

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

#define ll long long
#define ld long long
#define pi 3.14159265359

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

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

#define ll long long
#define ld long long
#define pi 3.14159265359

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll m;
  if (N < B) {
    m = (A * N) / B - A * (N / B);
  } else {
    m = (A * (B - 1)) / B - A * ((B - 1) / B);
  }
  cout << m << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ma = 0;
  for (int x = 0; x <= min(b, n); x++) {
    ma = max(a * x / b - x / b * a, ma);
    if (a * x / b - x / b * a >= a)
      break;
  }

  cout << ma << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#define int long long

signed main() {
  int N, A, B;
  std::cin >> A >> B >> N;
  /*
      int start = 0;
      int end = N + 1;
      int maxVal = 0;
      int moy = 0;

      while (start < end && moy < N)
      {
          moy = (start + end) / 2;
          int val = ((A * moy) / B) - (A * (moy / B));

          if (val > maxVal)
          {
              start = moy;
          }
          else
          {
              end = moy;
          }

          maxVal = std::max(val, maxVal);
      }

      moy = (start + end) / 2;
      int val = (int)(std::floor((A * moy) / B)) - (int)((A * std::floor(moy /
     B))); maxVal = std::max(val, maxVal);*/
  int maxVal = 0;
  for (int i = 0; i <= N; i++) {
    maxVal = std::max(maxVal, (int)(std::floor((A * i) / B)) -
                                  (int)((A * std::floor(i / B))));
  }
  std::cout << maxVal;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#define int long long

signed main() {
  int N, A, B;
  std::cin >> A >> B >> N;
  std::cout << (int)(std::floor((A * std::min((B - 1), N)) / B)) -
                   (int)((A * std::floor(std::min((B - 1), N) / B)));
}
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 P = pair<int, int>;
using ll = long long;

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

  long double ans = 0;
  rep(x, n + 1) { ans = max(ans, floor(a * x / b) - a * floor(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 P = pair<int, int>;
using ll = long long;

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

  long double ans = 0;
  if (n < b)
    ans = floor(a * n / b) - a * floor(n / b);
  else
    ans = floor(a * (b - 1) / b) - a * floor((b - 1) / b);

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

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

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

  bool flag = false;
  long long ans = 0;
  long long tmp;
  for (int x = 0; x <= N; x++) {
    if (A * x < B)
      continue;
    else if (x < B)
      tmp = (A * x) / B;
    else
      tmp = (A * x) / B - A * (x / B);
    if (tmp > ans) {
      ans = tmp;
      flag = true;
    }
    if (flag == true && tmp == 0)
      goto END;
  }
END:
  cout << ans << endl;
  return 0;
}


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

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

  long long x = min(B - 1, N);
  long long ans = (A * x) / B - A * (x / B);

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

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

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

int main() {
  using vi = vector<int>;

  long long a, b, n;
  cin >> a >> b >> n;
  long long x = 0;
  long long re = f(a, b, x);
  // int g = gcd(a,b);
  while (x <= n) {
    x += b;
    if (x > n) {
      x = n + 1;
    }
    long long y = f(a, b, x - 1);
    if (y > re) {
      re = y;
    }
  }
  cout << re << endl;
}

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()
#define _GLIBCXX_DEBUG

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

int main() {
  using vi = vector<int>;

  long long a, b, n;
  cin >> a >> b >> n;
  long long x = 0;
  long long re = f(a, b, x);
  // int g = gcd(a,b);
  x += b;
  if (x > n) {
    x = n + 1;
  }
  long long y = f(a, b, x - 1);
  if (y > re) {
    re = y;
  }
  cout << re << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin >>
#define Z class
#define ll long long
#define ln cout << '\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n", a)
#define mem(a) memset(a, 0, sizeof(a))
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++)
void pr() { ln; }
template <Z A, Z... B> void pr(const A &a, const B &...b) {
  cout << a << ' ';
  pr(b...);
}
template <Z A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  ln;
}
ll check(ll n, ll m, ll x, ll y) { return x >= 0 && x < n && y >= 0 && y < m; }
const ll MAX = 1e9 + 7, MAXL = 1LL << 61, dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1},
         dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
typedef pair<ll, ll> P;

void Main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  rep(i, 200000000) {
    ll x = n - i;
    if (x < 0)
      break;
    ll y = a * x / b - a * (x / b);
    ans = max(ans, y);
  }
  pr(ans);
}

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin >>
#define Z class
#define ll long long
#define ln cout << '\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n", a)
#define mem(a) memset(a, 0, sizeof(a))
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++)
void pr() { ln; }
template <Z A, Z... B> void pr(const A &a, const B &...b) {
  cout << a << ' ';
  pr(b...);
}
template <Z A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  ln;
}
ll check(ll n, ll m, ll x, ll y) { return x >= 0 && x < n && y >= 0 && y < m; }
const ll MAX = 1e9 + 7, MAXL = 1LL << 61, dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1},
         dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
typedef pair<ll, ll> P;

void Main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(n, b - 1);
  ll ans = a * x / b - a * (x / b);
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Main();
  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 = max(N, B-1);
  long long ans_max = -1;
  // cerr << (long long)((A * x) / B) << ", " << (A * (long long)(x / B)) <<
  // endl; long long ans = (long long)((A * x) / B) - (A * (long long)(x / B));
  // ans_max = max(ans, ans_max);

  for (long long x = 1; x <= B && x <= N; x++) {
    long long ans = (long long)((A * x) / B) - (A * (long long)(x / B));
    ans_max = max(ans, ans_max);
  }

  cout << ans_max << 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(B - 1, N);
  cout << (long long)(A * x / B) - A * (long long)(x / B) << endl;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int x = 1;
  int max = -1;
  double a, b, n;
  cin >> a >> b >> n;
  long long dif;
  for (int i = 1; i <= n; i++) {
    dif = floor(a * i / b) - a * floor(i / b);

    if (dif > max)
      max = dif;
  }
  cout << max;
  return 0;
}

Fixed submission:
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int x = 1;
  int max = -1;
  double a, b, n;
  cin >> a >> b >> n;
  long long dif;
  dif = b - 1;
  if (n < b - 1)
    dif = n;
  max = floor(a * dif / b) - a * floor(dif / b);
  cout << max;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  for (ll i = B - 1; i < N + 1; i += B) {
    ans = max(ans, A * i / B - A * (i / B));
    if (i > (B - 1) + B * 10000000)
      break;
  }
  ans = max(ans, (A * N) / B - A * (N / B));
  cout << ans << endl;
}
Problem p02696 (C++)

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

int main() {
  unsigned long long a, b, n;
  cin >> a >> b >> n;
  unsigned long long mx = 0;
  for (unsigned long long x = 1; x <= n; x++) {
    unsigned long long s =
        (unsigned long long)(a * x / b) - a * ((unsigned long long)(x / b));
    if (s > mx) {
      mx = s;
    }
  }
  cout << mx << endl;
  return 0;
}


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

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

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define file_name(a)                                                           \
  (freopen(((string)(a) + ".in").c_str(), "r", stdin),                         \
   freopen(((string)(a) + ".out").c_str(), "w", stdout))

int nxt() {
  int x;
  cin >> x;
  return x;
}

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

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define file_name(a)                                                           \
  (freopen(((string)(a) + ".in").c_str(), "r", stdin),                         \
   freopen(((string)(a) + ".out").c_str(), "w", stdout))

int nxt() {
  int x;
  cin >> x;
  return x;
}

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

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

void solve(long long A, long long B, long long N) {
  long long ans = 0;
  for (long long i = 1; i <= B - 1 && i <= N; i++) {
    ans = max(ans, (A * (i % B) - (A * i) % B) / B);
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long N;
  scanf("%lld", &N);
  solve(A, B, N);
  return 0;
}


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

void solve(long long A, long long B, long long N) {
  long long x = N < B ? N : B - 1;
  long long ans = floor((A * (x % B)) / B);
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long N;
  scanf("%lld", &N);
  solve(A, B, N);
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (long long i = 0; i < (n); i++)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll res = 0;
  if (b - 1 <= n)
    chmax(res, a * (b - 1) / b);
  for (ll i = n; (i > 0 && i % b != b - 1); i--) {
    chmax(res, (a * i) / b - a * (i / b));
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (long long i = 0; i < (n); i++)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll res = 0;
  if (b - 1 <= n)
    chmax(res, a * (b - 1) / b);
  chmax(res, a * n / b - a * (n / b));
  cout << res << 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, t, k, k1;
  cin >> a >> b >> n;
  if (b > n) {
    cout << (a * n) / b;
  } else {
    t = b - 1;
    k = ((a * t) / b) - (a * (t / b));
    while (1) {
      t++;
      if (t > n) {
        break;
      }
      k1 = ((a * t) / b) - (a * (t / b));
      if (k > k1) {
        break;
      } else if (k1 > k) {
        k = k1;
      }
    }
    cout << k;
  }
}


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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <math.h>
#include <memory>
#include <string>
#define Rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
void swap(int &a, int &b) {
  int temp = a;
  a = b;
  b = temp;
  return;
}
int ncr(int n, int r) {
  int a = 1;
  Rep(i, r) a = (a * (n - i)) / (i + 1);
  return a;
}
int npr(int n, int r) {
  int a = 1;
  Rep(i, r) a *= n - i;
  return a;
}
int mod(int a, int b) { return a % b; }

int main() {
  long double a, b, x, n;
  std::cin >> a >> b >> n;
  ll ans = 0;
  for (long double i = 0; i <= n; i++) {
    long double k = i / b;
    ll h = k;
    k = k - h;
    h = k * a;
    if (h > ans) {
      ans = h;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <math.h>
#include <memory>
#include <string>
#define Rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
void swap(int &a, int &b) {
  int temp = a;
  a = b;
  b = temp;
  return;
}
int ncr(int n, int r) {
  int a = 1;
  Rep(i, r) a = (a * (n - i)) / (i + 1);
  return a;
}
int npr(int n, int r) {
  int a = 1;
  Rep(i, r) a *= n - i;
  return a;
}
int mod(int a, int b) { return a % b; }

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

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

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

  int64_t max = 0;
  for (auto i = 0; i <= N; ++i) {
    auto score = (A * i / B) - A * (i / B);
    // std::cout << score << std::endl;

    if (max < score)
      max = score;
  }

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


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

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

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

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

using namespace std;

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long Y = 0;
  long long Ans = 0;
  for (int x = 0; x <= N; x++) {
    Y = floor(A * x / B) - A * floor(x / B);
    if (Ans < Y)
      Ans = Y;
  }

  cout << Ans << endl;

  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <limits>

using namespace std;

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long Y = 0;
  long long Ans = 0;
  if (N >= B)
    Ans = floor(A * (B - 1) / B) - A * floor((B - 1) / B);
  else if (N < B)
    Ans = floor(A * (N) / B) - A * floor(N / B);

  cout << Ans << endl;

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>#include <iostream>
#include <tuple>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i > b; i--)
#define vint vector<int>
#define vvint vector<vint>
#define CST(x) cout << fixed << setprecision(x) // 小数点以下の桁数指定
#define ct(a) cout << a << endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9 + 7;

ll A, B, N;
ll a[51], b[51], c[51], d[51];
ll ans = 0;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> A >> B >> N;

  FOR(i, 1, N + 1) {
    if (i % B == 0)
      break;
    ans = max(ans, (A * i) / B);
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>#include <iostream>
#include <tuple>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i > b; i--)
#define vint vector<int>
#define vvint vector<vint>
#define CST(x) cout << fixed << setprecision(x) // 小数点以下の桁数指定
#define ct(a) cout << a << endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9 + 7;

ll A, B, N;
ll a[51], b[51], c[51], d[51];
ll ans = 0;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> A >> B >> N;

  ll u = min(B - 1, N);
  cout << (A * u) / 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 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()
using namespace std;
typedef long long ll;
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  ll tmp;
  for (ll i = 0; i < N + 1; i++) {
    tmp = A * i / B - A * (i / B);
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Fixed submission:
#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()
using namespace std;
typedef long long ll;
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  ll tmp;
  tmp = min(B - 1, N);
  ans = A * tmp / B - A * (tmp / B);
  cout << ans << endl;
}