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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int IINF = INT32_MAX;
static const ll LINF = INT64_MAX;
static const ll mod = 1e9 + 7;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};

int N, M;

bool f[200005];
bool usem[200005];

int main() {
  cin >> N >> M;
  if (N % 2 == 1) {
    for (int i = 1; i <= M; ++i) {
      cout << i << " " << N - i + 1 << endl;
    }
  } else {
    int cnt = 0;
    int t = N - 1;
    int i = 1;
    while (cnt < M) {
      i %= N;
      if (i == 0)
        i = N;
      int a = (i + t) % N;
      int b = (i + N - t) % N;
      if (a == 0)
        a = N;
      if (b == 0)
        b = N;
      if ((f[i] || f[a]) && (f[i] || f[b])) {
        i++;
        continue;
      }
      if (f[i] || f[a]) {
        cout << i << " " << b << endl;
        f[i] = f[b] = true;
      } else {
        cout << i << " " << a << endl;
        f[i] = f[a] = true;
      }
      i++;
      t--;
      cnt++;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int IINF = INT32_MAX;
static const ll LINF = INT64_MAX;
static const ll mod = 1e9 + 7;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};

int N, M;

bool f[200005];
bool usem[200005];

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (ll i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());
  ll n, m;
  cin >> n >> m;
  set<ll> used;
  ll left = 0, right = 0;
  rep(i, m) {
    right = (right + 1) % n;
    while ((used.count(left) > 0) || (used.count(right) > 0)) {
      left = (left + 1) % n;
      right = (right + 1) % n;
    }
    used.insert(left);
    used.insert(right);
    printf("%lld %lld\n", left + 1, right + 1);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (ll i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());
  ll n, m;
  cin >> n >> m;
  if (m == 1) {
    printf("1 2\n");
    return 0;
  }
  ll v1 = 1;
  ll v2 = m + 2;
  rreps(i, 1, m + 1) {
    printf("%lld %lld\n", v1, v1 + i);
    v1++;
    swap(v1, v2);
  }
  return 0;
}
Problem p02697 (C++)

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

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 998244353;

inline int cmp(double x, double y = 0) {
  if (fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;

int a[maxn];

map<int, int> mapa;

int main() {
  ios::sync_with_stdio(0);
  int n, m;

  cin >> n >> m;
  set<int> s;
  for (int i = 1; i <= n; i++)
    s.insert(i);
  int gap = 1;
  for (int i = 1; i <= m; i++) {
    assert(s.size() > 0);
    int a = *s.begin();
    cout << a << ' ' << a + gap << endl;
    s.erase(s.find(a));
    s.erase(s.find(a + gap));
    gap++;
  }

  return 0;
}

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

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 998244353;

inline int cmp(double x, double y = 0) {
  if (fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;

int a[maxn];

map<int, int> mapa;

int main() {
  ios::sync_with_stdio(0);
  int n, m;

  cin >> n >> m;
  int l = 1, r = m + 1;
  while (l < r)
    cout << l++ << ' ' << r-- << endl;

  l = m + 2, r = 2 * m + 1;
  while (l < r)
    cout << l++ << ' ' << r-- << endl;

  return 0;
}
Problem p02697 (C++)

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

bool U[100005];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  vector<pll> ans;
  if (N % 2 == 1) {
    REP(i, M) { ans.push_back(pll(i + 1, N - 1 - i)); }
  } else {

    memset(U, 0, sizeof(U));
    for (ll i = 1; i <= M; i += 2) {
      ans.push_back(pll(i, i * 2));
      U[i] = U[i * 2] = true;
    }

    ll m = (M / 2) * 2;
    for (ll i = 2; i <= N; i += 2) {
      if (i + m > N)
        break;
      if (U[i] || U[i + m])
        continue;
      ans.push_back(pll(i, i + m));
      U[i] = U[i + m] = true;
      m -= 2;
    }
    for (ll i = ((M / 2) * 2) + 1; i <= N; i += 2) {
      if (i + m > N)
        break;
      if (U[i] || U[i + m])
        continue;
      ans.push_back(pll(i, i + m));
      U[i] = U[i + m] = true;
      m -= 2;
    }
  }

  REP(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }
  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

bool U[100005];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  vector<pll> ans;
  if (N % 2 == 1) {
    REP(i, M) { ans.push_back(pll(i + 1, N - 1 - i)); }
  } else {
    ll es = 1, os = N;
    for (ll m = M; m > 0; --m) {
      if (m % 2 == 0) {
        ans.push_back(pll(es, es + m));
        es++;
      } else {
        ans.push_back(pll(os, os - m));
        os--;
      }
    }
  }

  REP(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }
  return 0;
}
Problem p02697 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define exrep(i, a, b) for (long long i = a; i <= b; i++)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll>> vvl;
typedef vector<vector<P>> vvp;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

  int n, m;
  cin >> n >> m;
  vector<P> vec;
  if (n % 2) {
    for (int l = 1, r = n - 1; l <= n / 2; l++, r--) {
      vec.push_back(P(l, r));
    }
  } else {
    int l = 1, r = n, cnt = 1;
    while (cnt <= n / 4) {
      vec.push_back(P(l, r));
      l++;
      r--;
      cnt++;
    }
    l++;
    while (abs(l - r) > 1) {
      vec.push_back(P(l, r));
    }
  }
  rep(i, m) { cout << vec[i].first << " " << vec[i].second << endl; }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define exrep(i, a, b) for (long long i = a; i <= b; i++)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll>> vvl;
typedef vector<vector<P>> vvp;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

  int n, m;
  cin >> n >> m;
  vector<P> vec;
  if (n % 2) {
    for (int l = 1, r = n - 1; l <= n / 2; l++, r--) {
      vec.push_back(P(l, r));
    }
  } else {
    int l = 1, r = n, cnt = 1;
    while (cnt <= n / 4) {
      vec.push_back(P(l, r));
      l++;
      r--;
      cnt++;
    }
    l++;
    while (abs(l - r) > 1) {
      vec.push_back(P(l, r));
      l++;
      r--;
    }
  }
  rep(i, m) { cout << vec[i].first << " " << vec[i].second << endl; }
  return 0;
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define repf(i, m, n) for (int i = (m); i < (n); i++)
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;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> b(n, false);
  int pos = 0, mn = 0;
  repf(i, 1, m + 1) {
    pos = mn;
    if (b[pos + i]) {
      pos++;
    }
    cout << pos + 1 << " " << pos + i + 1 << endl;
    b[pos] = true;
    b[pos + i] = true;
    while (b[mn]) {
      mn++;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define repf(i, m, n) for (int i = (m); i < (n); i++)
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;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> b(n, false);
  int pos = 1, mx = 1;
  for (int i = m; i >= 1; i -= 2) {
    cout << pos << " " << pos + i << endl;
    pos++;
    chmax(mx, pos + i);
  }
  pos = mx;
  for (int i = m - 1; i >= 1; i -= 2) {
    cout << pos << " " << pos + i << endl;
    pos++;
  }
  return 0;
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
// g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  ll N, M;
  cin >> N >> M;
  ll a, b;
  a = 3;
  b = 5;
  if (M >= 1)
    cout << 1 << " " << 2 << endl;
  if (M >= 2)
    cout << 3 << " " << 5 << endl;
  vector<int> flag(200010, 1);
  flag[1] = 0;
  flag[2] = 0;
  flag[3] = 0;
  flag[5] = 0;
  if (M >= 3) {
    int i = 3;
    while (i <= M) {
      a++;
      if (flag[a] == 1 && flag[a + i] == 1) {
        b = a + i;
        cout << a << " " << b << endl;
        flag[a] = 0;
        flag[b] = 0;
        i++;
      }
    }
  }
}


Fixed submission:
// g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  ll N, M;
  cin >> N >> M;
  int a = N;
  int b = 1 + M;
  int flag = 1;
  for (int i = 1; i <= M; i++) {
    if (flag % 2 == 1) {
      cout << b << " " << b + i << endl;
      b--;
      flag--;
    } else {
      cout << a << " " << a - (N - i) << endl;
      a--;
      flag++;
    }
  }
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v, x) memset(v, x, sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(), v.end()
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int eu = 1, ini = 2;
  vector<int> vis(100100);
  for (int i = 1; i <= m; i++) {
    cout << eu << " " << ini << endl;
    vis[eu] = 1;
    vis[ini] = 1;
    while (vis[eu] or vis[ini]) {
      eu++;
      ini += 2;
      if (ini > n) {
        ini -= n;
      }
      if (eu > n) {
        eu -= n;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1, l = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define ms(v, x) memset(v, x, sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(), v.end()
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int val = 2 * m + 1;
  for (int i = 0; i < m / 2; i++) {
    cout << i + 1 << " " << val / 2 - i << endl;
  }
  int cnt = 1;
  for (int i = m / 2; i < m; i++) {
    cout << val / 2 + cnt << " " << val - (cnt - 1) << endl;
    cnt++;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1, l = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}
Problem p02697 (C++)

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

using namespace std;
typedef long long ll;
#define int ll

template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

#define REP(i, n) for (int i = 0; i < n; ++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

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

  if (N % 2 != 0 || N == 4) {
    // 真ん中から割って割り当てる
    int cur1 = N / 2;
    int cur2 = cur1 + 1;
    REP(i, M) {
      printf("%lld %lld\n", cur1, cur2);
      cur1--;
      cur2++;
    }
  } else {
    assert(false);
    // 末尾を 1 つ飛ばしで開ける
    int cur1 = 1;
    int cur2 = N - 1;
    REP(i, M) {
      printf("%lld %lld\n", cur1, cur2);
      cur1++;
      cur2--;
      if (i == 0) {
        cur2--;
      }
    }
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

#define REP(i, n) for (int i = 0; i < n; ++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

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

  if (N % 2 != 0 || N == 4) {
    // 真ん中から割って割り当てる
    int cur1 = N / 2;
    int cur2 = cur1 + 1;
    REP(i, M) {
      printf("%lld %lld\n", cur1, cur2);
      cur1--;
      cur2++;
    }
  } else {
    // 空ける間隔で偶奇に分けて詰めていく
    // 偶数(奇数)間隔から
    int lb = 1;
    int rb = lb + M;
    while (lb < rb) {
      printf("%lld %lld\n", lb, rb);
      lb++;
      rb--;
    }
    // 奇数(偶数)間隔
    lb = M + 2;
    rb = lb + M - 1;
    while (lb < rb) {
      printf("%lld %lld\n", lb, rb);
      lb++;
      rb--;
    }
  }

  return 0;
}
Problem p02697 (C++)

Buggy submission (status: 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;

  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;
}


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;

  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;
}
Problem p02697 (C++)

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

bool u[100010];
long long n, m, x;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  int i = 1;
  int j = n;
  while (m--) {
    x = j - i - 2;
    if (!u[x] && !u[n - x - 2]) {
      u[x] = u[n - x - 2] = true;
      cout << i << ' ' << j << '\n';
      i++, j--;
    } else
      j--, m++;
  }
}


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

bool u[1000010];
long long n, m, x;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  int i = 1;
  int j = n;
  while (m--) {
    x = j - i - 2;
    if (!u[x] && !u[n - x - 2]) {
      u[x] = u[n - x - 2] = true;
      cout << i << ' ' << j << '\n';
      i++, j--;
    } else
      j--, m++;
  }
}
Problem p02697 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
  }
}


Fixed submission:
#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++;
  }
}
Problem p02697 (C++)

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

int main() {
  ll N, M;
  cin >> N >> M;
  ll head = 2 * (M / 2) + 1;
  if (M % 2 == 0)
    return 1;
  rep(i, 1, M / 2 + 1) {
    cout << i << " " << head << endl;
    head--;
  }
  head = 2 * (M / 2) + 1 + 2 * (M + 1) / 2;
  rep(i, 1, (M + 1) / 2 + 1) {
    cout << i + 2 * (M / 2) + 1 << " " << head << endl;
    head--;
  }
  return 0;
}

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

int main() {
  ll N, M;
  cin >> N >> M;
  ll head = 2 * (M / 2) + 1;
  if (M % 2 == 0) {
    rep(i, 1, M / 2 + 1) {
      cout << i << " " << head << endl;
      head--;
    }
    head = 2 * (M / 2) + 1 + 2 * (M) / 2;
    rep(i, 1, (M) / 2 + 1) {
      cout << i + 2 * (M / 2) + 1 << " " << head << endl;
      head--;
    }
  } else {
    rep(i, 1, M / 2 + 1) {
      cout << i << " " << head << endl;
      head--;
    }
    head = 2 * (M / 2) + 1 + 2 * (M + 1) / 2;
    rep(i, 1, (M + 1) / 2 + 1) {
      cout << i + 2 * (M / 2) + 1 << " " << head << endl;
      head--;
    }
  }
  return 0;
}
Problem p02697 (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++)
#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;
  }
}

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;
  {
    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--;
    }
  }
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
#ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define FAST ;
#else
#define FAST                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ << ' ' <<
#define Fr(i, s, e) for (auto i = s; i < e; ++i)
#define All(v) v.begin(), v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 998'244'353;

signed main() {
  FAST;

  int n, m;
  cin >> n >> m;
  assert(n % 2);
}


Fixed submission:
#ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define FAST ;
#else
#define FAST                                                                   \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ << ' ' <<
#define Fr(i, s, e) for (auto i = s; i < e; ++i)
#define All(v) v.begin(), v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 998'244'353;

signed main() {
  FAST;

  int n, m;
  cin >> n >> m;
  Fr(i, 0, m / 2) cout _ i + 1 _ m / 2 * 2 + 1 - i _ endl;
  Fr(i, 0, (m + 1) / 2) cout _ m / 2 * 2 + 2 + i _ m * 2 + 1 - i _ endl;
}
Problem p02697 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())

sieve = [0] * (100000 + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, 100000 + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, 100000 + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

p = []
for i in range(N - 1, -1, -1):
    if sieve[i] == i:
        p.append(i)
p.append(1)

t = set()
pp = 0
for i in range(M):
    x = i + 1
    y = x + p[pp]
    while y in t:
        pp += 1
        y = x + p[pp]
    t.add(x)
    t.add(y)
    print(x, y)
    pp += 1


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

for i in range(1, M + 1):
    if i % 2 == 1:
        j = (i - 1) // 2
        print(1 + j, M + 1 - j)
    else:
        j = (i - 2) // 2
        print(M + 2 + j, 2 * M + 1 - j)
Problem p02697 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())
a, b = n, 1
V = [False for d in range(1, m + 2)]
for i in range(m):
    d = min(a - b, n - (a - b))
    if 2 * d == n or V[d]:
        a -= 1
    print(a, b)
    d = min(a - b, n - (a - b))
    V[d] = True
    a -= 1
    b += 1


Fixed submission:
n, m = map(int, input().split())
a, b = n, 1
V = [False for d in range(1, n + 1)]
for i in range(m):
    d = min(a - b, n - (a - b))
    if 2 * d == n or V[d]:
        a -= 1
    print(a, b)
    d = min(a - b, n - (a - b))
    V[d] = True
    a -= 1
    b += 1
Problem p02697 (C++)

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

typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;

  if (n % 2) {
    int dif = 1;
    int pivot = n / 2;
    for (int i = 0; i < m; i++) {
      cout << pivot << " " << pivot + dif << endl;
      pivot--;
      dif += 2;
    }
  } else {
    vector<bool> used(n + 1, false);
    int dif = 0;
    int pivot = 0;
    for (int i = 0; i < m; i++) {
      pivot = pivot % n + 1;
      int l = pivot;
      int r = (pivot + dif) % n + 1;
      if (used[l] || used[r]) {
        i--;
        continue;
      }
      cout << l << " " << r << endl;
      used[l] = true;
      used[r] = true;
      dif++;
    }
  }

  return 0;
}

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

typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;

  if (n % 2) {
    int dif = 1;
    int pivot = n / 2;
    for (int i = 0; i < m; i++) {
      cout << pivot << " " << pivot + dif << endl;
      pivot--;
      dif += 2;
    }
  } else {
    int dif = 1;
    int pivot = n / 2;
    int i = 0;
    for (; i < m; i++) {
      if (i >= n / 4)
        break;
      cout << pivot << " " << pivot + dif << endl;
      pivot--;
      dif += 2;
    }
    dif++;
    for (; i < m; i++) {
      cout << pivot << " " << pivot + dif << endl;
      pivot--;
      dif += 2;
    }
  }

  return 0;
}
Problem p02697 (C++)

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

using namespace std;

int m, n, tr, cnta, cntb;
int a[50005], b[50005];

int lo(int start, int step) { return (start + step + n - 1) % n + 1; }

int main() {
  cin >> n >> m;
  cnta = 1;
  cntb = n;
  for (int i = 0; i < m; i++) {
    if (i % 2 == 0) {
      a[i] = cnta;
      b[i] = lo(cnta, m - i);
      cnta++;
    } else {
      a[i] = cntb;
      b[i] = lo(cntb, i - m);
      cntb--;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << a[i] << ' ' << b[i] << endl;
  }
  return 0;
}

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

using namespace std;

int m, n, tr, cnta, cntb;
int a[100005], b[100005];

int lo(int start, int step) { return (start + step + n - 1) % n + 1; }

int main() {
  cin >> n >> m;
  cnta = 1;
  cntb = n;
  for (int i = 0; i < m; i++) {
    if (i % 2 == 0) {
      a[i] = cnta;
      b[i] = lo(cnta, m - i);
      cnta++;
    } else {
      a[i] = cntb;
      b[i] = lo(cntb, i - m);
      cntb--;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << a[i] << ' ' << b[i] << endl;
  }
  return 0;
}
Problem p02697 (C++)

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VP vector<pair<int, int>>
#define VPP vector<pair<int, pair<int, int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)
typedef pair<int, int> P;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;

int main() {

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

  if (n % 2 == 1) {
    REP(i, m) { cout << i + 1 << ' ' << m * 2 - i << endl; }
  } else {
    assert(n == 0);
    REP(i, m) { cout << i + 1 << ' ' << n - i << endl; }
  }
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VP vector<pair<int, int>>
#define VPP vector<pair<int, pair<int, int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)
typedef pair<int, int> P;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;

int main() {

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

  if (n % 2 == 1) {
    REP(i, m) { cout << i + 1 << ' ' << m * 2 - i << endl; }
  } else {
    if (m % 2 == 0) {
      REP(i, m / 2) { cout << i + 1 << ' ' << m - i << endl; }
      REP(i, m / 2) { cout << m + 2 + i << ' ' << m * 2 + 2 - i << endl; }
    } else {
      REP(i, m / 2 + 1) { cout << i + 1 << ' ' << m + 1 - i << endl; }
      REP(i, m / 2) { cout << m + 3 + i << ' ' << m * 2 + 2 - i << endl; }
    }
  }
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define MOD 1000000007
signed main() {
  SPEED;
  int n, m;
  cin >> n >> m;
  int i = 1, j = 2 * m;
  assert(m % 2);
  for (int t = 0; t < m; t++) {
    cout << i << " " << j << endl;
    ++i;
    --j;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define MOD 1000000007
signed main() {
  SPEED;
  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    int i = 1, j = 2 * m;
    for (int t = 0; t < m; t++) {
      cout << i << " " << j << endl;
      ++i;
      --j;
    }
  } else {
    int i = 1, j = n, f = 1;
    for (int t = 0; t < m; ++t) {
      if (t >= n / 4 && f == 1) {
        --j;
        f = -1;
      }
      cout << i << " " << j << endl;
      ++i;
      --j;
    }
  }
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int, int>
#define int long long
#define endl '\n'
#define pll pair<long long, long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  if (n & 1) {
    n--;
    for (int i = 0; i < m; i++) {
      cout << i + 1 << " " << n - i << endl;
    }
  } else {
    assert(false);
  }
  return 0;
}


Fixed submission:
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int, int>
#define int long long
#define endl '\n'
#define pll pair<long long, long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  if (n & 1) {
    n--;
    for (int i = 0; i < m; i++) {
      cout << i + 1 << " " << n - i << endl;
    }
  } else {

    for (int i = 0; i < m; i++) {
      if (i < (m + 1) / 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>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(x, a) for (auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001;          // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N, M;
ll ret = 0;
string s;

int main(void) {

  IN(N);
  IN(M);

  vl arr(N + 1, 0);
  ll left = 1;
  ll right;
  FOR(i, 1, M + 1) {
    right = left + i;
    cout << left << " " << right << endl;
    arr[left] = 1;
    arr[right] = 1;
    while (left < N + 1 && arr[left] == 1) {
      left++;
    }
  }
}


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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(x, a) for (auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001;          // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N, M;
ll ret = 0;
string s;

int main(void) {

  IN(N);
  IN(M);

  ll l = 1;
  ll r = l + (M % 2 == 1 ? M : M - 1);
  while (r > l) {
    cout << l << " " << r << endl;
    l++;
    r--;
  }
  r = 2 * M + 1;
  l = r - (M % 2 == 0 ? M : M - 1);
  while (r > l) {
    cout << l << " " << r << endl;
    l++;
    r--;
  }
}
Problem p02697 (C++)

Buggy submission (status: Runtime Error):
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define BOLT                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<array<int, 2>> ans;
  if (n & 1) {
    int a = 1, b = n / 2;
    while (a < b) {
      ans.pb({a, b});
      a++;
      b--;
    }
    a = n / 2 + 1, b = n - 1;
    while (a < b) {
      ans.pb({a, b});
      a++;
      b--;
    }
  } else {
    int a = 1, b = n;
    while (a < b) {
      ans.pb({a, b});
      a++;
      b--;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i][0] << " " << ans[i][1] << endl;
  }
}
int32_t main() {
  BOLT;
  solve();
}

Fixed submission:
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define BOLT                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<array<int, 2>> ans;
  if ((n & 1) ^ 1) {
    int a = 1, b = n / 2;
    while (a < b) {
      ans.pb({a, b});
      a++;
      b--;
    }
    a = n / 2 + 1, b = n - 1;
    while (a < b) {
      ans.pb({a, b});
      a++;
      b--;
    }
  } else {
    int a = 1, b = n;
    while (a < b) {
      ans.pb({a, b});
      a++;
      b--;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i][0] << " " << ans[i][1] << endl;
  }
}
int32_t main() {
  BOLT;
  solve();
}
Problem p02697 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  int i = 1, j = (N + 1) / 2;
  int D = j - i - 1;
  vector<pair<int, int>> ans;
  while (i < j)
    ans.emplace_back(i++, j--);
  i = N - D, j = N;
  while (ans.size() < M)
    ans.emplace_back(i++, j--);
  assert(ans.size() == M);
  for (auto &[a, b] : ans)
    cout << a << " " << b << '\n';
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int i = 1, j = (N + 1) / 2;
  int D = j - i - 1;
  vector<pair<int, int>> ans;
  while (i < j)
    ans.emplace_back(i++, j--);
  i = N - D, j = N;
  while (ans.size() < M)
    ans.emplace_back(i++, j--);
  while (ans.size() > M)
    ans.pop_back();
  assert(ans.size() == M);
  for (auto &[a, b] : ans)
    cout << a << " " << b << '\n';
  return 0;
}
Problem p02697 (C++)

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int u[100005];

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, k;
  cin >> n >> k;
  if (n % 2 == 1) {
    for (int j = 1; j <= k; j++) {
      cout << j << " " << (2 * k + 1 - j) << endl;
    }
  } else {
    for (int i = k; i >= 1; i--) {
      for (int j = 1; j <= n; j++)
        if (!u[j] && !u[(j + i - 1) % n + 1]) {
          cout << j << " " << (j + i - 1) % n + 1 << endl;
          u[j] = 1;
          u[(j + i - 1) % n + 1] = 1;
          break;
        }
    }
  }
}


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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int u[100005];

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, k;
  cin >> n >> k;
  if (n % 2 == 1) {
    for (int j = 1; j <= k; j++) {
      cout << j << " " << (2 * k + 1 - j) << endl;
    }
  } else {
    int mx = 0;
    for (int j = 1, dist = k; dist > 0; j++, dist -= 2) {
      cout << j << " " << j + dist << endl;
      mx = max(mx, j + dist);
    }
    for (int j = mx + 1, dist = k - 1; dist > 0; j++, dist -= 2) {
      cout << j << " " << j + dist << endl;
    }
  }
}
Problem p02697 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())
if n % 2 == 1:
    for i in range(1, m + 1):
        print(i, n + 1 - i)
else:
    used = [False] * (n + 1)
    i = 1
    count = 0
    while count < m:
        while used[i]:
            i += 1
        print(i, i + count + 1)
        used[i] = True
        used[i + count + 1] = True
        count += 1


Fixed submission:
n, m = map(int, input().split())
if n % 2 == 1:
    for i in range(1, m + 1):
        print(i, n + 1 - i)
else:
    turning_point = (m + 1) // 2
    for i in range(1, turning_point + 1):
        print(i, n + 1 - i)
    for i in range(turning_point + 1, m + 1):
        print(i, n - i)
Problem p02697 (Python)

Buggy submission (status: Runtime Error):
import sys


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


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


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

    if N % 2 == 0:
        used = [False] * (N + 1)
        i = 0
        span = 1
        cnt = 0
        while cnt < M:
            cnt += 1
            while used[i]:
                i += 1
            print(i + 1, i + 1 + span)
            used[i] = True
            used[i + span] = True
            span += 1
    else:
        for i in range(M):
            print(i + 1, N - i)


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():
    N, M = map(int, input().split())

    if N % 2 == 0:
        for i in range(M):
            x = i + 1
            y = N - i - 1
            if y - x > (N - y + x):
                print(x, y)
            else:
                print(x, y - 1)
    else:
        for i in range(M):
            print(i + 1, N - i)


if __name__ == "__main__":
    main()