alexjercan/bugnet huggingface dataset:
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

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


Error: WA

Fixed submission:

#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
  int N, M;
  cin >> N >> M;
  if (N % 2 == 0 && (N + 1 - N / 2) % 2 == 0) {
    assert(false);
  } else {
    for (int i = 1; i <= M; ++i)
      cout << i << " " << (N + 1 - i) << endl;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: 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 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();
  }
}

Error: WA

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

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

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

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

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

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

Error: WA

Fixed submission:

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

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

  vector<bool> checked(N + 1, false);
  for (int i = M; i > 0; i--) {
    for (int ai = 1; ai <= N; ai++) {
      int bi = ai + i;
      if (!checked.at(ai) && !checked.at(bi)) {
        printf("%d %d\\n", ai, bi);
        checked.at(ai) = checked.at(bi) = true;
        break;
      }
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
public:
  bool vis[11][11];
  void solve() {
    // int n = 10;
    // vector<int> a(n), b(4);
    // for (int i = 0; i < n; ++i) a[i] = i;
    // b[0] = 8;
    // b[1] = 7;
    // b[2] = 6;
    // b[3] = 5;
    // for (int i = 0; i < n; ++i) {
    //   for (int j : a) cout << j << " ";
    //   cout << endl;
    //   for (int j = 0; j < 4; ++j) {
    //     int x = a[j], y = a[b[j]];
    //     cout << x << "---" << y << endl;
    //     if (vis[x][y]) {
    //       cout << "no";
    //       return;
    //     }
    //     vis[x][y] = vis[y][x] = 1;
    //   }
    //   cout << "*****\\n";
    //   int a0 = a[0];
    //   for (int j = 0; j < n - 1; ++j) {
    //     a[j] = a[j + 1];
    //   }
    //   a.back() = a0;
    // }
    int n, m;
    cin >> n >> m;
    int len1 = m / 2, len2 = m - len1;
    int l = 1, r = len2 * 2;
    while (l < r) {
      cout << l << " " << r << '\\n';
      ++l, r--;
    }
    l = len2 * 2 + 1, r = l + len1 * 2;
    assert(r <= n);
    while (l < r) {
      cout << l << " " << r << '\\n';
      ++l, r--;
    }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
public:
  bool vis[11][11];
  void solve() {
    // int n = 10;
    // vector<int> a(n), b(4);
    // for (int i = 0; i < n; ++i) a[i] = i;
    // b[0] = 8;
    // b[1] = 7;
    // b[2] = 6;
    // b[3] = 5;
    // for (int i = 0; i < n; ++i) {
    //   for (int j : a) cout << j << " ";
    //   cout << endl;
    //   for (int j = 0; j < 4; ++j) {
    //     int x = a[j], y = a[b[j]];
    //     cout << x << "---" << y << endl;
    //     if (vis[x][y]) {
    //       cout << "no";
    //       return;
    //     }
    //     vis[x][y] = vis[y][x] = 1;
    //   }
    //   cout << "*****\\n";
    //   int a0 = a[0];
    //   for (int j = 0; j < n - 1; ++j) {
    //     a[j] = a[j + 1];
    //   }
    //   a.back() = a0;
    // }
    int n, m;
    cin >> n >> m;
    int len1 = m / 2, len2 = m - len1;
    int l = 1, r = len2 + 1 + 1;
    while (l < r) {
      cout << l << " " << r << '\\n';
      ++l, r--;
    }
    l = len2 + 1 + 1 + 1, r = l + len1;
    assert(r <= n);
    while (l < r) {
      cout << l << " " << r << '\\n';
      ++l, r--;
    }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: WA

Fixed submission:

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

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

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<P> ans;
  if (n % 2) {
    for (ll l = 1, r = n - 1; l < r; l++, r--) {
      ans.push_back(P(l, r));
    }
  } else {
    for (ll l = 1, r = n - 1; l < r; l++, r--) {
      if (r - l > n / 2)
        ans.push_back(P(l, r));
      else
        ans.push_back(P(l, r - 1));
    }
  }
  rep(i, m) cout << ans[i].first << " " << ans[i].second << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  ll n, m;
  cin >> n >> m;
  ll cnt = 1;
  vector<P> ans;
  vector<bool> used(n, false);
  ll l = 0;
  ll r = n - 1;
  while (ans.size() != m) {
    for (ll i = l; i <= r; i++) {
      if (!used[i] && !used[(i + cnt) % n]) {
        used[i] = true;
        used[(i + cnt) % n] = true;
        ans.push_back(make_pair(min(i, (i + cnt) % n), max(i, (i + cnt) % n)));
        cnt++;
        break;
      }
    }
    while (used[l])
      l++;
    while (used[r])
      r--;
  }
  rep(i, m) { cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl; }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = int(n); i < i##_len; ++i)
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define All(x) (x).begin(), (x).end()
#define rAll(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = int(n); i < i##_len; ++i)
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define All(x) (x).begin(), (x).end()
#define rAll(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
  int N, M;
  cin >> N >> M;
  if (N & 1) {
    REP(i, M) { cout << i + 1 << " " << N - i << endl; }
  } else {
    vector<bool> used(N + 1, false);
    int Left = 1, minus = 1;
    REP(i, M) {
      while (used[Left]) {
        Left++;
      }
      cout << Left << " " << Left + minus << endl;
      used[Left] = true;
      used[Left + minus] = true;
      minus++;
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main() {
#ifdef _DEBUG
  freopen("input1.txt", "r", stdin);
  freopen("output2.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 1; i <= m; i++) {
      cout << i << " " << n - i + 1 << "\\n";
    }
  } else {
    int diff = n - 1;
    vector<int> used(n);
    for (int i = 1; i <= m; i++) {
      used[n - diff] = 1;
      if (!used[diff]) {
        cout << i << " " << i + diff << "\\n";
      } else {
        diff--;
        cout << i << " " << i + diff << "\\n";
      }
      diff -= 2;
    }
  }
}

Error: 255

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main() {
#ifdef _DEBUG
  freopen("input1.txt", "r", stdin);
  freopen("output2.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 1; i <= m; i++) {
      cout << i << " " << n - i + 1 << "\\n";
    }
  } else {
    return -1;
    int l = n / 2;
    int r = n / 2 + 1;
    for (int i = 1; i <= m; i++) {
      if (r - l == n / 2)
        l--;
      cout << l << " " << r << "\\n";
      l--;
      r++;
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main(void) {
  int n, m, f, e;

  scanf("%d %d", &n, &m);

  for (f = 1, e = m; f < e; f++, e--)
    printf("%d %d\\n", f, e);
  for (f = m + 1, e = 2 * m + 1; f < e; f++, e--)
    printf("%d %d\\n", f, e);
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <stdio.h>
using namespace std;

bool what[111111];

int main(void) {
  int n, m, i;

  scanf("%d %d", &n, &m);

  if (n % 2) {
    int front = 1, end = n - 1;
    for (i = 1; i <= m; i++) {
      printf("%d %d\\n", front, end);
      front++, end--;
    }
  } else {
    int front = 1, end = n;
    for (i = 1; i <= min(n / 4, m); i++) {
      printf("%d %d\\n", front, end);
      what[front] = what[end] = true;
      front++, end--;
    }

    if (m > n / 4) {
      int cnt = 1, tmp = 0;
      for (i = n / 4 + 1; i <= n - n / 4 - 1; i++) {
        if (what[i] || what[i + cnt * 2])
          continue;
        printf("%d %d\\n", i, i + cnt * 2);
        tmp++;
        if (tmp == m - n / 4)
          return 0;
        what[i] = what[i + cnt * 2] = true;
        ++cnt;
      }
    }
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

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

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()

/* do your best */

int main() {

  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int l = 1, r = n - 1; l <= m; l++, r--) {
      cout << l << " " << r << endl;
    }
  } else {
    for (int l = 1, r = n - 1; l <= m; l++, r--) {
      if (r - l <= n / 2) {
        cout << l << " " << r - 1 << endl;
      } else {
        cout << l << " " << r << endl;
      }
    }
  }
  return 0;
}


Error: -6
1f6d11ea-d343-4b0e-a077-8bcb801906f7.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02697/C++/s820824949.cpp:47: int main(): Assertion `false' failed.


Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

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

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()

/* do your best */

int main() {

  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 0; i < m; i++) {
      cout << i + 1 << " " << n - i << endl;
    }
  } else {
    assert(false);
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M; // 2M+1 <= N <= 1e5
  vector<pair<int, int>> diffPairs(M);
  // for (int i = 0; i < M; ++i)
  //{
  //     diffPairs[i] = { i, N - i };
  // }

  vector<pair<int, int>> pairs;
  vector<bool> canUse(N, true);
  int diff = N - 1;
  int start = 0;
  for (int rem = M; rem > 0;) {
    for (int i = 0; i < N; ++i) {
      int s = (start + i) % N;
      int e = (start + diff + i) % N;
      if (canUse[s] && canUse[e]) {
        pairs.push_back({s + 1, e + 1});
        canUse[s] = canUse[e] = false;
        --rem;
        --diff;
        start = (start + 2) % N;
        break;
      }
    }
  }
  for (int i = 0; i < M; ++i) {
    cout << pairs[i].first << ' ' << pairs[i].second << endl;
  }
}
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++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
int s[300000] = {};

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
int s[200000] = {};

int main() {
  int N, M;
  cin >> N >> M;
  int p = 1;
  rep(i, M) {
    while (1) {
      if (s[p] != 0) {
        p++;
      } else {
        break;
      }
    }
    cout << p << " " << p + i + 1 << endl;
    s[p] = 1;
    s[p + i + 1] = 1;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n + 5);
  vector<int> dfs(n + 5);
  int mn = 1;
  int j = 1;
  for (int i = n - 1; i >= 1 && m--; i--) {
    while (v[j + i])
      i--;
    while (dfs[n - (i)] || i == n - i)
      i--;
    cout << j << ' ' << j + i << '\\n';
    dfs[i] = 1;
    v[j] = v[j + i] = 1;
    if (m == 0)
      break;
    while (j <= n && v[j])
      j++;
  }
  return 0;
}
/***
32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

6
2 3 3 1 3 1
*/


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n + 5);
  int mn = 1;
  int j = 1;
  for (int i = 1; i <= n && m--; i++) {
    cout << j << ' ' << j + i << '\\n';
    v[j] = v[j + i] = 1;
    if (m == 0)
      break;
    while (j <= n && v[j])
      j++;
  }
  return 0;
}
/***
32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

6
2 3 3 1 3 1
*/
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> // minmax, sort, swap
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>     // printf, scanf
#include <deque>      // deque
#include <functional> // function<void(int)>
#include <iomanip>    // cout<<setprecision(n)
#include <iostream>   // cin, cout, cerr
#include <map>        // key-value pairs sorted by keys
#include <numeric>    // iota
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>
#include <string> // string, stoi, to_string
#include <vector> // vector

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\\n'
#define rep(i, n) for (int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int>>;
const int INF = 1e17;
/* libraries */

signed main() {
  int n, m;
  std::cin >> n >> m;
  int x = 0;
  std::vector<int> used(n, false);
  for (int i = m; i > 0; i--) {
    if (used[x % n]) {
      x++;
      debug(x);
    }
    std::cout << i << ' ' << i + x + 1 << EL;
    x += 2;
    used[(n - 2 - x + n) % n] = true;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm> // minmax, sort, swap
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>     // printf, scanf
#include <deque>      // deque
#include <functional> // function<void(int)>
#include <iomanip>    // cout<<setprecision(n)
#include <iostream>   // cin, cout, cerr
#include <map>        // key-value pairs sorted by keys
#include <numeric>    // iota
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>
#include <string> // string, stoi, to_string
#include <vector> // vector

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\\n'
#define rep(i, n) for (int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int>>;
const int INF = 1e17;
/* libraries */

signed main() {
  int n, m;
  std::cin >> n >> m;
  int x = 0;
  std::vector<int> used(n, false);
  for (int i = m; i > 0; i--) {
    if (used[x]) {
      x++;
      debug(x);
    }
    std::cout << i << ' ' << i + x + 1 << EL;
    x += 2;
    used[n - 2 - x] = true;
  }
  return 0;
}