alexjercan/bugnet huggingface dataset:
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  if (N >= B - 1) {
    cout << (A * (B - 1)) / B - A * ((B - 1) / B) << endl;
  } else {
    cout << (A * (N)) / B - A * ((N) / B) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll i = 2, ans = (A / B) - A * (1 / B), wer = 0;
  while (i <= N && wer <= ans) {
    wer = ans;
    ans = (i * A / B) - A * (i / B);
    i++;
  }
  cout << max(ans, wer) << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  long long int a = 0, b = 0, n = 0, x = 0, y = 0, z = 0, max = 0;
  cin >> a >> b >> n;

  if (n >= b - 1) {
    y = (b - 1) / b;
    y = a * y;
    x = a * (b - 1) / b;
    z = x - y;
    if (max < z) {
      max = z;
    }
    z = 0;
  } else {
    y = n / b;
    y = a * y;
    x = a * n / b;
    z = x - y;
    max = z;
  }
  cout << max << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  long long int a = 0, b = 0, n = 0, x = 0, y = 0, z = 0, max = 0;
  cin >> a >> b >> n;

  if (n >= b - 1) {
    for (int i = b - 1; i <= n; i = i + b) {
      y = i / b;
      y = a * y;
      x = a * i / b;
      z = x - y;
      if (max < z) {
        max = z;
      }
      z = 0;
    }
  } else {
    y = n / b;
    y = a * y;
    x = a * n / b;
    z = x - y;
    max = z;
  }
  cout << max << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  unsigned long long n, a, b;
  cin >> a >> b >> n;
  int ll = n;
  if (b <= n + 1)
    n = b - 1;
  unsigned long long g = (a * (n) / b) - a * ((n) / b);
  // unsigned long long ans=max(g,l);
  // if(b>n)

  cout << g << endl;
  return 0;
}
// 1239123 12312 5
// 12312 5443234 1235


Error: TLE

Fixed submission:

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

int main() {

  unsigned long long n, a, b;
  cin >> a >> b >> n;
  // unsigned long long g=(a*n/b)-a*(n/b),l=(a*1/b)-a*(1/b);
  // unsigned long long ans=max(g,l);
  unsigned long long c = 0;
  int o;
  for (int i = 0; i <= n; i++) {
    unsigned long long p = (a * i / b) - a * (i / b);
    if (p > c)
      o = i;
    c = max(c, p);
  }

  cout << c << endl;
  return 0;
}
// 1239123 12312 5
// 12312 5443234 1235
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
using ll = long long;
int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  ll x = min(B - 1, N);
  ll F = (A * x) / B - A * (x / B);
  cout << F << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
using ll = long long;

ll aiueo(ll a) {
  for (int i = int(a); i < 1000000; i++)
    if (a - i < 0)
      return i - 1;
}

int main(void) {
  // Your code here!
  ll A, B, N;
  cin >> A >> B >> N;
  int max = 0;
  for (ll x = 0; x <= N; x++) {
    int t = aiueo(A * x / B) - A * aiueo(x / B);
    // cout << t << endl;
    if (max < t)
      max = t;
  }
  cout << max << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ch = min(n, b - 1);
  ll o = n / b;
  ch += o * b;
  while (ch > n) {
    ch -= b;
  }
  ll c = (a * n) / b, cc = a * (n / b), d = (a * ch) / b, dd = a * (ch / b);
  cout << max(c - cc, d - dd) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ch = min(n, b - 1);
  while (ch < n) {
    ch += b;
  }
  ch -= b;
  ll c = (a * n) / b, cc = a * (n / b), d = (a * ch) / b, dd = a * (ch / b);
  cout << max(c - cc, d - dd) << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long A, B, N;

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

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

  long long keisu = N / B;
  long long maxNum1 = calc(B * keisu - 1);
  long long maxNum2 = calc(N);
  cout << (maxNum1 > maxNum2 ? maxNum1 : maxNum2);
}


Error: TLE

Fixed submission:

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

long long A, B, N;

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

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

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

  cout << maxNum;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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


Error: TLE

Fixed submission:

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll sum = 0, prevSum = -1;
  for (ll x = 1; x <= n; x++) {
    sum = floor((a * x) / b) - a * floor(x / b);
    // cout<<x<<" "<<sum<<" "<<prevSum<<endl;
    if (prevSum == -1) {
      prevSum = sum;
    } else {
      if (sum < prevSum) {
        break;
      }
      prevSum = sum;
    }
  }
  // cout<<sum<<" "<<prevSum<<endl;
  cout << prevSum << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: 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;
  if (N < B)
    ans = (A * N / B);
  else
    ans = (A * (B - 1) / B);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll Ans = 0;
  for (int i = 0; i <= N; i++) {
    ll num = (A * i / B) - A * (i / B);
    Ans = max(Ans, num);
  }
  cout << Ans << endl;
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX(a, b) a = a > b ? a : b
#define MIN(a, b) a = a < b ? a : b
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPR(i, x, n) for (int i = n - 1; i >= x; i--)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI = 3.14159265358979323846;
ll dp;

int main() {
  ll n, m, z, ne;
  ;
  cin >> n >> m;

  if (m % 2 == 0) {
    z = m, ne = 1 + m;
  } else {
    z = m + 1, ne = m + 2;
  }
  bool f[101010] = {}, f2[101010] = {}; // f2kyori
  if (n % 2 == 1) {
    REP(i, 1, m + 1) { cout << i << " " << n - i + 1 << endl; }
  } else {
    int i = 1;
    while (z > i) {
      cout << i % n << " " << (z) % n << endl;
      i++;
      z--;
    }

    z = ne;
    i = ne;
    z = ne + m - (m % 2);
    while (z > i) {
      cout << i % n << " " << (z) % n << endl;
      i++;
      z--;
    }
    // REP(i,1,n*2+1){
    //    if(f[i%n]==0&&f[(i+z)%n]==0){
    //       if(i%n<(i+z)%n){
    //          cout<<i%n<<" "<<(i+z)%n<<endl;;
    //       }else{
    //          cout<<(i+z)%n<<" "<<(i)%n<<endl;;
    //       }

    //       f[i%n]=f[(i+z)%n]=1;
    //       z--;

    //    }
    //    if(z==0)return 0;
    // }
  }
}


Error: WA

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 - 1; i >= 0; i--)
#define MAX(a, b) a = a > b ? a : b
#define MIN(a, b) a = a < b ? a : b
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPR(i, x, n) for (int i = n - 1; i >= x; i--)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI = 3.14159265358979323846;
ll dp;

int main() {
  ll n, m, z = 1;
  ;
  cin >> n >> m;
  bool f[101010] = {}, f2[101010] = {}; // f2kyori
  if (n % 2 == 1) {
    REP(i, 1, m + 1) { cout << i << " " << n - i + 1 << endl; }
  } else {
    REP(i, 1, n + 1) {
      if (f[i] == 0) {
        cout << i << " " << i + z << endl;
        ;
        f[i] = f[i + z] = 1;
        z++;
      }
      if (z > m)
        return 0;
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define lc (x << 1)
#define rc (x << 1 | 1)
#define gc                                                                     \\
  getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int, int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5 + 10, size = 1 << 20;

// char buf[size],*p1=buf,*p2=buf;
template <class o> void qr(o &x) {
  char c = gc;
  x = 0;
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = gc;
  }
  while (isdigit(c))
    x = x * 10 + c - '0', c = gc;
  x *= f;
}
template <class o> void qw(o x) {
  if (x / 10)
    qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o> void pr1(o x) {
  if (x < 0)
    x = -x, putchar('-');
  qw(x);
  putchar(' ');
}
template <class o> void pr2(o x) {
  if (x < 0)
    x = -x, putchar('-');
  qw(x);
  puts("");
}

int n, m;

int main() {
  qr(n);
  qr(m);
  int t = m + (m & 1), tt = t + 1;
  for (int i = 1; i < t; i++)
    pr1(i), pr2(t--);
  t = 2 * m + 1;
  for (int i = tt; i < t; i++)
    pr1(i), pr2(t--);
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define lc (x << 1)
#define rc (x << 1 | 1)
#define gc                                                                     \\
  getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int, int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5 + 10, size = 1 << 20;

// char buf[size],*p1=buf,*p2=buf;
template <class o> void qr(o &x) {
  char c = gc;
  x = 0;
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = gc;
  }
  while (isdigit(c))
    x = x * 10 + c - '0', c = gc;
  x *= f;
}
template <class o> void qw(o x) {
  if (x / 10)
    qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o> void pr1(o x) {
  if (x < 0)
    x = -x, putchar('-');
  qw(x);
  putchar(' ');
}
template <class o> void pr2(o x) {
  if (x < 0)
    x = -x, putchar('-');
  qw(x);
  puts("");
}

int n, m;
bool v[N];

int main() {
  qr(n);
  qr(m);
  for (int i = 1, t = 1; i <= m; i++) {
    while (v[t] || v[t + i > n ? t + i - n : t + i]) {
      t++;
      if (t > n)
        t = 1;
    }
    pr1(t);
    pr2(t + i);
    v[t + i] = 1;
    t++;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

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

  ll n, m;
  cin >> n >> m;
  int i = 1, j = 1 + m;
  vector<pair<ll, ll>> ans;
  while (i < j) {
    ans.push_back({i, j});
    i++;
    j--;
  }
  i = 2 + m;
  j = 1 + 2 * m;
  while (i < j) {
    ans.push_back({i, j});
    i++;
    j--;
  }

  for (auto i : ans)
    cout << i.first << " " << i.second << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

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

  ll n, m;
  cin >> n >> m;
  vector<bool> used(n + 1, false);
  int j = 1;
  cout << 1 << " " << n << endl;
  used[1] = used[n] = true;
  for (int i = 2; i <= m; i++) {
    for (; j <= n; j++) {
      if (!used[j]) {
        cout << j << " ";
        used[j] = true;
        break;
      }
    }

    cout << j + i << endl;
    used[j + i] = true;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

  int n, m;
  cin >> n >> m;

  for (int i = 1; i * 2 <= m; ++i) {
    cout << i << ' ' << m - i + 1 << '\\n';
  }

  for (int i = 1; i * 2 <= m + 1; ++i) {
    cout << m + i << ' ' << m * 2 - i + 2 << '\\n';
  }

  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  int n, m;
  cin >> n >> m;

  if (n & 1) {
    for (int i = 0; i < m; ++i) {
      cout << i + 1 << ' ' << n - i - (n & 1) << '\\n';
    }
  } else {
    vector<int> a;
    a.resize(1000000000000000);
    for (int i = 0; i <= m / 2; ++i) {
      cout << i + 1 << ' ' << n - i << '\\n';
    }
    for (int i = m / 2 + 1; i < m; ++i) {
      cout << i + 1 << ' ' << n - i - 1 << '\\n';
    }
  }

  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()), ((x).end())
#define usecppio                                                               \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
#define int ll
const bool debug = 0;
using pii = pair<int, int>;
typedef long double D;

int32_t main() {
  usecppio int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 1; i <= m; i++)
      cout << i << ' ' << n - i << '\\n';
  } else {
    int odd = (m + 1) / 2;
    for (int i = 1; i <= odd; i++)
      cout << i << ' ' << n - i + 1 << '\\n';
    for (int i = odd + 1; i <= m; i++)
      cout << i << ' ' << n - i << '\\n';
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define fastIO                                                                 \\
  cout << fixed << setprecision(12), ios::sync_with_stdio(false),              \\
      cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 2e5;
bool vis[N];

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, m;
  cin >> n >> m;
  for (int i = 3; i <= n && m; ++i) {
    int diff = i - 1;
    if (!vis[diff] && m) {
      cout << 1 << ' ' << i - 1 << '\\n';
      vis[diff] = 1;
      for (int j = diff; j < N; j += diff)
        vis[j] = 1;
      --m;
      if (!m)
        break;
    }
  }
  assert(m == 0);
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
template <class T> void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}
template <class T> void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}

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

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

  vector<int> used(N, 0);
  vector<pair<int, int>> ans;
  int ps = 1;
  for (int i = M; i >= 1; i--) {
    if (i % 2 == M % 2) {
      int a = (M - i) / 2;
      ans.push_back(mkp(a, a + i));
    } else {
      int a = M + 1 + (M - 1 - i) / 2;
      ans.push_back(mkp(a, a + i));
    }
  }

  for (int i = 0; i < M; i++)
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << "\\n";

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
template <class T> void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}
template <class T> void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}

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

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

  vector<int> used(N, 0);
  vector<pair<int, int>> ans;
  int ps = 1;
  for (int i = 0; i < N; i++) {
    if (used[i])
      continue;
    if (i + ps < N && used[i + ps] == 0) {
      used[i] = 1;
      used[i + ps] = 1;
      ans.push_back(mkp(i + 1, i + ps + 1));
      ps++;
    }
    if (ps > M)
      break;
  }

  for (int i = 0; i < M; i++)
    cout << ans[i].first << " " << ans[i].second << "\\n";

  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
  for (int i = 0; i < sz(v); i++) {
    os << v[i];
    if (i < sz(v) - 1)
      os << " ";
  }
  return os;
}
int main() {
  int n, m;
  cin >> n >> m;
  {
    int a = 1, b = m + 1;
    for (int i = m; i >= 1; i -= 2) {
      assert(b <= n);
      cout << a << " " << b << endl;
      a++;
      b--;
    }
  }
  {
    int a = m + 2, b = 2 * m + 1;
    for (int i = m - 1; i >= 1; i -= 2) {
      assert(b <= n);
      cout << a << " " << b << endl;
      a++;
      b--;
    }
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
  for (int i = 0; i < sz(v); i++) {
    os << v[i];
    if (i < sz(v) - 1)
      os << " ";
  }
  return os;
}
int main() {
  int n, m;
  cin >> n >> m;
  set<int> st;
  for (int i = 1; i <= n; i++)
    st.insert(i);
  for (int i = 1; i <= m; i++) {
    int a = *st.begin();
    st.erase(a);
    int b = a + i;
    st.erase(b);
    assert(b <= n);
    cout << a << " " << b << endl;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

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

signed main() {
  int n, m;
  cin >> n >> m;
  int cnt = 1;
  for (int i = m; i >= 1; i -= 2) {
    cout << cnt << " " << cnt + i << endl;
    cnt++;
  }
  cnt = m + 2;
  for (int i = m - 1; i >= 1; i -= 2) {
    cout << cnt << " " << cnt + i << endl;
    cnt++;
  }
}


Error: TLE

Fixed submission:

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

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> used(n, 0);
  int now = 0;
  for (int i = 1; i <= m; i++) {
    int a = now + i;
    while (used[now] || used[a])
      (++now) %= n, (++a) %= n;
    cout << now + 1 << " " << a + 1 << endl;
    used[now] = used[a] = 1;
  }
}