alexjercan/bugnet huggingface dataset:
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;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  if (m % 2 == 0) {
    int c = m + 1, d = 1, i = 0;
    while (c - d > 0) {
      a[i] = d;
      b[i] = c;
      ++d;
      --c;
      ++i;
    }
    int e = m + 2, f = 2 * m + 1;
    while (f - e > 0) {
      a[i] = e;
      b[i] = f;
      ++e;
      --f;
      ++i;
    }
  } else {
    int c = m, d = 1, i = 0;
    while (c - d > 0) {
      a[i] = d;
      b[i] = c;
      ++d;
      --c;
      ++i;
    }
    int e = m + 1, f = 2 * m + 1;
    while (f - e > 0) {
      a[i] = e;
      b[i] = f;
      ++e;
      --f;
      ++i;
    }
  }
  rep(i, m) { cout << a[i] << " " << b.at(i) << "\\n"; }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  int c = (n + 1) / 2, d = 1, i = 0;
  while (c - d > 0) {
    a[i] = d;
    b[i] = c;
    ++d;
    --c;
    ++i;
  }
  int e = (n + 1) / 2 + 1, f = n;
  while (f - e > 0) {
    a[i] = e;
    b[i] = f;
    ++e;
    --f;
    ++i;
  }
  rep(i, m) { cout << a[i] << " " << b.at(i) << "\\n"; }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

  int n, m;
  cin >> n >> m;
  if (n & 1) {
    for (int i = 0; i < m; i++) {
      cout << i + 1 << ' ' << n - i << endl;
    }
  } else {
    for (int i = 0; i < m; i++) {
      if (i * 2 < (n - 2) / 2)
        cout << i + 1 << ' ' << n - i << endl;
      else
        cout << i + 1 << ' ' << n - i - 1 << endl;
    }
  }
  return 0;
}


Error: WA

Fixed submission:

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

  int n, m;
  cin >> n >> m;
  vector<bool> used(n + 1);

  for (int i = 1, j = 1; j <= m; i++, j++) {
    while (used[i])
      i++;
    cout << i << ' ' << i + j << endl;
    used[i] = used[i + j] = true;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    rep(i, m) { cout << n-- << " " << i + 2 << endl; }
    return 0;
  }

  int d = n / 2 - 1;
  int l = 1, r = l + d;
  vector<P> p;
  while (r > l) {
    p.emplace_back(l, r);
    l++;
    r--;
  }
  l = d + 3, r = n;
  while (m > p.size()) {
    p.emplace_back(l, r);
    l++;
    r--;
  }
  rep(i, m) cout << p[i].first << " " << p[i].second << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> used(n);
  int cnt = n / 2;
  int i = 0;
  while (cnt > 0) {

    int opo = i + cnt;
    if (opo > n - 1)
      opo -= n;
    if (used[i] == 1 || used[opo] == 1) {
      i++;
      if (i == n)
        i -= n;
      continue;
    }

    used[i] = 1;
    used[opo] = 1;
    cout << i + 1 << " " << opo + 1 << endl;
    i++;
    if (i == n)
      i -= n;
    cnt--;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  int a = 0, b = 1;
  rep(i, M) {
    cout << a + 1 << " " << b + 1 << "\\n";

    if (N % 2 == 0 && i + 1 == N / 4) {
      b++;
    }
    a = (a + N - 1) % N;
    b = (b + 1) % N;
  }

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >'


Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  if (N % 2 == 0) {
    throw string("hoge");
  }

  int a = 0, b = 2;
  rep(i, M) {
    if (N % 2 == 0 && abs(a - b) == N / 2) {
      b++;
      b %= N;
    }
    cout << a + 1 << " " << b + 1 << "\\n";

    a = (a + N - 1) % N;
    b = (b + 1) % N;
  }

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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> ans;
  if (n & 1) {
    for (int i = 0; i < (n - 1) / 2; i++) {
      ans.emplace_back(i + 2, -i + n);
    }
  } else {
    int k = 0;
    for (int i = 0; n / 2 - 2 * i - 1 > 0; i++) {
      ans.emplace_back(i + 1, -i + n);
      k++;
    }
    for (; k < (n - 2) / 2; k++) {
      ans.emplace_back(k + 2, -k + n);
    }
  }

  for (int i = 0; i < m; i++) {
    cout << ans[i].first << ' ' << ans[i].second << endl;
  }
}

Error: -11

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> ans;
  if (n & 1) {
    for (int i = 0; i < (n - 1) / 2; i++) {
      ans.emplace_back(i + 2, -i + n);
    }
  } else {
    for (int i = 0; i < (n - 2) / 4; i++) {
      ans.emplace_back(i + 1, -i + n);
    }
    for (int i = 0; i < (n - 2) / 4; i++) {
      ans.emplace_back(i + 2, -i + n);
    }
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i].first << ' ' << ans[i].second << endl;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> seen(100001, 0);
  int odd_l = 1;
  int odd_r = 1 + m;
  int even_l = 2 + m;
  int even_r = 2 * m + 1;
  int d = 1;
  for (int i = 1; i <= m; i++) {
    if (i % 2 == 1) {
      cout << odd_l << ' ' << odd_r << endl;
      odd_l++;
      odd_r--;
    } else {
      cout << even_l << ' ' << even_r << endl;
      even_l++;
      even_r--;
    }
    d++;
  }
}

Error: WA

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> seen(100001, 0);
  int now = 1;
  int d = 1;
  for (int i = 0; i < m; i++) {
    cout << now << ' ' << now + d << endl;
    seen[now] = 1;
    seen[now + d] = 1;
    for (int j = now + 1; j <= 100001; j++) {
      if (seen[j] == 0) {
        now = j;
        break;
      }
    }
    d++;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
  ll N, M;
  cin >> N >> M;
  vector<P> ans;
  ll start = 1;
  ll end = N;
  if (N % 2) {
    rep(i, M) {
      ans.push_back(make_pair(start, end));
      start++;
      end--;
    }
  } else {
    for (int i = 0; i < (M + 1) / 2; i++) {
      ans.push_back(make_pair(i + 1, N - i));
    }
    for (int i = (M + 1) / 2; i < M; i++) {
      ans.push_back(make_pair(i + 1, N - i - 1));
    }
  }
  rep(i, M) { cout << ans[i].first << " " << ans[i].second << '\\n'; }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
  ll N, M;
  cin >> N >> M;
  vector<P> ans;
  ll start = 1;
  ll end = N;
  if (N % 2) {
    rep(i, M) {
      ans.push_back(make_pair(start, end));
      start++;
      end--;
    }
  } else {
    for (int i = 0; i < M / 2 + 1; i++) {
      ans.push_back(make_pair(start, end));
      start++;
      end--;
    }
    for (int i = M / 2 + 1; i < M; i++) {
      start++;
      end -= 2;
    }
  }
  rep(i, M) { cout << ans[i].first << " " << ans[i].second << '\\n'; }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

// 競技プログラミング用のテンプレート
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> t(m, {0, 0});
  if (n % 2 != 0) {
    int l = 1;
    int r = n - 1;
    for (int i = 0; i < m; i++) {
      t[i] = {l, r};
      l++;
      r--;
    }
  } else {
    bool flag = false;
    int l = 1;
    int r = n;
    for (int i = 0; i < m; i++) {
      if (!flag && r - l <= n / 2) {
        r--;
        flag = true;
      }
      t[i] = {l, r};
      l++;
      r--;
    }
  }
  for (auto e : t) {
    cout << e.first << " " << e.second << endl;
  }
}


Error: WA

Fixed submission:

// 競技プログラミング用のテンプレート
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> t(m, {0, 0});
  if (n % 2 == 0) {
    int diff = 1;
    int start = 1;
    vector<bool> flag(n + 1, false);
    for (int i = 0; i < m; i++) {
      for (int start = 1; start <= n; start++) {
        if (!flag[start]) {
          t[i] = {start, start + diff};
          flag[start] = true;
          flag[start + diff] = true;
          diff++;
          break;
        }
      }
    }
  } else {
    int l = 1;
    int r = n;
    for (int i = 0; i < m; i++) {
      t[i] = {l, r};
      l++;
      r--;
    }
  }
  for (auto e : t) {
    cout << e.first << " " << e.second << endl;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

  int N, M;
  cin >> N >> M;
  int a = 1;
  int b = a + M;
  int c = b + 1;
  int d = c + M - 1;
  for (int i = 0; i < M; ++i) {
    if (i % 2 == 0) {
      cout << a << ' ' << b << endl;
      a++;
      b--;
    } else {
      cout << c << ' ' << d << endl;
      c++;
      d--;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

  int N, M;
  cin >> N >> M;
  vector<int> used(N, 0);
  int num = 0;
  int dist = 1;
  for (int i = 0; i < M;) {
    if (used.at(num) == 0 && used.at((num + dist) % N) == 0) {
      cout << num + 1 << ' ' << (num + dist) % N + 1 << endl;
      used.at(num)++;
      used.at((num + dist) % N)++;
      num = (num + 1) % N;
      dist++;
      i++;
    } else {
      num = (num + 1) % N;
    }
  }

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

// #define LOCAL
#include <algorithm>
#include <map>
#include <math.h>
#include <random>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using lld = long long int;
using llu = unsigned long long int;
using pii = pair<int, int>;
using pli = pair<lld, int>;
using pil = pair<int, lld>;
using pll = pair<lld, lld>;
using piii = pair<pii, pii>;
using pdii = pair<int, pii>;
int n, m;
pii a[1000009];
int mark[1000009];
bool test() {
  int i, j, k;
  for (i = 0; i <= n; i++) {
    mark[i] = 0;
  }
  for (k = 0; k < m; k++) {
    i = a[k].second - a[k].first;
    if (i < 0)
      i += n;
    mark[i]++;
    mark[n - i]++;
  }
  int cnt = 0;
  for (i = 1; i <= n; i++) {
    if (mark[i] > 1) {
      cnt++;
      // printf("fail at %d %d\\n", i, mark[i]);
    }
  }
  // printf("cnt : %d\\n", cnt);
  for (k = 0; k < cnt / 2; k++) {
    a[m - k - 1].second--;
  }
  for (i = 0; i <= n; i++) {
    mark[i] = 0;
  }
  for (k = 0; k < m; k++) {
    i = a[k].second - a[k].first;
    if (i < 0)
      i += n;
    mark[i]++;
    mark[n - i]++;
  }
  if (mark[a[m - cnt / 2 - 1].second - a[m - cnt / 2 - 1].first] > 1) {
    a[m - cnt / 2 - 1].second--;
  }
  return cnt;
}
int main() {
  int i, j, k, l;
  int t = 1, tv = 0;
  while (t--) {
    scanf("%d %d", &n, &m);
    if (n % 2 == 1) {
      for (i = 1, j = n, k = 0; k < m; k++, i++, j--) {
        a[k] = pii(i, j);
      }
    } else {
      bool ting = 0;
      for (i = 1, j = n, k = 0; k < m; k++, i++, j--) {
        a[k] = pii(i, j);
      }
      if (test()) {
        test();
      }
    }
    for (k = 0; k < m; k++) {
      printf("%d %d\\n", a[k].first, a[k].second);
    }
  }
}

Error: TLE

Fixed submission:

// #define LOCAL
#include <algorithm>
#include <map>
#include <math.h>
#include <random>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using lld = long long int;
using llu = unsigned long long int;
using pii = pair<int, int>;
using pli = pair<lld, int>;
using pil = pair<int, lld>;
using pll = pair<lld, lld>;
using piii = pair<pii, pii>;
using pdii = pair<int, pii>;
int n, m;
pii a[100009];
int mark[100009];
bool test() {
  int i, j, k;
  for (i = 0; i <= n; i++) {
    mark[i] = 0;
  }
  for (k = 0; k < m; k++) {
    i = a[k].second - a[k].first;
    if (i < 0)
      i += n;
    mark[i]++;
    mark[n - i]++;
  }
  int cnt = 0;
  for (i = 1; i <= n; i++) {
    if (mark[i] > 1) {
      cnt++;
      // printf("fail at %d %d\\n", i, mark[i]);
    }
  }
  // printf("cnt : %d\\n", cnt);
  for (k = 0; k < (cnt + 1) / 2; k++) {
    a[m - k - 1].second--;
  }
  return cnt;
}
int main() {
  int i, j, k, l;
  int t = 1, tv = 0;
  while (t--) {
    scanf("%d %d", &n, &m);
    if (n % 2 == 1) {
      for (i = 1, j = n, k = 0; k < m; k++, i++, j--) {
        a[k] = pii(i, j);
      }
    } else {
      bool ting = 0;
      for (i = 1, j = n, k = 0; k < m; k++, i++, j--) {
        a[k] = pii(i, j);
      }
      while (test())
        ;
    }
    for (k = 0; k < m; k++) {
      printf("%d %d\\n", a[k].first, a[k].second);
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
int dat1[100005], dat2[100005];
using namespace std;
int main() {

  int n, m;
  cin >> n >> m;
  if (!(n & 1))
    n--;
  int mm = (n - 1) / 2;
  if (mm & 1) {
    for (int i = 1; i <= mm / 2; i++) {
      dat1[i] = i;
      dat2[i] = (n + 1) / 2 - i;
    }
    for (int j = (n + 1) / 2, i = mm / 2 + 1, k = 0; i <= mm; i++, j++, k++) {
      dat1[i] = j;
      dat2[i] = n - k;
    }
  } else {
    for (int i = 1; i <= mm / 2; i++) {
      dat1[i] = i;
      dat2[i] = (n + 3) / 2 - i;
    }
    for (int i = (n + 3) / 2, j = n, k = mm / 2 + 1; k <= mm; i++, j--, k++) {
      dat1[k] = i;
      dat2[k] = j;
    }
  }
  // for(int i=1;i<=6;i++) cout<<dat1[i]<<" "<<dat2[i]<<endl;
  for (int i = 1; i <= m; i++)
    cout << dat1[i] << " " << dat2[i] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
int dat1[50005], dat2[50005];
using namespace std;
int main() {

  int n, m;
  cin >> n >> m;
  if (!(n & 1))
    n--;
  int mm = (n - 1) / 2;
  if (mm & 1) {
    for (int i = 1; i <= mm / 2; i++) {
      dat1[i] = i;
      dat2[i] = (n + 1) / 2 - i;
    }
    for (int j = (n + 1) / 2, i = mm / 2 + 1, k = 0; i <= mm; i++, j++, k++) {
      dat1[i] = j;
      dat2[i] = n - k;
    }
  } else {
    for (int i = 1; i <= mm / 2; i++) {
      dat1[i] = i;
      dat2[i] = (n + 3) / 2 - i;
    }
    for (int i = (n + 3) / 2, j = n, k = mm / 2 + 1; k <= mm; i++, j--, k++) {
      dat1[k] = i;
      dat2[k] = j;
    }
  }
  // for(int i=1;i<=6;i++) cout<<dat1[i]<<" "<<dat2[i]<<endl;
  for (int i = 1; i <= m; i++)
    cout << dat1[i] << " " << dat2[i] << endl;
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\\n"

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M;
  cin >> N >> M;
  ll num;
  if (N % 2 == 0)
    num = (N - 1) / 2;
  else
    num = N / 2;

  ll odd = (num + 1) / 2;
  ll even = num / 2;

  ll counter = 0;
  ll start = 1;
  for (int i = odd; i >= 1; i--) {
    cout << start << ' ' << start + 2 * i - 1 << endl;
    start++;
    counter++;
    if (counter == M)
      return 0;
  }
  start = 2 * odd + 1;
  for (int i = even; i >= 1; i--) {
    cout << start << ' ' << start + 2 * i << endl;
    start++;
    counter++;
    if (counter == M)
      return 0;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\\n"

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M;
  cin >> N >> M;
  vector<bool> flag(N + 1, false);
  ll counter = 0;
  for (int i = 1; i <= N; i++) {
    if (flag.at(i))
      continue;
    counter++;
    cout << i << ' ' << i + counter << endl;
    flag.at(i) = true;
    flag.at(i + counter) = true;
    if (counter == M)
      break;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

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

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

  int64_t even_num = (M + 1) / 2;
  int64_t sep = even_num * 2;
  for (int64_t i = 0; i < even_num; i++) {
    cout << i + 1 << " " << sep - i << endl;
  }

  int64_t right = (N % 2 == 0 ? N - 1 : N);
  for (int64_t i = 0; i < M - even_num; i++) {
    cout << sep + 1 + i << " " << right - i << endl;
  }
}

Error: -6
9f2a711c-225a-452c-87e7-31582dfccf40.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02697/C++/s325029532.cpp:15: int main(): Assertion `false' failed.


Fixed submission:

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

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

  if (N % 2 == 1) {
    for (int64_t i = 1; i <= M; i++) {
      cout << N / 2 - i + 1 << " " << N / 2 + i + 1 << endl;
    }
    return 0;
  }

  assert(false);

  set<int64_t> st;
  for (int64_t i = 1; i <= N; i++) {
    st.insert(i);
  }

  vector<pair<int64_t, int64_t>> ans;
  for (int64_t i = 1; i <= M; i++) {
    auto l = st.begin();
    st.erase(l);

    int64_t l_value = *l;
    auto r = st.lower_bound(l_value + i);
    ans.emplace_back(l_value, *r);
    cout << l_value << " " << *r << endl;
    st.erase(r);
  }
}