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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define endl '\n'
#define all(s) s.begin(), s.end()
#define lowbit(x) (x & -x)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define mem(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = -1;
  for (int i = 1; i <= n; i++) {
    ll now = a * i / b - i / b * a;
    if (now > ans)
      ans = now;
    else if (now < ans)
      break;
  }
  cout << ans;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define endl '\n'
#define all(s) s.begin(), s.end()
#define lowbit(x) (x & -x)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define mem(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = -1;
  //	for(int i=1;i<=n;i++){
  //		ll now=a*i/b-i/b*a;
  //		if(now>ans) ans=now;
  //		else if(now<ans)
  //	}
  ll pos = b - 1;
  if (n < pos)
    pos = n;
  ans = a * pos / b - pos / b * a;
  cout << ans;
}
Problem p02696 (C++)

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

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

  ll ans = 0;
  for (ll x = 0; x <= n; x++) {
    if (x % b == 0)
      continue;
    ll l = (a * x) / b;
    ll r = a * (x / b);
    ans = max(ans, l - r);
  }

  cout << ans << endl;
}

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(n, b - 1);
  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;

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

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

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

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

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

  ll ans = 0;
  rep(i, n + 1) { ans = max(ans, a * i / b - a * (i / b)); }
  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;

  double low = 0;
  // 右側
  double high = n + 1;

  auto f = [&](ll i) { return a * i / b - a * (i / b); };
  int cnt = 10000;
  while (--cnt) {
    double c1 = (low * 2 + high) / 3;
    double c2 = (low + high * 2) / 3;
    if (f(c1) <= f(c2))
      low = c1;
    else
      high = c2;
  }
  cout << fixed << setprecision(20) << f(low) << 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 FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll mx = 0;
  ll j = N;
  j -= B + 1;
  if (j < 0) {
    j = 1;
  }

  for (ll i = j; i <= N; i++) {
    if (A * i % B == 1 && i % B == B - 1) {
      cout << floor(A * i / B) - A * floor(i / B);
      return 0;
    }
    chmax(mx, (ll)(floor(A * i / B) - A * floor(i / B)));
  }

  cout << mx << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  cout << floor(A * x / B) - A * floor(x / B) << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL << 63 - 1)
#define endl '\n'
#define si size()
#define all(v) v.begin(), v.end()
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Matrix vector<vector<long long>>

using namespace std;

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

const long double Pi = acos(-1), e = 2.718;
const int N = 2e5 + 10, mod = 1e9 + 7;

int main() {
  FASTIO
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll st = max(0ll, (ll)(n - 2e8 + 5e7));
  for (ll i = st; i <= n; i++) {
    ans = max(ans, (a * i) / b - a * (i / b));
  }
  cout << ans << endl;
  return 0;
}
/**

*/


Fixed submission:
#include <bits/stdc++.h>
#include <limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL << 63 - 1)
#define endl '\n'
#define si size()
#define all(v) v.begin(), v.end()
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Matrix vector<vector<long long>>

using namespace std;

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

const long double Pi = acos(-1), e = 2.718;
const int N = 2e5 + 10, mod = 1e9 + 7;

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, B, N;
  cin >> A >> B >> N;
  // A*x/B - x/B の最大値は?
  // xが大きい方がよさそぅ
  if (B == 1)
    cout << 0 << endl;
  else if (B - 1 > N)
    cout << A * N / B - A * (N / B) << endl;
  else {
    ll ok = 0, ng = 1000000000001;
    ll m = (ok + ng) / 2;
    while (abs(ok - ng) > 1) {
      assert(m * B - 1 >= -1);
      if (m * B - 1 <= N)
        ok = m;
      else
        ng = m;
      m = (ok + ng) / 2;
    }
    ll x = ok * B - 1;
    cout << A * x / B - A * (x / B) << endl;
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, B, N;
  cin >> A >> B >> N;
  // A*x/B - x/B の最大値は?
  // xが大きい方がよさそぅ
  if (B == 1)
    cout << 0 << endl;
  else if (B - 1 > N)
    cout << A * N / B - A * (N / B) << endl;
  else {
    ll ok = (N + 1) / B;
    ll x = ok * B - 1;
    cout << A * x / B - A * (x / B) << endl;
  }
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
// https://atcoder.jp/contests/abc165/tasks/abc165_d
// 2020-05-02
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long ans = 0;
  if (N < B) {
    ans = ((A * N) / B) - A * (N / B);
  } else {
    long long tmp = B - 1;
    while (tmp <= N) {
      long long tmp = ((N / B) * B) - 1;
      ans = (A * tmp) / B - A * (tmp / B);
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
// https://atcoder.jp/contests/abc165/tasks/abc165_d
// 2020-05-02
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

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

ll A, B, N;

int main(void) {
  cin >> A >> B >> N;
  ll ans = 0;
  for (ll k = 0; k <= N; k++) {
    ll aa = (A * k) / B;
    ll ab = k / B;
    ll m = aa - A * ab;
    ans = max(ans, m);
  }
  cout << ans << endl;
}

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

ll A, B, N;

int main(void) {
  cin >> A >> B >> N;
  ll ans = 0;
  ll m = min(B - 1, N);
  ans = (A * m) / B - A * (m / B);
  cout << ans << endl;
}
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 < n; i++)
using P = pair<int, int>;
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const long long INF = 1LL << 60;
const int mod = 1000000007;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  for (int x = 0; x <= n; ++x) {
    ll X = a * x / b;
    ll Y = x / b * a;
    ans = max(ans, X - Y);
  }
  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 < n; i++)
using P = pair<int, int>;
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const long long INF = 1LL << 60;
const int mod = 1000000007;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = min((b - 1), n) * a / b - a * (min((b - 1), n) / b);
  cout << ans << endl;
}
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 ans = 0;

  long long k = 0;
  while (k * (b - 1) <= n) {
    long long x = k * (b - 1);
    ans = max(ans, (a * x / b) - a * (x / b));
    k++;
  }
  ans = max(ans, (a * n / b) - a * (n / b));
  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;

  long long ans = 0;

  //    long long k = 0;
  //    while(k*(b-1)<=n) {
  //        long long x = k*(b-1);
  //        ans = max(ans, (a*x/b)-a*(x/b));
  //        k++;
  //    }
  long long k = n / b;
  long long x = k * (b - 1);
  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):
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve() {
  LL A, B, N;
  cin >> A >> B >> N;
  LL ans = 0;
  LL AmB = A % B;
  for (int x = 1; x <= min(N, B - 1); x++) {
    ans = max(ans, (A * x - (x * AmB) % B) / B);
  }
  std::cout << ans << endl;
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  solve();
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve() {
  LL A, B, N;
  cin >> A >> B >> N;
  LL x = min(N, B - 1);
  LL ans = (A * x) / B - A * (x / B);

  std::cout << ans << endl;
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  solve();
  return 0;
}
Problem p02696 (Python)

Buggy submission (status: Time Limit Exceeded):
a, b, n = map(int, input().split())
ans = 0
# floor(a * x / b)
# = floor(a * floor(x / b) + a * (x / b - floor(x / b)))
# = a * floor(x / b) + floor(a * (x / b - floor(x / b))))
for i in range(min(b, n + 1)):
    ans = max(ans, int(a * i / b))
print(ans)


Fixed submission:
a, b, n = map(int, input().split())
ans = 0
# floor(a * x / b)
# = floor(a * floor(x / b) + a * (x / b - floor(x / b)))
# = a * floor(x / b) + floor(a * (x / b - floor(x / b))))
print(int(a * min(b - 1, n) / b))
Problem p02696 (Python)

Buggy submission (status: Time Limit Exceeded):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    a, b, n = map(int, input().split())

    ans = 0

    for x in range(min(b, n + 1)):
        ans = max(int(a * x / b) - a * int(x / b), ans)

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Fixed submission:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    a, b, n = map(int, input().split())

    ans = 0

    x = min(b - 1, n)
    ans = max(int(a * x / b) - a * int(x / b), ans)

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Problem p02696 (Python)

Buggy submission (status: Runtime Error):
def m():
    a, b, n = map(int, input().split())

    def calc(x):
        return int((a * x) / b) - (a * int(x / b))

    if calc(1) < calc(n // 2):
        return max([calc(i) for i in range(n // 2, n + 1)])
    else:
        return max([calc(i) for i in range(1, n // 2 + 1)])


print(m())


Fixed submission:
def m():
    a, b, n = map(int, input().split())

    def calc(x):
        return int((a * x) / b) - (a * int(x / b))

    return calc(min(n, b - 1))


print(m())
Problem p02696 (Python)

Buggy submission (status: Time Limit Exceeded):
def main():
    a, b, n = [int(x) for x in input().split()]
    gen = (a * x // b - x // b * a for x in range(min(b, n) + 1))
    return max(gen)


if __name__ == "__main__":
    print(main())


Fixed submission:
def main():
    a, b, n = [int(x) for x in input().split()]
    # gen = (a * x // b - x // b * a for x in range(min(b, n) + 1))

    if n >= b - 1:
        x = b - 1
    else:
        x = n

    return a * x // b - x // b * a


if __name__ == "__main__":
    print(main())
Problem p02696 (Python)

Buggy submission (status: Time Limit Exceeded):
A, B, N = map(int, input().split())

ans = 0

for i in range(1, N + 1):
    tmp = (A * i) // B - A * (i // B)
    ans = max(ans, tmp)

print(ans)


Fixed submission:
A, B, N = map(int, input().split())

x = min(B - 1, N)
ans = (A * x) // B - A * (x // B)
print(ans)
Problem p02696 (Python)

Buggy submission (status: Time Limit Exceeded):
#


def main():
    a, b, n = map(int, input().split(" "))
    fac = 0
    for i in range(n + 1):
        j = i // b
        if j == 0:
            if fac < i:
                fac = i
        else:
            break
    ans = a * fac // b - a * (fac // b)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
#


def main():
    a, b, n = map(int, input().split(" "))
    fac = 0
    start = min(b, n)
    if b <= n:
        fac = start - 1
    else:
        fac = start
    ans = a * fac // b - a * (fac // b)
    print(ans)


if __name__ == "__main__":
    main()
Problem p02696 (Python)

Buggy submission (status: Runtime Error):
a, b, n = map(int, input().split())

x = min(b.n)
print(int(a * x / b))


Fixed submission:
a, b, n = map(int, input().split())

x = min(b - 1, n)
ans = int(a * x / b)

# if a == 1 or b == 1 or b == n:
#    print(0)
# else:
print(ans)
Problem p02696 (Python)

Buggy submission (status: Time Limit Exceeded):
def f(x):
    return (a * x) // b - a * (x // b)


a, b, n = map(int, input().split())

k = (n + 1) // b

ans = 0
for x in range(max(0, k * b - 1), n + 1):
    ans = max(ans, f(x))

print(ans)


Fixed submission:
def f(x):
    return (a * x) // b - a * (x // b)


a, b, n = map(int, input().split())

k = (n + 1) // b

x = max(k * b - 1, 0)
ans = f(x)
ans = max(ans, f(n))
print(ans)
Problem p02696 (Python)

Buggy submission (status: Time Limit Exceeded):
import math

A, B, N = map(int, input().split(" "))
ans = 0
for x in range(min(B, N + 1)):
    res = math.floor((A * x) / B) - A * (math.floor(x / B))
    ans = max(res, ans)
print(int(ans))


Fixed submission:
import math

A, B, N = map(int, input().split(" "))
ans = 0
x = min(B, N + 1) - 1
ans = math.floor((A * x) / B) - A * (math.floor(x / B))
print(int(ans))
Problem p02696 (Python)

Buggy submission (status: Time Limit Exceeded):
a, b, n = map(int, input().split())

ans = 0
if b > n:
    x = n
    ans = int(a * x // b) - int(a * (x // b))
else:
    m = 0
    for i in range(b):
        if int(a * (n - i) // b) - int(a * ((n - i) // b)) > m:
            m = int(a * (n - i) // b) - int(a * ((n - i) // b))
    ans = m
print(ans)


Fixed submission:
a, b, n = map(int, input().split())

ans = 0
if b > n:
    x = n
    ans = int(a * x // b) - int(a * (x // b))
else:
    x = n
    ans1 = int(a * x // b) - int(a * (x // b))
    x = (n // b) * b - 1
    ans2 = int(a * x // b) - int(a * (x // b))
    ans = max(ans1, ans2)
print(ans)
Problem p02696 (Python)

Buggy submission (status: Runtime Error):
from math import floor

A, B, N = list(map(int, input().split()))
# print(A, B, N)

x = None
if N < B:
    x = N

answer = floor(A * x / B) - A * floor(x / B)

print(answer)


Fixed submission:
from math import floor

A, B, N = list(map(int, input().split()))
# print(A, B, N)

x = None
if N < B:
    x = N
else:
    x = B
    x = B - 1
    # max_diff = 0
    # for _x in range(B, N + 1):
    #     diff = (x / B) - floor(x / B)
    #     if max_diff <= diff:
    #         max_diff = diff
    #         x = _x

answer = floor(A * x / B) - A * floor(x / B)

print(answer)
Problem p02696 (C++)

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, n, i, m = 0, d;
  cin >> a >> b >> n;
  m = min(b - 1, n);
  d = (a * m) / b - (a * (m / b));
  cout << d << endl;
}
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 max = 0;
  for (int i = 1; i < b && i <= n; i++) {
    long k = a * i / b;
    if (max < k)
      max = k;
  }

  cout << max << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long i = min(b - 1, n);
  long long max = a * i / b;

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

using namespace std;
using ll = long long;

int main() {

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

  ll max = 0;
  if (b < n) {
    repi(x, 1, b) {

      ll t = ((a * x) / b) - (a * (x / b));
      if (t > max) {
        max = t;
      }
    }
  } else {
    repi(x, 1, n) {

      ll t = ((a * x) / b) - (a * (x / b));
      if (t > max) {
        max = t;
      }
    }
  }

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


Fixed submission:
#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

using namespace std;
using ll = long long;

int main() {

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

  ll max = 0;
  ll x = (n >= b) ? b - 1 : n;
  max = ((a * x) / b) - a * (x / b);
  //     repi(x,1,b-1){
  // //        if((a*x)%b != 0) continue;
  //         ll t =((a * x)/b) - (a * (x/b));
  //         printf("t:%d\n",t);
  //         if(t > max){
  //             max = t;
  //         }
  //     }

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

Buggy submission (status: Time Limit Exceeded):
// #include <bits/stdc++.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
ll a, b, n, ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> n;
  for (ll i = 1; i <= n; i++) {
    ll cur = a * i / b - a * (i / b);
    //        cout<<i<<" "<<cur<<endl;
    if (cur < ans)
      break;
    ans = max(ans, cur);
  }
  cout << ans;
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */


Fixed submission:
// #include <bits/stdc++.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
ll a, b, n, ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> n;
  ll x = min(b - 1, n);
  ans = a * x / b - a * (x / b);
  cout << ans;
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */
Problem p02696 (C++)

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

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

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

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

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

long long int a;
long long int b;
long long int n;
using namespace std;

int main() {
  cin >> a;
  cin >> b;
  cin >> n;
  long long int m = 0;
  for (long long int x = 0; x <= n; x++) {
    long long int t = ((a * x) / b) - a * (x / b);
    if (t > m) {
      m = t;
    }
  }
  cout << m;
}

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

long long int a;
long long int b;
long long int n;
using namespace std;

int main() {
  cin >> a;
  cin >> b;
  cin >> n;
  long long int m = 0;
  /*
  for(long long int x=0;x<=n;x++){
      long long int t=((a*x)/b)-a*(x/b);
      if(t>m){
          m=t;
      }
  }*/
  if (b <= n) {
    long long int x = b - 1;
    cout << ((a * x) / b) - a * (x / b);
  } else {
    long long int x = n;
    cout << ((a * x) / b) - a * (x / b);
    /*
    for (long long int i = 0; x < n; i++)
    {
        x = b * n - 1;
        if (x > n)
        {
            break;
        }
        long long int t = ((a * x) / b) - a * (x / b);
        if (t > m)
        {
            m = t;
        }
    }*/
  }
  return 0;
  long long int x = 0;
  for (long long int i = 0; x < n; i++) {
    x = b * n - 1;
    if (x > n) {
      break;
    }
    long long int t = ((a * x) / b) - a * (x / b);
    if (t > m) {
      m = t;
    }
  }
  cout << m;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                                                                \
  if (dbg) {                                                                   \
    cout << #x << " = " << (x) << endl;                                        \
  }
bool dbg = false;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve() {}
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  int memo = 0;
  ll i = b - 1;
  if (n <= 100000000) {
    for (int i = 1; i <= n; i++) {
      memo = max(memo, int(floor(a * i / b) - a * floor(i / b)));
    }
  } else if (n < b) {
    memo = max(memo, int(floor(a * n / b) - a * floor(n / b)));
  } else {
    while (n >= i) {
      memo = max(memo, int(floor(a * i / b) - a * floor(i / b)));
      i += b;
    }
  }
  cout << memo << endl;
  solve();
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                                                                \
  if (dbg) {                                                                   \
    cout << #x << " = " << (x) << endl;                                        \
  }
bool dbg = false;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

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

Buggy submission (status: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    A, B, N = map(int, input().split())

    def func(x):
        res = (A * x) // B - A * (x // B)
        return res

    M = 0
    for i in range(N, max(0, N - 10**7), -1):
        tmp = func(i)
        if tmp > M:
            M = tmp

    print(M)


if __name__ == "__main__":
    main()


Fixed submission:
import sys


sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    A, B, N = map(int, input().split())

    def func(x):
        res = (A * x) // B - A * (x // B)
        return res

    print(func(min(N, B - 1)))


if __name__ == "__main__":
    main()
Problem p02696 (C++)

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

long long a, b, n;

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


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

long long a, b, n;

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define ll long long
using namespace std;

ll i, j, k;
const ll MOD = 1000000000 + 7;

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll term = b / gcd(a, b);
  vector<ll> A;
  if (n < term) {
    REP(i, n) {
      ll tmp = (i + 1) * a / b - a * ((i + 1) / b);
      A.push_back(tmp);
    }
    ans = *max_element(A.begin(), A.end());

  } else {
    REP(i, term) {
      ll tmp = (i + 1) * a / b - a * ((i + 1) / b);
      A.push_back(tmp);
    }
    if (A[0] < A.back()) {
      ans = *max_element(A.begin(), A.end()) * (n / term) +
            *max_element(A.begin(), A.begin() + n % term);
    } else {
      ans = *max_element(A.begin(), A.end());
    }
  }
  cout << ans << '\n';

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define ll long long
using namespace std;

ll i, j, k;
const ll MOD = 1000000000 + 7;

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

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

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

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;

void Main() {
  // input
  u_int64_t A, B, N;
  cin >> A >> B >> N;

  // translate
  u_int64_t ans = 0;
  if (N < B) {
    cout << (A * N) / B << endl;
    return;
  }

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

  // output
  cout << ans << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;

void Main() {
  // input
  u_int64_t A, B, N;
  cin >> A >> B >> N;

  // translate
  u_int64_t ans = 0;
  if (B == 1) {
    cout << 0 << endl;
    return;
  }

  if (N < B) {
    cout << (A * N) / B << endl;
    return;
  }

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

  // output
  cout << ans << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  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 max = 0;
  for (long long x = 1; x <= n; x++) {
    long long v = ((a * x) / b) - (a * (x / b));
    if (v > max) {
      max = v;
    }
  }

  cout << max;

  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 = n < b - 1 ? n : b - 1;
  cout << (a * x) / b - a * (x / b);

  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 REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)

using ll = long long;

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

  int maxv = 0;
  if (n <= b) {
    long long int A, B;
    for (int i = 1; i <= n; i++) {
      A = int(a * i / b);
      B = int(i / b);
      maxv = max(maxv, int(A - B * a));
    }
    cout << maxv << endl;
  } else {
    double A, B;
    long long int i = b - 1;
    A = double(a * i / b);
    B = double(i / b);
    maxv = max(maxv, int(floor(A) - floor(B) * a));

    cout << maxv << endl;
  }
}

/*
floor は x=nb+m とおくとnによらずmのみで決定する
またmが大きい時差が最大になる
*/

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

using ll = long long;

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

  int maxv = 0;
  if (n < b) {
    // n<=bってことは[x/b]=0こていなのでAxがクソでかいほうがいいのでは？
    /*long long int A,B;
    for(int i=1;i<=n;i++){
      A = int(a*i/b);
      B = int(i/b);
      maxv = max(maxv, int(A-B*a) );
    }*/
    double A;
    A = double(a * n / b);
    maxv = floor(A);
    cout << maxv << endl;
  } else {
    double A, B;
    long long int i = b - 1;
    A = double(a * i / b);
    B = double(i / b);
    maxv = max(maxv, int(floor(A) - floor(B) * a));

    cout << maxv << endl;
  }
}

/*
floor は x=nb+m とおくとnによらずmのみで決定する
またmが大きい時差が最大になる
*/
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 = 1; i <= n; ++i) {
    ans = max(ans, ll(floor(a * i / b) - a * floor(i / b)));
  }
  cout << ans << endl;
  return 0;
}


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

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;

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

  ll a, b, n;
  cin >> a >> b >> n;
  ll res = ((a * n) / b) - a * (n / b);
  if (b > 1e6) {
    for (ll k = 0; k * b - 1 <= n; ++k) {
      ll x = k * b - 1;
      res = max(res, ((a * x) / b) - a * (x / b));
    }
  } else {
    for (ll x = 0; x <= n; ++x) {
      res = max(res, ((a * x) / b) - a * (x / b));
    }
  }
  cout << res << "\n";

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;

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

  ll a, b, n;
  cin >> a >> b >> n;
  ll res = ((a * n) / b) - a * (n / b);
  if (b > 1e6) {
    for (ll k = 0; k * b - 1 <= n; ++k) {
      ll x = k * b - 1;
      res = max(res, ((a * x) / b) - a * (x / b));
    }
  } else {
    for (ll x = 0; x <= min(n, 3 * b); ++x) {
      res = max(res, ((a * x) / b) - a * (x / b));
    }
  }
  cout << res << "\n";

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define _Max(a, b, c) Max(a, Max(b, c))
#define lop(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using namespace std;
/*
 *
 * Saroar Zahan Sojib
 * Green University - Bangladesh (GUB)
 *
 */
int main() {
  set<long long> vec;
  long long a, b, n, i, k;
  cin >> a >> b >> n;
  k = sqrt(n);
  for (i = k; i <= n; i++) {
    long long e, f, g;
    e = floor((a * i) / b);
    f = floor(i / b);
    g = e - (a * f);
    vec.insert(g);
  }
  long long max = 0;
  for (auto x : vec) {
    if (max < x) {
      max = x;
    }
  }
  cout << max << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define _Max(a, b, c) Max(a, Max(b, c))
#define lop(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using namespace std;
/*
 *
 * Saroar Zahan Sojib
 * Green University - Bangladesh (GUB)
 *
 */
int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long x = min(B - 1, N);
  cout << (A * x) / B - A * (x / B) << endl;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  double a, b, n;
  cin >> a >> b >> n;
  double max1 = INT_MIN;
  for (double i = n; i >= 0; i--) {
    max1 = max(max1, (ll)(floor((a * i) / b)) - a * floor(i / b));
  }
  cout << max1;
}
int main() {
  fast();
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  double a, b, n;
  cin >> a >> b >> n;
  ll max1 = min(b - 1, n);
  // for(double i=n;i>=0;i--){
  ll m1 = (ll)(floor((a * (max1)) / b)) - a * floor((max1) / b);
  //}
  cout << m1;
}
int main() {
  fast();
  solve();
  return 0;
}
Problem p02696 (C++)

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

long long mmax(long long a, long long b) {
  if (a > b)
    return a;
  return b;
}

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

  if (n < b)
    cout << a * n / b << endl;
  else {
    long long x, maxn = 0;
    for (x = b - 1ll; x <= n; x += b)
      maxn = mmax(maxn, a * x / b - a * (x / b));
    cout << maxn << endl;
  }
  return 0;
}

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

long long mmax(long long a, long long b) {
  if (a > b)
    return a;
  return b;
}

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

  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }

  if (n < b)
    cout << a * n / b << endl;
  else {
    long long x, maxn = 0;
    for (x = b - 1ll; x <= n; x += b)
      maxn = mmax(maxn, a * x / b - a * (x / b));
    cout << maxn << 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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

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

  ll ans = -INF;
  for (ll x = b - 1; x <= n; x += b) {
    ll res1 = a * x / b;
    ll res2 = x / b * a;
    chmax(ans, res1 - res2);
  }
  ll x = n;
  ll res1 = a * x / b;
  ll res2 = x / b * a;
  chmax(ans, res1 - res2);
  cout << ans << '\n';

  return 0;
}

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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

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

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

  return 0;
}
Problem p02696 (C++)

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x)                                                            \
  Sort(x);                                                                     \
  reverse(ALL(x))

template <typename V, typename T> T find_num(V v, T num) {
  if (find(ALL(v), num) == v.end()) {
    return false;
  } else {
    return true;
  }
}

// π M_PI
// deg = rad*180/M_PI

ll num(ll a, ll b, ll i) {
  ll ans = (int)(a * i / b) - a * (int)(i / b);
  // cout << "a " << ans << endl;
  return ans;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (n < b) {
    std::vector<ll> v;
    /*
    rep2(i, n) {
        v.push_back( num(a, b, i) );
    }
    ans = *max_element(ALL(v));*/
    ans = num(a, b, n);
  } else {
    ll nn = b;
    ll i = 2;
    // std::vector<ll> v;
    priority_queue<ll> q;
    while (nn <= n) {
      // v.push_back( num(a, b, nn-1) );
      // v.push_back( num(a, b, nn) );
      ll k = num(a, b, nn - 1); /*
         if ( !q.empty() && k < q.top() ) {
             break;
         }*/
      q.push(num(a, b, nn - 1));
      q.push(num(a, b, nn));
      nn = b * i;
      i++;
    }
    ans = q.top();
  }

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


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x)                                                            \
  Sort(x);                                                                     \
  reverse(ALL(x))

template <typename V, typename T> T find_num(V v, T num) {
  if (find(ALL(v), num) == v.end()) {
    return false;
  } else {
    return true;
  }
}

// π M_PI
// deg = rad*180/M_PI

ll num(ll a, ll b, ll i) {
  ll ans = (int)(a * i / b) - a * (int)(i / b);
  // cout << "a " << ans << endl;
  return ans;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (n < b) {
    std::vector<ll> v;
    /*
    rep2(i, n) {
        v.push_back( num(a, b, i) );
    }
    ans = *max_element(ALL(v));*/
    ans = num(a, b, n);
  } else {
    ll nn = b;
    ll i = 2;
    // std::vector<ll> v;
    priority_queue<ll> q;
    while (nn <= n) {
      // v.push_back( num(a, b, nn-1) );
      // v.push_back( num(a, b, nn) );
      ll k = num(a, b, nn - 1);
      if (!q.empty() && k < q.top()) {
        break;
      }
      q.push(num(a, b, nn - 1));
      q.push(num(a, b, nn));
      nn = b * i;
      i++;
    }
    ans = q.top();
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
using namespace std;

int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  int64_t m = 0;
  rep(i, n / 2, n + 1) { m = max(m, ((a * i / b) - a * (i / b))); }
  cout << m << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
using namespace std;

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
// 型に気を付けよう

#define rep(i, n) for (i = 1; i < n; i++)
typedef long long ll;
typedef long double ld;
const double pi = 3.1415926535;
const ll mod = 1000000007;
// 桁数指定　cout << fixed << setprecision(2)
int main() {
  ld ans = 0;
  ld a, b, n;
  cin >> a >> b >> n;
  int x = 1;
  rep(x, min(b, n + 1)) {
    ld sum = floorl(a * x / b) - a * floorl(x / b);
    ans = max(ans, sum);
    // cerr<<x<<sum<<endl;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// 型に気を付けよう

#define rep(i, n) for (i = 1; i < n; i++)
typedef long long ll;
typedef long double ld;
const double pi = 3.1415926535;
const ll mod = 1000000007;
// 桁数指定　cout << fixed << setprecision(2)
int main() {
  ld ans = 0;
  ld a, b, n;
  cin >> a >> b >> n;
  ll x = min(b - 1, n);
  ld sum = floorl(a * x / b) - a * floorl(x / b);
  ans = max(ans, sum);
  cerr << x << sum << endl;

  cout << ans;
}