alexjercan/bugnet huggingface dataset:
Problem p02697 (C++) — buggy submission, verdict: 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 {
    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; }
    }
  }
}


Error: -6
4a223790-515c-4207-bd3d-7cd040de31ca.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02697/C++/s094347515.cpp:43: int main(): Assertion `n == 0' failed.


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 {
    assert(n == 0);
    REP(i, m) { cout << i + 1 << ' ' << n - i << endl; }
  }
}
Problem p02697 (C++) — buggy submission, verdict: 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;
  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;
    }
  }
}

Error: WA

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;
  int i = 1, j = 2 * m;
  assert(m % 2);
  for (int t = 0; t < m; t++) {
    cout << i << " " << j << endl;
    ++i;
    --j;
  }
}
Problem p02697 (C++) — buggy submission, verdict: 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 {

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


Error: -6
bf608b4c-8015-4cfe-80f8-43a1a37f0623.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02697/C++/s479002330.cpp:43: int32_t main(): Assertion `false' failed.


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 {
    assert(false);
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

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

const ll INF = 1LL << 61;

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

const ll mod = 1000000007;

int main() {
  ll n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 0; i < m; i++) {
      cout << i + 1 << " " << n - i - 1 << endl;
    }
  } else {
    vector<bool> dist(n + 1, false);
    for (int i = 0, j = 0; i < m; i++, j++) {
      auto left = i + 1;
      auto right = n - j - 1;
      while (true) {
        auto c1 = right - left;
        auto c2 = (left - right + n) % n;
        if (dist[c1] || dist[c2] || (c1 == c2)) {
          right--;
          j++;
        } else {
          dist[c1] = true;
          dist[c2] = true;
          break;
        }
      }
      cout << left << " " << right << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

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

const ll INF = 1LL << 61;

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

const ll mod = 1000000007;

int main() {
  ll n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 0; i < m; i++) {
      cout << i + 1 << " " << n - i - 1 << endl;
    }
  } else {
    vector<bool> dist(n + 1, false);
    for (int i = 0, j = 0; i < m; i++, j++) {
      auto left = i + 1;
      auto right = n - j;
      while (true) {
        auto c1 = right - left;
        auto c2 = (left - right + n) % n;
        if (dist[c1] || dist[c2] || (c1 == c2)) {
          right--;
          j++;
        } else {
          break;
        }
      }
      cout << left << " " << right << endl;
      dist[left] = true;
      dist[right] = true;
    }
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
static const int MAXN = 100000;
static const int MAX = 1000000007;

int N, M;

int main() {
  cin >> N >> M;
  vector<int> a(M), b(M);

  a[0] = 1;
  for (int i = 1; i < M; i++) {
    a[i] = a[i - 1] + 1;
  }
  b[0] = N;
  for (int i = 1; i < M; i++) {
    b[i] = b[i - 1] - 1;
  }

  if (N % 2 == 0) {
    for (int i = N / 4; i < M; i++) {
      b[i]--;
    }
  }

  rep(i, M) { cout << a[i] << " " << b[i] << endl; }

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
static const int MAXN = 100000;
static const int MAX = 1000000007;

int N, M;

int main() {
  cin >> N >> M;
  vector<int> a(M), b(M);
  a[0] = 1;
  for (int i = 1; i < M; i++) {
    a[i] = a[i - 1] + 1;
  }
  b[0] = N;
  for (int i = 1; i < M; i++) {
    b[i] = b[i - 1] - 1;
  }
  if (N % 2 == 0) {
    if ((N / 2 - (N / 4 + 1)) % 2 == 0) {
      b[N / 4] = N / 2;
    } else
      b[N / 4] = N / 2 + 1;
  }

  rep(i, M) { cout << a[i] << " " << b[i] << endl; }

  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  int odd = (m + 1) / 2;
  int even = m / 2;
  int cur = 1;

  for (int i = odd; i >= 1; i--) {
    printf("%d %d\\n", cur, cur + i * 2 - 1);
    cur++;
  }

  cur = n;
  for (int i = even; i >= 1; i--) {
    printf("%d %d\\n", cur - i * 2, cur);
    cur--;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

bool flag[200005];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  int p = 0;
  for (int i = 1; i <= m; i++) {
    while (flag[p] || flag[(p + i) % n])
      p = (p + 1) % n;
    printf("%d %d\\n", p + 1, (p + i) % n + 1);
    flag[p] = 1;
    flag[(p + i) % n] = 1;
  }
}
Problem p02697 (C++) — buggy submission, verdict: 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;

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

Error: WA

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;

  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;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

vector<pair<int, int>> pairs;

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

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

  for (int i = N, m = M; i > (N - (int)(M / 2) - (M % 2 == 0 ? 0 : 1));
       i--, m -= 2) {
    pairs.push_back(make_pair(i, i - m));
  }

  for (int i = 1, m = M - 1; i <= (int)(M / 2); i++, m -= 2) {
    pairs.push_back(make_pair(i, i + m));
  }

  for (int i = 0; i < pairs.size(); i++)
    cout << pairs[i].first << " " << pairs[i].second << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

const int N = 1e5 + 5;
int is_used[N];
vector<pair<int, int>> pairs;

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

  int N, M, diff = 1, i = 1;
  cin >> N >> M;

  while (pairs.size() != M) {
    for (; i <= N; i++) {
      if (!is_used[i]) {
        pairs.push_back(make_pair(i, i + diff));
        is_used[i] = 1;
        is_used[i + diff] = 1;
        diff++;
        break;
      }
    }
  }

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

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define P pair<int, int>
#define siz(s) (int)s.size()
#define pb push_back

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void cmps(vector<int> &v, int &i) { i = lower_bound(all(v), i) - v.begin(); }
constexpr int mod = 1e9 + 7;
constexpr int inf = 3e18;

int N, M;
signed main() {
  cin >> N >> M;
  if (N & 1) {
    rep(i, M) cout << i + 1 << " " << N - i << endl;
  } else {
    int l = 1, r = N;
    bool flag = false;
    rep(i, M) {
      if (r - l <= N / 2 && !flag) {
        r--;
        flag = true;
      }
      cout << l++ << " " << r-- << endl;
    }
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define P pair<int, int>
#define siz(s) (int)s.size()
#define pb push_back

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void cmps(vector<int> &v, int &i) { i = lower_bound(all(v), i) - v.begin(); }
constexpr int mod = 1e9 + 7;
constexpr int inf = 3e18;

int f(int a, int b, int x) { return (a * x / b) - a * (x / b); }
signed main() {
  int N, M;
  cin >> N >> M;
  if (M == 1) {
    cout << 1 << " " << 2 << endl;
    return 0;
  }
  int p = N - M, q = M;
  if ((p - q) % 2) {
    rep(i, M) cout << i + 1 << " " << 2 * M - i << endl;
  } else {
    exit(1);
    cout << 1 << " " << 2 * M + 1 << endl;
    REP(i, M) cout << i + 1 << " " << 2 * M - i << endl;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(v) (v).begin(), (v).end()

const int INF = 100000002;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pi> 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); }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(v) (v).begin(), (v).end()

const int INF = 100000002;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pi> ans;
  if (n % 2) {
    for (int l = 1, r = n - 1; r < 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].first); }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: WA

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  int k = 1, l = 2;
  vector<int> S(N + 1, 0);
  S.at(1) = 1;
  S.at(2) = 1;
  cout << 1 << " " << 2 << endl;
  for (int i = 2; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      if (S.at(j) == 0) {
        k = j;
        l = k + i;
        break;
      }
    }
    cout << k << " " << l << endl;
    S.at(k) = 1;
    S.at(l) = 1;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int n, m;
int dist(int x, int y) { return min(abs(x - y), n - abs(x - y)); }
int main() {
  cin >> n >> m;
  int half;
  if (m % 2 == 1) {
    half = n / 2 - 1;
  } else {
    half = n / 2;
  }
  int a = 0, b = half, c = half + 1, d = n - 1;
  if (n % 2 == 0)
    a++;

  rep(i, m) {
    if (a + 1 < b) {
      cout << a + 1 << " " << b + 1 << endl;
      cerr << dist(a + 1, b + 1) << endl;

      a++;
      b--;
    } else {
      cout << c + 1 << " " << d + 1 << endl;
      cerr << dist(c + 1, d + 1) << endl;

      c++;
      d--;
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int n, m;
int dist(int x, int y) { return min(abs(x - y), n - abs(x - y)); }
int main() {
  cin >> n >> m;
  VI tmp(n);
  rep(i, n) {
    if (i % 2 == 0) {
      tmp[i] = i / 2 + 1;
    } else {
      tmp[i] = n - i / 2;
    }
    cerr << tmp[i] << " ";
  }
  cerr << endl;
  reverse(ALL(tmp));
  vector<PII> ans;
  map<int, int> used;
  int pad = 0;
  rep(i, m) {
    assert(2 * (i + pad) + 1 < n);
    int x = tmp[2 * i];
    int y = tmp[2 * (i + pad) + 1];

    if (used[dist(x, y)]) {
      pad = 1;
    }
    x = tmp[2 * i];
    y = tmp[2 * (i + pad) + 1];
    ans.push_back({x, y});
    used[dist(x, y)] = true;
  }
  used.clear();
  map<int, bool> mm;
  for (auto &&x : ans) {
    cout << x.first << " " << x.second << endl;
    assert(x.first <= n && x.second <= n);
    assert(x.first != x.second);
    assert(n % 2 == 1 || dist(x.first, x.second) != n / 2);
    cerr << dist(x.first, x.second) << endl;
    assert(used[dist(x.first, x.second)] == false &&
           used[n - dist(x.first, x.second)] == false);
    used[dist(x.first, x.second)] = true;
    used[n - dist(x.first, x.second)] = true;
    assert(mm[x.first] == false && mm[x.second] == false);
    mm[x.first] = true;
    mm[x.second] = true;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if (n & 1)
    for (int i = 1; i <= m; i++)
      printf("%d %d\\n", i, n - i);
  else
    for (int i = 1; i <= m; i++)
      printf("%d %d\\n", i, n - i - (i >= (n + 3) / 4));
}

Error: WA

Fixed submission:

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

int main() {
  int n, m, c = 0;
  scanf("%d %d", &n, &m);
  vector<int> f(n, 1);
  for (int i = 0; i < n; i++) {
    if (f[i]) {
      c++;
      printf("%d %d\\n", i + 1, i + 1 + c);
      f[i] = 0, f[i + c] = 0;
    }
    if (c == m)
      break;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define db(x) cout << (x) << '\\n';
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<double, ll> pdi;
typedef pair<string, ll> psi;
typedef pair<ll, string> pls;
typedef pair<string, string> pss;
typedef pair<ll, pii> pip;
typedef pair<pii, pii> ppp;

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

  int n, m;
  cin >> n >> m;
  int p1 = (m + 1) / 2;
  int d = (p1 * 2) + 1;
  for (int i = 1; i <= m; i += 2) {
    cout << p1 << ' ' << p1 + i << '\\n';
    p1--;
  }

  for (int j = (m - (m & 1)); j >= 2; j -= 2) {
    cout << d << ' ' << d + j << '\\n';
    d++;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define db(x) cout << (x) << '\\n';
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<double, ll> pdi;
typedef pair<string, ll> psi;
typedef pair<ll, string> pls;
typedef pair<string, string> pss;
typedef pair<ll, pii> pip;
typedef pair<pii, pii> ppp;
#define MAXN 100005

bool mk[MAXN];

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

  int n, m;
  cin >> n >> m;
  int pos = 0;
  for (int i = 2; i <= m; i++) {
    while (mk[pos])
      pos++;
    mk[pos] = 1;
    mk[pos + i] = 1;
    cout << pos + 1 << ' ' << pos + i + 1 << '\\n';
  }

  for (int i = 0; i < n; i++)
    if (!mk[i] && !mk[i + 1]) {
      cout << i + 1 << ' ' << i + 2 << '\\n';
      break;
    }

  return 0;
}