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

#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int main() {
  scanf("%d %d", &n, &m);
  if (n % 2 == 0) {
    int m2 = m / 2;
    int m1 = m - m2;
    for (int i = 1; i <= m1; ++i) {
      std::cout << i << " " << m1 * 2 + 1 - i << std::endl;
    }

    int d = m1 * 2;
    for (int i = 1; i <= m2; ++i) {
      std::cout << d + i << " " << d + m2 * 2 + 2 - i << std::endl;
    }
  } else {
    for (int i = 1; i <= m; i++)
      printf("%d %d\\n", i, n - (n % 2 == 0) - i + 1);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int main() {
  scanf("%d %d", &n, &m);
  if (n % 2 == 0) {
    for (int i = 1; i < m; i++) {
      printf("%d %d\\n", i, n - i - 1);
    }
    printf("%d %d\\n", n - 1, n);
  } else {
    assert(0);
    for (int i = 1; i <= m; i++)
      printf("%d %d\\n", i, n - i + 1);
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv) {
  int N, M;
  cin >> N >> M;
  int p1, p2;
  p1 = 1;
  p2 = N;
  bool f[N];
  REP(i, N) f[i] = false;

  REP(i, M) {
    cout << p1 << " " << p2 << endl;
    f[p2 - p1] = true;
    f[p1 + N - p2] = true;
    p1++;
    p2--;
    while (true) {
      if (f[p2 - p1] == true || f[p1 + N - p2] == true ||
          p2 - p1 == p1 + N - p2) {
        p2--;
      } else {
        break;
      }
    }
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv) {
  int N, M;
  cin >> N >> M;
  int p1, p2;
  p1 = 1;
  p2 = N;
  REP(i, M) {
    cout << p1 << " " << p2 << endl;
    p1++;
    p2--;

    if (i == M - 1)
      break;
    while (true) {
      int d1 = p2 - p1;
      int d2 = (p1 + N) - p2;
      if (d1 < d2) {
        int t = d1;
        d1 = d2;
        d2 = t;
      }
      if ((d1 % d2) == 0) {
        p2--;
      } else {
        break;
      }
      break;
    }
  }

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

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

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


Error: 9

Fixed submission:

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

int main(void) {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    if (n % 2)
      cout << i << " " << n - i + 1 << endl;
    else
      exit(9);
  }
  return (0);
}
Problem p02697 (C++) — buggy submission, verdict: 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;
  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;
}


Error: -6
6a94afd4-e624-47a8-b2ea-a38b1cab0c1f.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02697/C++/s908641400.cpp:29: int main(): Assertion `n%2' failed.


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

#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
ll n, m;
int main() {
  ll i;
  cin >> n >> m;
  if (n % 2 == 0) {
    for (i = 0; i < m; i++) {
      if (i <= m / 2 && i * 2 != m) {
        cout << i + 1 << " " << n - i << endl;
      } else {
        cout << i + 1 << " " << n - i - 1 << endl;
      }
    }
  } else {
    for (i = 0; i < m; i++) {
      cout << i + 1 << " " << n - i << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
ll n, m;
bool book[N];
int main() {
  ll i, j = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cout << j % n + 1 << " " << (j + i + 1) % n + 1 << endl;
    book[j] = true;
    book[(j + i) % n + 1] = true;
    while (book[j]) {
      j = j % n + 1;
    }
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
int n, m;
bool vis[nax];

int main() {

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

  if (n % 2 == 0) {

    /// lol
    /// the construction is really stupid....
    /// but I'm more stupid
    /// I laugh as if I was crazy when I figured out stupid pattern...

    int l = 1, r = n;

    bool turn = true;

    for (int i = m; i >= 1; --i, turn ^= 1) {

      if (turn) {
        printf("%d %d\\n", l, l + i);
        ++l;
      } else {
        printf("%d %d\\n", r, r - i);
        --r;
      }
    }

    return 0;
  }

  int r = n, l = 1;

  for (int i = 1; i <= m; ++i) {
    printf("%d %d\\n", l++, r--);
  }
}
/*
    Good Luck
        -Lucina
*/
/*
    I hate Progmeth
*/


Error: -6
terminate called without an active exception


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
int n, m;

int main() {

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

  if (n % 2 == 0)
    throw;

  int r = n, l = 1;

  for (int i = 1; i <= m; ++i) {
    printf("%d %d\\n", l++, r--);
  }
}
/*
    Good Luck
        -Lucina
*/
/*
    I hate Progmeth
*/
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read() {
  ll a = 0, b = getchar(), c = 1;
  while (!isdigit(b))
    c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b))
    a = a * 10 + b - '0', b = getchar();
  return a * c;
}
int n, m, x, y;
int main() {
  n = read(), m = read();
  x = m % 2 + m - 1, y = m - m % 2;
  int j = x + 2;
  for (int i = 1; x > 0 and m > 0; i++, x -= 2, m--)
    printf("%d %d\\n", i, i + x);
  for (; y > 1 and m > 0; j++, y -= 2, m--)
    printf("%d %d\\n", j, j + y);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read() {
  ll a = 0, b = getchar(), c = 1;
  while (!isdigit(b))
    c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b))
    a = a * 10 + b - '0', b = getchar();
  return a * c;
}
int n, m, x, a[100005];
int main() {
  cin >> n >> m;
  x = n;
  for (int i = 0; i < m; i++) {
    while (a[x - i])
      x--;
    a[x - i] = a[n - x + i] = 1;
    printf("%d %d\\n", i + 1, x);
    x--;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() { cout << "Yes\\n"; }
void No() { cout << "No\\n"; }
void YES() { cout << "YES\\n"; }
void NO() { cout << "NO\\n"; }

#include <vector>

/*	verified : 2020/07/18
                AOJ, Disjoint Set: Union Find Tree
                http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A
*/

struct union_find {
  long long N;                   // the number of nodes
  long long M;                   // the number of trees
  std::vector<long long> parent; // parent[i] := the direct parent of i
  std::vector<long long>
      size; // size[i] := the number of nodes in the tree rooted to i
  vector<ll> white_cnt;
  vector<ll> black_cnt;

  union_find(long long n) : N(n), M(n) {
    parent.resize(n, -1);
    size.resize(n, 1);
    white_cnt.resize(n, 0);
    black_cnt.resize(n, 0);
  }

  long long root(long long i) {
    if (parent[i] == -1)
      return i;
    else
      return parent[i] = root(parent[i]);
  }

  bool is_united(long long i, long long j) { return (root(i) == root(j)); }

  // true : unite succeeded
  bool unite(long long i, long long j) {
    i = root(i);
    j = root(j);
    if (i == j)
      return false;
    if (size[i] < size[j])
      std::swap(i, j);
    parent[j] = i;
    size[i] += size[j];
    white_cnt[i] += white_cnt[j];
    black_cnt[i] += black_cnt[j];
    M--;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // constexpr ll P = 1e9 + 7;
  // constexpr ll P = 998244353;

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(nullptr);
  // const ll p = 1e9 + 7;
  // const ll p = 998244353;

  ll n, m;
  cin >> n >> m;

  vector<bool> chk(n + 1, false);
  ll x = 1;
  for (ll i = 0; i < m; i++) {
    while (chk[x])
      x++;
    cout << x << " " << x + i + 1 << endl;
    chk[x] = true;
    chk[x + i + 1] = true;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
int lcm(int a, int b) { return a / __gcd(a, b) * b; }

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  tc = 1;
  // cin >> tc;
  while (tc--) {
    int n, m;
    cin >> n >> m;
    int l = 1, r = n;
    if (n % 2) {
      for (int i = 0; i < m; i++) {
        cout << l << " " << r << endl;
        l++;
        r--;
      }
    } else {
      int a[n];
      int l = n / 2, r = n / 2 + 1;
      int g = 1, h = n - 1;
      int k = 0;
      while (m) {
        if (k % 2 == 0) {
          cout << l << " " << r << endl;
          l--;
          r++;
        } else {
          cout << g << " " << h << endl;
          g++;
          h--;
        }
        k++;
        m--;
      }
    }
  }

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
int lcm(int a, int b) { return a / __gcd(a, b) * b; }

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  tc = 1;
  // cin >> tc;
  while (tc--) {
    int n, m;
    cin >> n >> m;
    int l = 1, r = n;
    set<int> se;
    for (int i = 1; i <= n; i++) {
      se.insert(i);
    }
    int ans = 1;
    for (int i = 0; i < m; i++) {
      if (se.size() == 0) {
        break;
      }
      auto j = se.begin();
      cout << *j << " ";
      int f = *j;
      se.erase(j);
      auto k = se.lower_bound(f + ans);
      cout << *k << " ";
      se.erase(k);
      ans++;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  set<int> s;
  for (int i = 1; i <= n; i++)
    s.insert(i);
  int i = 1;
  while (i <= m) {
    int front = *s.begin();
    int next = front + i;
    if (next > n) {
      next -= n;
    }
    if (s.find(next) == s.end()) {
      continue;
    }
    cout << front << ' ' << next << endl;
    s.erase(front);
    s.erase(next);
    i++;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define p_ pair<int, int>
#define mp_ make_pair
#define ll long long
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define show1(a) cout << #a << " = " << a << endl
#define show2(a, b) cout << #a << " = " << a << "; " << #b << " = " << b << endl
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int maxn = 2e5 + 5;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int vis[maxn];
int main() {
  fastio();
  int n, m, cnt = 0, l, r;
  cin >> n >> m;
  if (n % 2 == 0)
    n--;
  if (m & 1) {
    l = 1, r = n / 2;
    while (1) {
      if (cnt == m)
        return 0;
      if (l >= r)
        break;
      cout << l << " " << r << endl;
      l++, r--, cnt++;
    }
    l = n / 2 + 1, r = n % 2 == 0 ? n - 1 : n;
    while (1) {
      if (cnt == m)
        return 0;
      if (l >= r)
        break;
      cout << l << " " << r << endl;
      l++, r--, cnt++;
    }
  } else {
    l = 1, r = n / 2 + 1;
    while (1) {
      if (cnt == m)
        return 0;
      if (l >= r)
        break;
      cout << l << " " << r << endl;
      l++, r--, cnt++;
    }
    l = n / 2 + 2, r = n;
    while (1) {
      if (cnt == m)
        return 0;
      if (l >= r)
        break;
      cout << l << " " << r << endl;
      l++, r--, cnt++;
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define p_ pair<int, int>
#define mp_ make_pair
#define ll long long
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define show1(a) cout << #a << " = " << a << endl
#define show2(a, b) cout << #a << " = " << a << "; " << #b << " = " << b << endl
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int maxn = 2e5 + 5;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int vis[maxn];
int main() {
  fastio();
  int n, m, cnt = 0;
  ;
  cin >> n >> m;
  int now = n;
  while (1) {
    if (!vis[now] && !vis[now - cnt - 1]) {
      cout << now << " " << now - cnt - 1 << endl;
      vis[now] = vis[now - cnt - 1] = 1;
      cnt++;
    }
    now--;
    if (cnt == m)
      break;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error


#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() { cerr << endl; }

template <typename H, typename... T> void d_err(H h, T... t) {
  cerr << h << " ";
  d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9 + 7;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

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

  int c = 0;
  REP(i, M) {
    int a = i + 1;
    int b = N - i;

    if (N % 2 == 0 && b - a <= N - b + a)
      c = 1;

    cout << a << " " << b - c << endl;
  }
}


Error: 1

Fixed submission:


#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() { cerr << endl; }

template <typename H, typename... T> void d_err(H h, T... t) {
  cerr << h << " ";
  d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9 + 7;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);

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

  REP(i, M) {
    if (N % 2) {
      cout << i + 1 << " " << N - i << endl;
    } else {
      exit(1);
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

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

  int l = 1, r = N;
  vector<pii> ans;
  REP(i, M) {
    if (N % 2 == 0 && (N / 2 - 1) % 2 == 0 && r - l == N / 2)
      --r;
    ans.emplace_back(l, r);
    if (N % 2 == 0 && (N / 2 - 1) % 2 == 1 && r - l == N / 2 + 1)
      --r;
    ++l, --r;
  }
  for (pii cur : ans)
    printf("%d %d\\n", cur.fi, cur.se);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
  int N, M;
  cin >> N >> M;
  if (N & 1)
    REP(i, M) printf("%d %d\\n", i + 1, N - i);
  else {
    vector<int> done(N);
    vector<pii> ans;

    int p = 0, d = 1;
    while (ans.size() < M) {
      while (done[p] || done[(p + d) % N])
        p = (p + 1) % N;
      ans.emplace_back(p, p + d);
      done[p] = done[(p + d) % N] = true;
      ++d;
    }
    REP(i, M) printf("%d %d\\n", ans[i].fi + 1, ans[i].se + 1);
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long lint;

int ap[200009];

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

  int dr = n / 2;
  int st = 1;
  int dist = dr - st;
  dist = dist & 1;
  while (m > 0 && st < dr) {
    if (ap[st] == 0 && ap[dr] == 0)
      ap[st] = ap[dr] = 1;

    cout << st << " " << dr << "\\n";
    st++;
    dr--;
    m--;
  }

  st = n / 2 + 1;
  dr = n;
  if (((dr - st) & 1) == dist)
    dr--;

  while (m > 0 && st < dr) {
    if (ap[st] == 0 && ap[dr] == 0)
      ap[st] = ap[dr] = 1;

    cout << st << " " << dr << "\\n";
    st++;
    dr--;
    m--;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long lint;

int ap[100009];

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

  ap[1] = ap[2] = 1;
  cout << "1 2\\n";

  m--;
  int dist = 2;
  int st = 3;
  while (m > 0) {
    m--;

    while (ap[st] == 1 || ap[st + dist] == 1)
      st++;

    cout << st << " " << st + dist << "\\n";
    ap[st] = ap[st + dist] = 1;
    dist++;
  }

  return 0;
}