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

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

using namespace std;

int main() {
  long a, b, n;
  cin >> a >> b >> n;
  long ans = a / b - a * (1 / b);

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

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

using namespace std;

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a)                                                               \
  rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  rp(i, 0, min(n, b) + 1) { ans = max(ans, ll(a * i / b) - a * ll(i / b)); }
  ce(ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a)                                                               \
  rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (n >= b - 1) {
    ce(ll(a * (b - 1) / b) - a * ll((b - 1) / b));
  } else {
    ce(ll(a * (n) / b) - a * ll((n) / b));
  }
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
using namespace std;
typedef long long ll;

ll A, B, N;

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

  ll ans = 0;
  rep(i, max(N + 1, (ll)1000000)) {
    ans = max(ans, (A * (N - i)) / B - A * ((N - i) / B));
  }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
using namespace std;
typedef long long ll;

ll A, B, N;

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

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

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

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long a, b, n;
long long ans;
int main() {
  cin >> a >> b >> n;
  if (n < b) {
    cout << max(ans, a * n / b - a * (n / b));
  } else {
    if (a * b > n) {
      for (long long i = b - 1; i <= n; i += b) {
        long long tot = a * i / b - a * (i / b);
        if (tot > ans) {
          ans = tot;
        }
      }
    } else {
      for (long long i = 1; i <= a; i++) {
        long long tot = a * (i * b - 1) / b - a * (i - 1);
        if (tot > ans) {
          ans = tot;
        }
      }
    }
    cout << ans;
  }
  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 counter = 0;
  counter = ((A * N) / B) - A * (N / B);
  long long i = N;
  for (i; i > 0; i--) {
    if (i % B == 0) {
      i--;
      break;
    } else
      continue;
  }
  counter = max(counter, ((A * i) / B) - A * (i / B));
  cout << counter << 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 counter = 0;
  counter = ((A * N) / B) - A * (N / B);
  long long i = N - (N % B) - 1;
  counter = max(counter, ((A * i) / B) - A * (i / B));
  cout << counter << endl;

  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset>        // bitset
#include <cmath>         // sqrt
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  ll x = N;
  for (ll x = N % B; x < N + 1; x++) {
    long double a = A * x / B;
    ll aa = a;
    long double b = x / B;
    ll bb = b * A;
    ans = max(ans, aa - bb);
    // cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset>        // bitset
#include <cmath>         // sqrt
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  ll x = min(B - 1, N);
  ll tmp = floor(A * x / B) - A * floor(x / B);

  ans = max(ans, tmp);

  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, X = 0, T;

  cin >> A >> B >> N;

  for (long long I = 0; I <= N; I++) {
    T = floor((A * I) / B) - (A * floor(I / B));
    X = max(X, T);
  }
  cout << X << endl;
}


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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a;
  long long b, n;
  cin >> a >> b >> n;
  long long mn = min(n, b - 1);
  cout << a * mn / b << '\n';
  return 0;
}
Problem p02696 (C++)

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

using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int A, B, N, i, j, ans = 0;
  cin >> A >> B >> N;
  if (N >= B - 1) {
    for (i = B - 1; i <= N; i += B)
      ans = (ans, A * i / B - A * (i / B));
  } else
    ans = (A * N / B - A * (N / B));
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int A, B, N, i, j, ans = 0;
  cin >> A >> B >> N;
  ans = (N >= B - 1) ? A * (B - 1) / B - A * ((B - 1) / B)
                     : (A * N / B - A * (N / B));
  cout << ans << '\n';
  return 0;
}
Problem p02696 (C++)

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

using namespace std;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a)                                                               \
  { std::cout << #a << " = " << a << "\n"; }
template <class T1, class T2> inline bool minimize(T1 &a, T2 b) {
  return b < a && (a = b, 1);
}
template <class T1, class T2> inline bool maximize(T1 &a, T2 b) {
  return a < b && (a = b, 1);
}
template <class T, class V> istream &operator>>(istream &ist, pair<T, V> &p) {
  return ist >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &ost, pair<T, T> &p) {
  return ost << p.first << ", " << p.second;
}
template <class T> istream &operator>>(istream &ist, vector<T> &vs) {
  for (auto &e : vs)
    ist >> e;
  return ist;
}

typedef long long ll;
int const inf = INT_MAX / 2;

ll f(ll A, ll B, ll x) { return A * x / B - A * (x / B); }

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  cout << f(A, B - 1, N) << "\n";
}


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

using namespace std;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a)                                                               \
  { std::cout << #a << " = " << a << "\n"; }
template <class T1, class T2> inline bool minimize(T1 &a, T2 b) {
  return b < a && (a = b, 1);
}
template <class T1, class T2> inline bool maximize(T1 &a, T2 b) {
  return a < b && (a = b, 1);
}
template <class T, class V> istream &operator>>(istream &ist, pair<T, V> &p) {
  return ist >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &ost, pair<T, T> &p) {
  return ost << p.first << ", " << p.second;
}
template <class T> istream &operator>>(istream &ist, vector<T> &vs) {
  for (auto &e : vs)
    ist >> e;
  return ist;
}

typedef long long ll;
int const inf = INT_MAX / 2;

ll f(ll A, ll B, ll x) { return A * x / B - A * (x / B); }

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  cout << f(A, B, min(B - 1, N)) << "\n";
}
Problem p02696 (C++)

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()

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

using namespace std;

ll temp(ll a, ll b, ll x) {
  ll axb = (long double)(a * x) / (long double)b;
  ll bx = (long double)x / (long double)b;
  // cout << axb << " " << a * bx << endl;
  return axb - a * bx;
}

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

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

  ll ans = 0;
  ll x = n;
  for (ll i = n; i >= 0; i--) {
    ans = max(temp(a, b, i), ans);
  }

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

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()

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

using namespace std;

ll temp(ll a, ll b, ll x) {
  ll axb = (long double)(a * x) / (long double)b;
  ll bx = (long double)x / (long double)b;
  // cout << axb << " " << a * bx << endl;
  return axb - a * bx;
}

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

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

  ll x = n > b - 1 ? b - 1 : n;
  ll ans = temp(a, b, x);

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll a, b, n;

int main(void) {
  scanf("%lld%lld%lld", &a, &b, &n);
  ll ans = a * (n) / b - a * ((n) / b);
  for (ll i = b - 1; i <= n; i += b) {
    ans = max(ans, a * i / b - a * (i / b));
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll a, b, n;

int main(void) {
  scanf("%lld%lld%lld", &a, &b, &n);
  ll ans = a * (n) / b - a * ((n) / b);
  for (ll i = b - 1; i <= min(n, a * b); i += b) {
    ans = max(ans, a * i / b - a * (i / b));
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void) {
  ll A, B, N, b;
  cin >> A >> B >> N;
  if (B > N)
    b = N;
  else
    b = B - 1;
  ll max_x = 0;
  for (ll i = 0; i < B; i++)
    max_x = max(max_x, A * (b - i) / B - A * ((b - i) / B));
  cout << max_x << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void) {
  ll A, B, N, b;
  cin >> A >> B >> N;
  if (B > N)
    b = N;
  else
    b = B - 1;
  ll max_x = 0;
  for (ll i = 0; i < 100000; i++)
    max_x = max(max_x, A * (b - i) / B - A * ((b - i) / B));
  cout << max_x << endl;
  return 0;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int binary(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}
long comb(int n, int r) {
  long ans = 1;
  for (int i = n; i > n - r; --i) {
    ans = ans * i;
  }
  for (int i = 1; i < r + 1; ++i) {
    ans = ans / i;
  }
  return ans;
}
using namespace std;
/*int main(){
    int n;std::cin >> n;
    int keta=0;
    while(true){
        keta++;
        if(n/10==0)break;
        n=n/10;
    }
    keta=keta-1;
    if(n>=7)n=3;
    else if(n>=5)n=2;
    else if(n>=3)n=1;
    int k=0;
    for(int i=3;i<=keta;i++){
        k+=comb(i-1,2);
        std::cout << k << std::endl;
    }std::cout << k << std::endl;
    k+=n*(keta);

    std::cout << k << std::endl;

}


*/

int main() {
  unsigned long long a, b, n;
  int s = 0;
  std::cin >> a >> b >> n;
  int w;
  for (int i = 1; i < n + 1; i++) {
    w = (((a * i) / b) - a * (i / b));
    s = max(s, w);
  }
  std::cout << s << std::endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int binary(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}
long comb(int n, int r) {
  long ans = 1;
  for (int i = n; i > n - r; --i) {
    ans = ans * i;
  }
  for (int i = 1; i < r + 1; ++i) {
    ans = ans / i;
  }
  return ans;
}
using namespace std;
/*int main(){
    int n;std::cin >> n;
    int keta=0;
    while(true){
        keta++;
        if(n/10==0)break;
        n=n/10;
    }
    keta=keta-1;
    if(n>=7)n=3;
    else if(n>=5)n=2;
    else if(n>=3)n=1;
    int k=0;
    for(int i=3;i<=keta;i++){
        k+=comb(i-1,2);
        std::cout << k << std::endl;
    }std::cout << k << std::endl;
    k+=n*(keta);

    std::cout << k << std::endl;

}


*/

int main() {
  unsigned long long a, b, n;
  int s = 0;
  std::cin >> a >> b >> n;

  std::cout << a * min((b - 1), n) / b << std::endl;
  return 0;
}
Problem p02696 (C++)

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

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


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

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

  ll s = min(b - 1, n);
  ll ans = floor(a * s / b) - a * floor(s / b);
  cout << ans << endl;
}
Problem p02696 (C++)

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

int main() {
  int A;
  long long B, N;
  long long ans;
  std::cin >> A >> B >> N;
  ans = (A * N) / B - (N / B) * A;
  for (long long x = B - 1; x <= N; x += B) {
    long long buf = (A * x) / B - (x / B) * A;
    if (ans < buf) {
      ans = buf;
    }
  }
  std::cout << ans;
}

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

int main() {
  int A;
  long long B, N;
  long long ans;
  std::cin >> A >> B >> N;
  ans = (A * N) / B - (N / B) * A;
  // for(long long x=B-1;x<=N;x+=B){
  //     long long buf=(A*x)/B-(x/B)*A;
  //     if(ans<buf){
  //         ans=buf;
  //     }
  // }
  long long buf = ((N / B) - 1) * B + B - 1;
  buf = (A * buf) / B - (buf / B) * A;
  if (ans < buf) {
    ans = buf;
  }
  std::cout << ans;
}
Problem p02696 (C++)

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

using namespace std;

int main() {
  int64_t A, B, N;
  cin >> A >> B >> N;
  // vector<vector<int>> input(q, vector<int>(4));

  int64_t loop = N / B + 1;
  int64_t x, ans, tmp;
  ans = 0;

  for (int i = 1; i <= loop; i++) {
    if ((i * B - 1) < N)
      x = i * B - 1;
    else
      x = N;
    tmp = floor(A * x / B) - A * floor(x / B);
    if (tmp > ans)
      ans = tmp;
  }

  cout << ans << endl;
}


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

using namespace std;

int main() {
  int64_t A, B, N;
  cin >> A >> B >> N;
  // vector<vector<int>> input(q, vector<int>(4));

  int64_t loop = N / B + 1;
  int64_t x, ans, tmp;
  ans = 0;

  if (B == 1) {
    ans = 0;
  } else {
    for (int i = 1; i <= loop; i++) {
      if ((i * B - 1) < N)
        x = i * B - 1;
      else
        x = N;
      tmp = floor(A * x / B) - A * floor(x / B);
      if (tmp > ans)
        ans = tmp;
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(), v.end()
#define mem(v, x) memset(v, x, sizeof(v))
#define N 100005

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll val = 0;
  ll temp = b - 1;
  while (1) {
    if (temp > n)
      break;
    ll nval = a * temp / b - (temp / b) * a;
    if (nval < val)
      break;
    val = max(val, nval);
    temp += b;
  }
  ll nval = a * n / b - (n / b) * a;
  val = max(val, nval);
  cout << val;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(), v.end()
#define mem(v, x) memset(v, x, sizeof(v))
#define N 100005

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll val = 0;
  if (n >= b - 1)
    val = a * (b - 1) / b;
  ll nval = a * n / b - (n / b) * a;
  val = max(val, nval);
  cout << val;
}
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;
  long long x = n, res = 0, lim = b / a;
  while (x > lim)
    res = max(res, a * x / b - a * (x / b)), --x;
  cout << res << 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 res;
  if (n / b == 0)
    res = a * n / b - a * (n / b);
  else
    res = a * (n / b * b - 1) / b - a * ((n / b * b - 1) / 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;
  cin >> A >> B >> N;

  long long int x = min(B - 1, N);

  long long int ans = 0;

  while (true) {
    long long int tmp_ans = A * x / B - x / B * A;
    if (tmp_ans > ans) {
      ans = tmp_ans;
    }
    if (x == N) {
      break;
    }
    x = min(x + B, N);
  }

  cout << ans << endl;
}

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

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

  long long int x = min(B - 1, N);

  long long int ans = A * x / B - x / B * A;

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

Buggy submission (status: Runtime Error):
#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 ans1 = a * n / b - a * (n / b);
  int64_t ans2 = 0;
  int x = b - 1;
  if (n >= b - 1)
    ans2 = a / (b - 1);
  cout << max(ans1, ans2) << 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 ans1 = a * n / b - a * (n / b);
  int64_t ans2 = 0;
  if (b != 1) {
    if (n >= b - 1)
      ans2 = a * (b - 1) / b;
  }
  cout << max(ans1, ans2) << endl;
}
Problem p02696 (C++)

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

int64_t sol(int64_t a, int64_t b, int64_t n) {
  int64_t before = -1, cur = 0, i = 1;
  for (i = 1; i <= min((int64_t)5e8, n); ++i) {
    cur = floor((double)a * i / b) - a * floor((double)i / b);
    if (before > cur) {
      break;
    }
    before = cur;
  }
  return before;
}

int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  cout << sol(a, b, n);
  return 0;
}

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

int64_t sol(int64_t a, int64_t b, int64_t n) {
  int64_t i = min(n, b - 1);
  return floor((double)a * i / b) - a * floor((double)i / b);
}

int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  cout << sol(a, b, n);
  return 0;
}
Problem p02696 (C++)

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  int ans = -2e9;
  int r = n - b;
  for (ll i = max(1, r); i <= n; i++) {
    int x = (a * i) / b;
    int y = (i / b);
    int m = x - a * y;
    ans = max(ans, m);
  }
  cout << ans << endl;
}


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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll s = b - 1;
  int ans;
  bool ok = true;
  while (ok) {
    if (s <= n) {
      int x = (a * s) / b;
      int y = (s / b);
      ans = x - a * y;
      ok = false;
    } else
      s--;
  }
  cout << ans << endl;
}
Problem p02696 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n, k) for (int i = (n); i < (k); i++)
#define ALL(a) (a).begin(), (a).end()
ll ans = 0;
ll calc(ll a, ll b, ll x) { return a * x / b - x / b * a; }
void Main() {
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  ll n;
  cin >> n;
  for (ll i = 1; i < n + 1; i++) {
    ll t = calc(a, b, i);
    if (t > ans)
      ans = t;
    else if (t < ans)
      break;
  }
  cout << ans << endl;
}
int main() {
  Main();
  /*
  東方風神録は神が出てくるので当然神ゲー
  */
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n, k) for (int i = (n); i < (k); i++)
#define ALL(a) (a).begin(), (a).end()
ll ans = 0;
ll calc(ll a, ll b, ll x) { return a * x / b - x / b * a; }
void Main() {
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  ll n;
  cin >> n;
  for (ll i = min(b, n); i > 0; i--) {
    ll t = calc(a, b, i);
    if (t > ans)
      ans = t;
    else if (t < ans)
      break;
  }
  cout << ans << endl;
}
int main() {
  Main();
  /*
  東方風神録は神が出てくるので当然神ゲー
  */
  return 0;
}
Problem p02696 (C++)

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll res = 0;
  for (ll x = N; x - B <= x && 0 <= x; x--) {
    res = max(res, (ll)(floor((A * x) / B) - A * floor(x / B)));
  }
  cout << res;
}

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

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

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const ll INF = 2e18;
const int inf = 1e9 + 10;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100;
const int MOD = 1000000007;

ll x, y, n;
int main() {
  freopen("a.txt", "r", stdin);
  freopen("b.txt", "w", stdout);

  scanf("%lld%lld%lld", &x, &y, &n);
  ll t = min(y - 1, n);
  ll ans = (x * t) / y - x * (t / y);
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const ll INF = 2e18;
const int inf = 1e9 + 10;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100;
const int MOD = 1000000007;

ll x, y, n;
int main() {

  scanf("%lld%lld%lld", &x, &y, &n);
  ll t = min(y - 1, n);
  ll ans = (x * t) / y - x * (t / y);
  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;

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

  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 z = min(B - 1, N);
  long long ans = A * z / B;

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long f = 0;
  if (n < b)
    f = (a * n) / b - a * (n / b);
  if (n == b)
    f = (a * (n - 1)) / b - a * ((n - 1) / b);
  if (n > b)
    for (long long i = 0; i <= n % b; i++) {
      long long t = (a * (n - i)) / b - a * ((n - i) / b);
      if (t > f)
        f = t;
    }
  cout << f << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long f = 0;
  if (n < b)
    f = (a * n) / b - a * (n / b);
  if (n == b)
    f = (a * (n - 1)) / b - a * ((n - 1) / b);
  if (n > b)
    f = (a * (n - 1 - n % b)) / b - a * ((n - 1 - n % b) / b);

  cout << f << endl;
}
Problem p02697 (C++)

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

int main(void) {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    if (n % 2)
      cout << i << " " << n - i + 1 << endl;
    else
      exit(9);
  }
  return (0);
}


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

int main(void) {
  int n, m;
  cin >> n >> m;
  n -= (n % 2 == 0);
  int start = 1;
  int end = n / 2;
  int cnt = 0;
  while (1) {
    if (start >= end - start + 1 || cnt == m)
      break;
    cout << start << " " << end - start + 1 << endl;
    start++;
    cnt++;
  }
  start = n / 2 + 1;
  end = n;
  while (1) {
    if (start >= end - start + (n / 2 + 1) || cnt == m)
      break;
    cout << start << " " << end - start + (n / 2 + 1) << endl;
    start++;
    cnt++;
  }
  return (0);
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using int64 = long long;

using namespace std;

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

  int N, M;
  cin >> N >> M;

  vector<pair<int, int>> ams;
  if (N % 2 == 1) {
    for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
      ams.emplace_back(lb, ub);
    }
  } else {
    bool flag = false;
    for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
      if (!flag && ub - lb <= N / 2) {
        flag = false;
        ub--;
      }
      ams.emplace_back(lb, ub);
    }
  }

  for (int i = 0; i < M; i++) {
    cout << ams[i].first << " " << ams[i].second << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using int64 = long long;

using namespace std;

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

  int N, M;
  cin >> N >> M;

  vector<pair<int, int>> ams;
  if (N % 2 == 1) {
    for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
      ams.emplace_back(lb, ub);
    }
  } else {
    bool flag = false;
    for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
      if (!flag && ub - lb <= N / 2) {
        flag = true;
        ub--;
      }
      ams.emplace_back(lb, ub);
    }
  }

  for (int i = 0; i < M; i++) {
    cout << ams[i].first << " " << ams[i].second << endl;
  }

  return 0;
}
Problem p02697 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> ans;
  if (n % 2) {
    for (int l = 1, r = n - 1; l < r; l++, r--) {
      ans.emplace_back(l, r);
    }
  } else {
    bool flag = false;
    for (int l = 1, r = n - 1; l < r; l++, r++) {
      if (!flag && r - l <= n / 2) {
        --r;
        flag = true;
      }
      ans.emplace_back(l, r);
    }
  }

  rep(i, m) { printf("%d %d\n", ans[i].first, ans[i].second); }
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> ans;
  if (n % 2) {
    for (int l = 1, r = n - 1; l < r; l++, r--) {
      ans.emplace_back(l, r);
    }
  } else {
    bool flag = false;
    for (int l = 1, r = n - 1; l < r; l++, r--) {
      if (!flag && r - l <= n / 2) {
        --r;
        flag = true;
      }
      ans.emplace_back(l, r);
    }
  }

  rep(i, m) { printf("%d %d\n", ans[i].first, ans[i].second); }
  return 0;
}
Problem p02697 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  if (N % 2)
    for (int i = 0; i < M; i++)
      cout << i + 1 << " " << N - i << endl;
  else {
    vector<bool> used(N + 1, false);
    int pos = 1;
    for (int k = M; k > 0; k--) {
      while (1) {
        if (!used[pos] && !used[pos + k]) {
          cout << pos << " " << pos + k << endl;
          used[pos] = used[pos + k] = true;
          pos++;
          break;
        }
        pos++;
      }
    }
  }
  return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  if (N % 2)
    for (int i = 0; i < M; i++)
      cout << i + 1 << " " << N - i << endl;
  else {
    for (int i = 0; i < (M + 1) / 2; i++)
      cout << i + 1 << " " << (M + 1) / 2 * 2 - i << endl;
    int r = (M + 1) / 2 * 2;
    for (int i = 0; i < M / 2; i++)
      cout << r + i + 1 << " " << r + M / 2 * 2 + 1 - i << endl;
  }
  return 0;
}
Problem p02697 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 0; i < m; i++) {
      cout << i + 1 << " " << n - i << endl;
    }
  } else {
    vector<bool> check(100005);
    int arrow = 1;
    int dif = 1;
    int cnt = 0;
    while (cnt < m) {
      if (!check[arrow]) {
        cout << arrow << " " << arrow + dif << endl;
        check[arrow] = true;
        check[arrow + dif] = true;
        dif++;
        cnt++;
      }
      arrow++;
    }
  }
  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 0; i < m; i++) {
      cout << i + 1 << " " << n - i << endl;
    }
  } else {
    for (int i = 0; i < m; i++) {
      cout << i + 1 << " " << n - i - (2 * i >= m) << endl;
    }
  }
  return 0;
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  int n, m;
  cin >> n >> m;
  ll p = (n - 1) / 2;

  if (n % 2 != 0) {
    rep(i, m) { cout << p - i << " " << p + i + 1 << endl; }
  } else {
    bool done[200010];
    memset(done, 0, sizeof(done));
    int now = 0;
    int i = 0;
    while (i < m) {
      int diff = i + 1;
      if (done[now] || done[(now + diff) % n]) {
        now++;
        continue;
      } else
        cout << now + 1 << " " << (now + diff) % n + 1 << endl;
      done[now] = true;
      done[now + diff] = true;
      i++;
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  int n, m;
  cin >> n >> m;
  ll p = (n - 1) / 2;

  if (n % 2 != 0) {
    rep(i, m) { cout << p - i << " " << p + i + 1 << endl; }
    return 0;
  }

  int h = n / 2;

  rep(i, (m + 1) / 2) { cout << h / 2 - i << " " << h / 2 + i + 1 << endl; }

  rep(i, m - (m + 1) / 2) {
    cout << h + h / 2 - i - 1 << " " << h + h / 2 + i + 1 << endl;
  }

  return 0;
}
Problem p02697 (C++)

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;

  vector<bool> visited(N + 1, false);
  int j = 1;
  for (int i = 1; i <= M; ++i) {
    while (visited[j])
      ++j;
    cout << j << ' ' << j + i << endl;
    visited[j] = visited[j + i] = true;
  }
  return 0;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;

  bool even = (M % 2 == 0);
  int left = 1;
  int right = M;

  if (!even)
    ++right;
  while (left < right) {
    cout << left << ' ' << right << endl;
    ++left;
    --right;
  }

  left = M + 1;
  if (!even)
    ++left;
  right = left + M;
  if (!even)
    --right;
  while (left < right) {
    cout << left << ' ' << right << endl;
    ++left;
    --right;
  }
  return 0;
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
int dat1[50005], dat2[50005];
using namespace std;
int main() {

  int n, m;
  cin >> n >> m;
  if (!(n & 1))
    n--;
  int mm = (n - 1) / 2;
  if (mm & 1) {
    for (int i = 1; i <= mm / 2; i++) {
      dat1[i] = i;
      dat2[i] = (n + 1) / 2 - i;
    }
    for (int j = (n + 1) / 2, i = mm / 2 + 1, k = 0; i <= mm; i++, j++, k++) {
      dat1[i] = j;
      dat2[i] = n - k;
    }
  } else {
    for (int i = 1; i <= mm / 2; i++) {
      dat1[i] = i;
      dat2[i] = (n + 3) / 2 - i;
    }
    for (int i = (n + 3) / 2, j = n, k = mm / 2 + 1; k <= mm; i++, j--, k++) {
      dat1[k] = i;
      dat2[k] = j;
    }
  }
  // for(int i=1;i<=6;i++) cout<<dat1[i]<<" "<<dat2[i]<<endl;
  for (int i = 1; i <= m; i++)
    cout << dat1[i] << " " << dat2[i] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
int dat1[100005], dat2[100005];
using namespace std;
int main() {

  int n, m;
  cin >> n >> m;
  if (!(n & 1))
    n--;
  int mm = (n - 1) / 2;
  if (mm & 1) {
    for (int i = 1; i <= mm / 2; i++) {
      dat1[i] = i;
      dat2[i] = (n + 1) / 2 - i;
    }
    for (int j = (n + 1) / 2, i = mm / 2 + 1, k = 0; i <= mm; i++, j++, k++) {
      dat1[i] = j;
      dat2[i] = n - k;
    }
  } else {
    for (int i = 1; i <= mm / 2; i++) {
      dat1[i] = i;
      dat2[i] = (n + 3) / 2 - i;
    }
    for (int i = (n + 3) / 2, j = n, k = mm / 2 + 1; k <= mm; i++, j--, k++) {
      dat1[k] = i;
      dat2[k] = j;
    }
  }
  // for(int i=1;i<=6;i++) cout<<dat1[i]<<" "<<dat2[i]<<endl;
  for (int i = 1; i <= m; i++)
    cout << dat1[i] << " " << dat2[i] << endl;
  return 0;
}
Problem p02697 (C++)

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

  int n, m;
  cin >> n >> m;
  vector<bool> used(n + 1);

  for (int i = 1, j = 1; j <= m; i++, j++) {
    while (used[i])
      i++;
    cout << i << ' ' << i + j << endl;
    used[i] = used[i + j] = true;
  }
  return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

  int n, m;
  cin >> n >> m;
  if (n & 1) {
    for (int i = 0; i < m; i++) {
      cout << i + 1 << ' ' << n - i << endl;
    }
  } else {
    for (int i = 0; i < m; i++) {
      if (i * 2 < (n - 2) / 2)
        cout << i + 1 << ' ' << n - i << endl;
      else
        cout << i + 1 << ' ' << n - i - 1 << endl;
    }
  }
  return 0;
}
Problem p02697 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  int c = (n + 1) / 2, d = 1, i = 0;
  while (c - d > 0) {
    a[i] = d;
    b[i] = c;
    ++d;
    --c;
    ++i;
  }
  int e = (n + 1) / 2 + 1, f = n;
  while (f - e > 0) {
    a[i] = e;
    b[i] = f;
    ++e;
    --f;
    ++i;
  }
  rep(i, m) { cout << a[i] << " " << b.at(i) << "\n"; }
  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() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  if (m % 2 == 0) {
    int c = m + 1, d = 1, i = 0;
    while (c - d > 0) {
      a[i] = d;
      b[i] = c;
      ++d;
      --c;
      ++i;
    }
    int e = m + 2, f = 2 * m + 1;
    while (f - e > 0) {
      a[i] = e;
      b[i] = f;
      ++e;
      --f;
      ++i;
    }
  } else {
    int c = m, d = 1, i = 0;
    while (c - d > 0) {
      a[i] = d;
      b[i] = c;
      ++d;
      --c;
      ++i;
    }
    int e = m + 1, f = 2 * m + 1;
    while (f - e > 0) {
      a[i] = e;
      b[i] = f;
      ++e;
      --f;
      ++i;
    }
  }
  rep(i, m) { cout << a[i] << " " << b.at(i) << "\n"; }
  return 0;
}
Problem p02697 (C++)

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

using namespace std;

typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  set<int> s;
  for (int i = 1; i <= n; i++)
    s.insert(i);
  int i = 1;
  while (i <= m) {
    int front = *s.begin();
    int next = front + i;
    if (next > n) {
      next -= n;
    }
    if (s.find(next) == s.end()) {
      continue;
    }
    cout << front << ' ' << next << endl;
    s.erase(front);
    s.erase(next);
    i++;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  int i = 0;
  while (1) {
    int start = 1 + i;
    int end = m + 1 - i;
    if (start >= end)
      break;
    cout << start << ' ' << end << endl;
    i++;
  }
  i = 0;
  while (1) {
    int start = m + 2 + i;
    int end = 2 * m + 1 - i;
    if (start >= end)
      break;
    cout << start << ' ' << end << endl;
    i++;
  }
  return 0;
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                                                       \
  cerr << __LINE__ << ": " << #x << " = {";                                    \
  for (long long hoge = 0; (hoge) < (n); ++(hoge))                             \
    cerr << ((hoge) ? "," : "") << x[hoge];                                    \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  bool used[N];
  fill(used, used + N, false);
  int cur = 0;
  for (int i = 1; i <= M; i++) {
    while (cur < N && used[cur])
      cur++;
    used[cur] = true;
    used[cur + i] = true;
    cout << cur + 1 << " " << cur + i + 1 << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                                                       \
  cerr << __LINE__ << ": " << #x << " = {";                                    \
  for (long long hoge = 0; (hoge) < (n); ++(hoge))                             \
    cerr << ((hoge) ? "," : "") << x[hoge];                                    \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  if (N & 1) {
    for (int i = 1; i <= M; i++) {
      cout << i << " " << N + 1 - i << endl;
    }
  } else {
    for (int i = 1, len = M & 1 ? M : M - 1; len >= 1; i++, len -= 2) {
      cout << i << " " << i + len << endl;
    }
    for (int i = N - 1, len = M & 1 ? M - 1 : M; len >= 2; i--, len -= 2) {
      cout << i << " " << i - len << endl;
    }
  }
  return 0;
}
Problem p02697 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;

  vector<bool> checked(N + 1, false);
  for (int i = M; i > 0; i--) {
    for (int ai = 1; ai <= N; ai++) {
      int bi = ai + i;
      if (!checked.at(ai) && !checked.at(bi)) {
        printf("%d %d\n", ai, bi);
        checked.at(ai) = checked.at(bi) = true;
        break;
      }
    }
  }
}

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

int main() {
  int N, M;
  cin >> N >> M;

  vector<bool> checked(N + 1, false);

  int ai = 1;
  for (int i = M; i > 0; i -= 2) {
    printf("%d %d\n", ai, ai + i);
    ai++;
  }

  ai = N;
  for (int i = M - 1; i > 0; i -= 2) {
    printf("%d %d\n", ai, ai - i);
    ai--;
  }
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod = 1000000007, INF = mod * mod * 3LL;
#define doublecout(a) cout << fixed << setprecision(10) << a << endl;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  if (n & 1) {
    ll id = 1;
    vector<pair<ll, ll>> v(m);
    for (int i = 0; i < n; i++) {
      v[i].first = id;
      id++;
    }
    id = n / 2 + 1;
    for (int i = m - 1; i >= 0; i--) {
      v[i].second = id;
      id++;
    }
    for (auto &i : v) {
      cout << i.first << " " << i.second << endl;
    }
    return 0;
  }
  ll a = n / 2, b;
  if (a & 1)
    b = a - 1, a -= 2;
  else
    b = a - 2, a--;
  vector<pair<ll, ll>> v;
  int idx = 1;
  for (ll i = a; i >= 1; i -= 2, idx++) {
    v.push_back({idx, idx + i});
  }
  idx = a + 2;
  for (int i = b; i >= 1; i -= 2, idx++) {
    v.push_back({idx, idx + i});
  }
  for (int i = 0; i < m; i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod = 1000000007, INF = mod * mod * 3LL;
#define doublecout(a) cout << fixed << setprecision(10) << a << endl;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  if (n & 1) {
    ll id = 1;
    vector<pair<ll, ll>> v(m);
    for (int i = 0; i < m; i++) {
      v[i].first = id;
      id++;
    }
    id = n / 2 + 1;
    for (int i = m - 1; i >= 0; i--) {
      v[i].second = id;
      id++;
    }
    for (auto &i : v) {
      cout << i.first << " " << i.second << endl;
    }
    return 0;
  }
  ll a = n / 2, b;
  if (a & 1)
    b = a - 1, a -= 2;
  else
    b = a - 2, a--;
  vector<pair<ll, ll>> v;
  int idx = 1;
  for (ll i = a; i >= 1; i -= 2, idx++) {
    v.push_back({idx, idx + i});
  }
  idx = a + 2;
  for (int i = b; i >= 1; i -= 2, idx++) {
    v.push_back({idx, idx + i});
  }
  for (int i = 0; i < m; i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
  return 0;
}