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

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using int64 = long long;

using namespace std;

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

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

  vector<pair<int, int>> ams;
  if (N % 2 == 1) {
    for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
      ams.emplace_back(lb, ub);
    }
  } else {
    bool flag = false;
    for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
      if (!flag && ub - lb <= N / 2) {
        flag = true;
        ub--;
      }
      ams.emplace_back(lb, ub);
    }
  }

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

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using int64 = long long;

using namespace std;

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

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

  vector<pair<int, int>> ams;
  if (N % 2 == 1) {
    for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
      ams.emplace_back(lb, ub);
    }
  } else {
    bool flag = false;
    for (int lb = 1, ub = N - 1; lb < ub; lb++, ub--) {
      if (!flag && ub - lb <= N / 2) {
        flag = false;
        ub--;
      }
      ams.emplace_back(lb, ub);
    }
  }

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

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

#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout << setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX * 0.99
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238

typedef pair<int, int> P;

signed main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  int cnt = 0;
  REP(i, min(N / 4, M)) {
    cout << i + 1 << " " << N / 2 - i << endl;
    cnt++;
  }
  if (cnt <= M) {
    if (((N / 2) % 2 == 0 && (N % 2 == 0)) ||
        ((N / 2) % 2 == 1 && (N % 2 == 0))) {
      REP(i, M - cnt) { cout << N / 2 + i + 1 << " " << N - i - 1 << endl; }
    } else {
      REP(i, M - cnt) { cout << N / 2 + i + 1 << " " << N - i << endl; }
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout << setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX * 0.99
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238

typedef pair<int, int> P;

signed main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  vector<bool> flag(N, 0);
  int cnt = 0;
  REP(i, N) {
    if (flag[i] == false) {
      cout << i + 1 << " " << i + cnt + 2 << endl;
      flag[i] = true;
      flag[i + cnt + 1] = true;
      cnt++;
    }
    if (cnt == M)
      break;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

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

  int i = (M + 1) / 2, j = N - M / 2 + 1, k = 0;
  while (M > 0) {
    k++;
    if (k % 2 == 1) {
      cout << i << " " << i + k << endl;
      i--;
    } else {
      cout << j << " " << j - k << endl;
      j++;
    }
    M--;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  int N, M;
  cin >> N >> M;
  vector<bool> p(N, true);

  int i = 0, j = 1;
  while (M > 0) {

    while (!(p[i % N] && p[(i + j) % N]))
      i++;
    i %= N;
    int k = (i + j) % N;
    cout << i + 1 << " " << k + 1 << endl;
    p[i] = false;
    p[k] = false;
    j++;
    M--;
  }
}
Problem p02697 (C++) — buggy submission, verdict: 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);

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


Error: WA

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

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
#define int LL
const int mo = 1e9 + 7;
typedef pair<int, int> pii;
#define gc() getchar()
template <typename _T> void read(_T &x) {
  _T f = 1;
  x = 0;
  char s = gc();
  while (s > '9' || s < '0') {
    if (s == '-')
      f = -1;
    s = gc();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = gc();
  }
  x *= f;
}
template <typename _T> _T Fabs(_T x) { return x < 0 ? -x : x; }
int n, m, vis[300005];
signed main() {
  read(n);
  read(m);
  int l = 1, r = n;
  while (m) {
    // printf("%d %d %d\\n",l,r,n-r+2);
    if (!vis[r] && !vis[n - r + 2] && r != n - r + 2)
      printf("%lld %lld\\n", l, l + r - 1), vis[r] = vis[n - r + 2] = 1, m--,
                                           l++, r--;
    r--;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
#define int LL
const int mo = 1e9 + 7;
typedef pair<int, int> pii;
#define gc() getchar()
template <typename _T> void read(_T &x) {
  _T f = 1;
  x = 0;
  char s = gc();
  while (s > '9' || s < '0') {
    if (s == '-')
      f = -1;
    s = gc();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = gc();
  }
  x *= f;
}
template <typename _T> _T Fabs(_T x) { return x < 0 ? -x : x; }
int n, m, vis[200005];
signed main() {
  read(n);
  read(m);
  int l = 1, r = n;
  while (m) {
    if (!vis[r - l + 1 + n])
      printf("%lld %lld\\n", l, r), m--;
    vis[r - l + 1 + n] = 1;
    r--;
    l++;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i, m, n) for (ll(i) = (m), (i_len) = (n); (i) < (i_len); ++(i))
#define FORR(i, v) for (auto(i) : v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)), greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

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

  if (N % 2 == 0) {
    ll B = (N + 2) / 2;
    ll W = N - 1;
    ll left = 0, right = N - 2, cnt = 0;
    while (W > B && cnt < M) {
      cout << left + 1 << " " << right + 1 << endl;
      ++left;
      --right;
      W = right - left + 1;
      ++cnt;
    }
    --right;
    while (cnt < M) {
      cout << left + 1 << " " << right + 1 << endl;
      ++left;
      --right;
      ++cnt;
    }
  } else {
    ll left = 0, right = N - 2, cnt = 0;
    while (cnt < M) {
      cout << left + 1 << " " << right + 1 << endl;
      ++left;
      --right;
      ++cnt;
    }
  }
  return 0;
}

/*






*/

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i, m, n) for (ll(i) = (m), (i_len) = (n); (i) < (i_len); ++(i))
#define FORR(i, v) for (auto(i) : v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)), greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

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

  vector<bool> F(N);
  ll left = 0, right = 1, cnt = 1;
  REP(i, 0, M) {
    cout << left + 1 << " " << right + 1 << endl;
    F[left] = true;
    F[right] = true;
    ++cnt;
    while (F[left])
      ++left;
    right = left + cnt;
  }

  return 0;
}

/*






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

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

// #include <stack>
// #include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;
ll visit[1000010] = {};

int main() {

  cin >> N;
  cin >> M;
  if (M == 1) {
    cout << 1 << " " << 2 << endl;
  } else {
    ll left = 1;
    ll bet = M - 2;
    ll right = left + bet + 1;

    ll left2 = right + 1;
    bet++;
    ll right2 = left2 + bet + 1;
    ll mi = 0;
    while (mi < M) {
      cout << left << " " << right << endl;
      left++;
      right--;
      if (left >= right) {
        left = left2;
        right = right2;
      }

      mi++;
    }
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

// #include <stack>
// #include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;
ll visit[100001] = {};

int main() {

  cin >> N;
  cin >> M;

  if (N % 2 == 1) {
    rep(mi, M) {
      ll left;
      ll right;
      left = mi + 1;
      right = N - (left - 1);
      cout << left << " " << right << endl;
    }

  } else {
    ll left = 1;
    ll bet = 1;
    rep(mi, M) {
      while (visit[left] == 1) {
        left++;
      }
      ll right = left + bet;
      visit[right] = 1;
      visit[left] = 1;
      cout << left << " " << right << endl;
      bet++;
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: 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) ^ 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();
}

Error: WA

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) {
    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, verdict: Runtime Error

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

int main() {
  int n, m, c = 0;
  cin >> n >> m;
  rep(i, m) {
    int a = i + 1, b = n - i - c;
    if (b - a <= n / 2 && n % 2 == 0 && c == 0) {
      c = 1;
      --b;
    }
    cout << a << " " << b << "\\n";
  }
  return 0;
}


Error: 255

Fixed submission:

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

int main() {
  int n, m, c = 0;
  cin >> n >> m;
  if (n % 2 == 0)
    return -1;
  rep(i, m) {
    int a = i + 1, b = n - i - c;
    if (b - a < n / 2 && n % 2 == 0 && c == 0) {
      c = 1;
      --b;
    }
    cout << a << " " << b << "\\n";
  }
  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;
  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;
}


Error: WA

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--);
  assert(ans.size() == M);
  for (auto &[a, b] : ans)
    cout << a << " " << b << '\\n';
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); i++)

using namespace std;

typedef long long ll;

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

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

  int l = 1;
  int r = (m + 1) / 2 * 2;
  rep(i, (m + 1) / 2) {
    cout << l << " " << r << "\\n";
    l++;
    r--;
  }

  l = (m + 1) / 2 * 2 + 1;
  r = 2 * m + 1;
  rep(i, m / 2) {
    cout << l << " " << r << "\\n";
    l++;
    r--;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); i++)

using namespace std;

typedef long long ll;

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

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

  if (n % 2 == 0) {
    int r = n - 1;
    int l;
    vector<bool> used(n, false);
    rep(i, m) {
      l = r - i - 1;
      while (used[l] || used[r]) {
        r--;
        l--;
      }

      cout << (l + 1) << " " << (r + 1) << "\\n";
      used[l] = true;
      used[r] = true;
    }
  } else {
    rep(i, m) { cout << (i + 1) << " " << (n - i - 1) << "\\n"; }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 2019;

int gcd(int x, int y) {
  if (x < y)
    swap(x, y);
  int r = x % y;
  if (r == 0) {
    return y;
  }
  return gcd(y, r);
}

ll mypow(ll x, ll n) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return mypow(((x % mod) * (x % mod)) % mod, n / 2);
  else
    return ((x % mod) * mypow(((x % mod) * (x % mod)) % mod, (n - 1) / 2)) %
           mod;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> ab(M);
  bool flag = false;
  for (int r = 1, l = N - 1, i = 0; i < M; r++, l--, i++) {
    if (!flag && N % 2 == 0 && l - r <= N / 2) {
      l--;
      flag = true;
    }
    ab.at(i).first = r + 1;
    ab.at(i).second = l + 1;
  }
  for (auto p : ab) {
    cout << p.first << " " << p.second << endl;
  }
}

Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 2019;

int gcd(int x, int y) {
  if (x < y)
    swap(x, y);
  int r = x % y;
  if (r == 0) {
    return y;
  }
  return gcd(y, r);
}

ll mypow(ll x, ll n) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return mypow(((x % mod) * (x % mod)) % mod, n / 2);
  else
    return ((x % mod) * mypow(((x % mod) * (x % mod)) % mod, (n - 1) / 2)) %
           mod;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> ab(M);
  for (int r = 1, l = N - 1; r < l; r++, l--) {
    if (N % 2 == 0 && l - r == N / 2)
      l--;
    ab.at(r - 1).first = r + 1;
    ab.at(r - 1).second = l + 1;
  }
  for (auto p : ab) {
    cout << p.first << " " << p.second << endl;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(), (v).end())
typedef int64_t lint;
// lint mod = 998244353;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

void app() {
  int n, m;
  cin >> n >> m;

  if (n % 2 == 1) {
    rep(i, m) { cout << (i + 1) << " " << (n - i) << "\\n"; }
    return;
  }

  rep(i, m) {
    if (i == n / 4)
      break;
    cout << (i + 1) << " " << (n - i) << "\\n";
  }
  rep_range(i, n / 4, m) { cout << (i + 2) << " " << (n - i) << "\\n"; }
}

int main() {
  app();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(), (v).end())
typedef int64_t lint;
// lint mod = 998244353;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

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

  rep(i, m) { cout << (i + 1) << " " << (n - i) << endl; }
}

int main() {
  app();
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: 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 {
    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;
    }
  }
}


Error: WA

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