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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  if (n % 2) {
    rep(i, m) cout << i + 1 << " " << n - i << endl;
  } else {
    rep(i, (m + 1) / 2) cout << ((1 - i + n) % n == 0 ? n : (1 - i + n) % n)
                             << " " << (2 + i) % n << endl;
    rep(i, m / 2) cout << (n / 2 - i) % n << " " << (n / 2 + 2 + i) % n << endl;
  }
  return 0;
}

Error: -6
8f392d09-706d-41b9-9dc1-7657c858291c.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02697/C++/s382884057.cpp:27: int main(): Assertion `m * 2 + 2 != n' failed.


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  if (n % 2) {
    rep(i, m) cout << i + 1 << " " << n - i << endl;
  } else {
    assert(m * 2 + 2 != n);
    rep(i, (m + 1) / 2) cout << ((1 - i + n) % n == 0 ? n : (1 - i + n) % n)
                             << " " << (2 + i) % n << endl;
    rep(i, m / 2) cout << (n / 2 + 1 - i) % n << " " << (n / 2 + 3 + i) % n
                       << endl;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: -11

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> ans(m, vector<int>(2));
  int writer = 0;

  int l = 1, r = n / 2;
  int s = r + 1, t = n;
  while (l < r) {
    ans[writer][0] = l++;
    ans[writer++][1] = r--;
  }
  while (s < t) {
    ans[writer][0] = s++;
    ans[writer++][1] = t--;
  }
  rep(i, m) { cout << ans[i][0] << " " << ans[i][1] << endl; }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

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

  int odd = (N / 2 + 1) / 2;
  int even = N / 2 / 2;
  // cerr << odd << ' ' << even << endl;
  for (int i = 1; i <= N / 2; i++) {
    if (M == 0)
      break;
    if (i % 2 == 0) {
      cout << N - even - i / 2 << ' ' << N - even + i / 2 << endl;
    } else {
      cout << odd - i / 2 << ' ' << odd + (i + 1) / 2 << endl;
    }
    --M;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> used(N + 2);

  int d = 1;
  for (int i = 0;; i++) {
    if (M == 0)
      break;
    int j = (i + d) % N;
    if (used[i] == 0 && used[j] == 0) {
      cout << i + 1 << ' ' << j + 1 << endl;
      used[i] = 1;
      used[j] = 1;
      ++d;
      --M;
    }
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define decp(n) cout << fixed << setprecision((int)n)
const int inf = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vvin a(m, vin(2));
  if (m % 2) {
    int s = 1;
    int l = (m / 2) * 2 + 1;
    rep(i, m / 2) {
      cout << s << " " << l << endl;
      s++;
      l--;
    }
    s = (m / 2) * 2 + 2;
    l = s + 2 * (m / 2 + 1) - 1;
    rep(i, m / 2 + 1) {
      cout << s << " " << l << endl;
      s++;
      l--;
    }
  } else {
    int s = 1;
    int l = m + 1;
    rep(i, m / 2) {
      cout << s << " " << l << endl;
      s++;
      l--;
    }
    s = m + 2;
    l = s + m - 1;
    rep(i, m / 2) {
      cout << s << " " << l << endl;
      s++;
      l--;
    }
  }
}

Error: WA

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define decp(n) cout << fixed << setprecision((int)n)
const int inf = 1e9 + 7;

int j = 0;
int n = 200010;
int m;
vbo judge(n, true);
int tmp = 0;

void dfs(vvin &a) {
  rep2(i, tmp + 1, n + 1) if (judge[i - 1]) {
    tmp = i;
    break;
  }
  a[j][0] = tmp;
  judge[a[j][0] - 1] = false;
  a[j][1] = (a[j][0] + j + 1) % n;
  judge[a[j][1] - 1] = false;
  if (j == m - 1)
    return;
  j++;
  dfs(a);
}

int main() {
  cin >> n >> m;
  vvin ans(m, vin(2));
  dfs(ans);
  rep(i, m) cout << ans[i][0] << " " << ans[i][1] << endl;
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  vector<pair<int, int>> ans;
  set<int> used;

  int start = N / 2;
  int end = N / 2 + 1;
  int cnt = 0;
  ans.push_back({start, end});
  used.insert(1 + end - start);
  used.insert(N - (end - start - 1));
  cnt++;
  start--;
  end++;
  while (cnt < M) {
    while (1) {
      // int x = start + N - end;
      // printf("start: %d, end: %d, x: %d\\n", start, end, x);
      if (used.find(1 + end - start) != used.end() ||
          used.find(N - (end - start - 1)) != used.end() ||
          end - start == start + N - end) {
        if (end < N) {
          end++;
        } else {
          start--;
        }
      } else {
        break;
      }
    }
    assert(start >= 1 && end <= N);
    ans.push_back({start, end});
    used.insert(1 + end - start);
    used.insert(N - (end - start - 1));
    cnt++;
    start--;
    end++;
  }

  for (auto &p : ans) {
    cout << p.first << " " << p.second << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  vector<pair<int, int>> ans;
  set<int> used;

  int start = N / 2;
  int end = N / 2 + 1;
  int cnt = 0;
  ans.push_back({start, end});
  used.insert(1 + end - start);
  used.insert(N - (end - start - 1));
  cnt++;
  start--;
  end++;
  while (cnt < M) {
    while (1) {
      // int x = start + N - end;
      // printf("start: %d, end: %d, x: %d\\n", start, end, x);
      while (1) {
        if (used.find(1 + end - start) != used.end() ||
            used.find(N - (end - start - 1)) != used.end()) {
          if (end < N) {
            end++;
          } else {
            start--;
          }
        } else {
          break;
        }
      }
    }
    assert(start >= 1 && end <= N);
    ans.push_back({start, end});
    used.insert(1 + end - start);
    used.insert(N - (end - start - 1));
    cnt++;
    start--;
    end++;
  }

  for (auto &p : ans) {
    cout << p.first << " " << p.second << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
map<int, int> app;
int main() {
  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    int l = 1, r = n - 1;
    for (int i = 1; i <= m; ++i)
      cout << (l++) << " " << (r--) << endl;
    return 0;
  } else {
    int l = 1, r = n;
    for (int i = 1; i <= m; ++i) {
      while (true) {
        app[r - l]++;
        if (app[r - l] >= 2) {
          ++l;
          app[r - l]--;
          continue;
        }
        app[l - r + n]++;
        if (app[l - r + n] >= 2) {
          ++l;
          app[l - r + n]--;
          continue;
        }
        break;
      }
      cout << l << " " << r << '\\n';
      ++l, --r;
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
int main() {
  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    assert(0);
    int l = 1, r = n;
    for (int i = 1; i <= m; ++i)
      cout << (l++) << " " << (r--) << endl;
    return 0;
  } else {
    int l = 1, r = n - 1;
    for (int i = 1; i <= m; ++i) {
      cout << (l++) << " " << (r--) << endl;
    }
    return 0;
  }
  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;
  int ma = M;
  vector<pair<int, int>> ans;
  if (ma % 2 == 0) {
    for (int i = 0; i < ma / 2; i++) {
      ans.push_back({N - ma + i + 1, N - i});
    }
    for (int i = 0; i < ma / 2; i++) {
      ans.push_back({i + 1, ma - i + 1});
    }
  } else {
    for (int i = 0; i < ma / 2 + 1; i++) {
      ans.push_back({N - ma + i, N - i});
    }
    for (int i = 0; i < ma / 2; i++) {
      ans.push_back({i + 1, ma - i});
    }
  }
  for (int i = 0; i < M; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}


Error: 1

Fixed submission:

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

void solve(long long N, long long M) {
  if (N % 2 == 1) {
    N /= 2;
    N *= 2;
    vector<pair<int, int>> p;
    for (int i = 0; i < N / 2; i++) {
      // cout<<i+1<<" "<<N - i<<endl;
      p.push_back({i + 1, N - i});
    }
    reverse(p.begin(), p.end());
    for (int i = 0; i < M; i++) {
      cout << p[i].first << " " << p[i].second << endl;
    }
  } else {
    exit(1);
    if (M <= N / 2 - 2) {
      set<int> se;
      for (int i = 0; i < N; i++)
        se.insert(i);
      int cnt = 1;
      for (int i = 0; i < M; i++) {
        int q = *se.begin();
        se.erase(q);
        /*
        if(se.find(q + cnt) == se.end()){
            exit(1);
        }
        */

        se.erase(q + cnt);
        cout << q + 1 << " " << (q + cnt) % N + 1 << endl;
        cnt++;
      }
    } else {
      N--;
      N /= 2;
      N *= 2;
      vector<pair<int, int>> p;
      for (int i = 0; i < N / 2; i++) {
        // cout<<i+1<<" "<<N - i<<endl;
        p.push_back({i + 1, N - i});
      }
      reverse(p.begin(), p.end());
      for (int i = 0; i < M; i++) {
        cout << p[i].first << " " << p[i].second << endl;
      }
    }
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  solve(N, M);
  return 0;
}
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 vl = vector<ll>;
using Map = map<ll, vl>;
using Tu = tuple<ll, ll, ll>;
using vvl = vector<vector<ll>>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

  for (ll i = 0; i < M; i++) {
    if (1 + i < M - i) {
      cout << 1 + i << " " << M - i << endl;
    } else
      break;
    ;
  }
  for (ll i = 0; i < M; i++) {
    if (M + 1 + i < 2 * M + 1 - i) {
      cout << M + 1 + i << " " << 2 * M + 1 - i << endl;
    } else
      break;
    ;
  }

  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Map = map<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using T = tuple<ll, ll, vl>;
ll INF = 1LL << 60;
ll MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N, 0);
  vector<ll> u(N - 1, 0);
  vector<ll> v(N - 1, 0);
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (ll i = 0; i < N - 1; i++) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
    ;
  }
  vector<vector<ll>> gr(N, vector<ll>(0));
  for (ll i = 0; i < N - 1; i++) {
    gr[u[i]].emplace_back(v[i]);
    gr[v[i]].emplace_back(u[i]);
    ;
  }

  vector<ll> d(N, INF);
  d[0] = 0;
  vector<ll> longest(N, 1);
  queue<ll> qu;
  // 訪問フラグ
  vector<ll> check(N, 0);
  check[0] = 1;
  vector<vector<ll>> vec(N, vector<ll>(N, INF));
  vec[0][0] = a[0];
  qu.push(0);
  while (!qu.empty()) {
    ll x = qu.front();
    qu.pop();
    for (ll i = 0; i < gr[x].size(); i++) {
      ll k = gr[x][i];
      if (check[k])
        continue;
      vl w = vec[x];
      *lower_bound(w.begin(), w.end(), a[k]) = a[k];
      d[k] = d[x] + 1;
      vec[k] = w;
      qu.push(k);
      longest[k] = lower_bound(w.begin(), w.end(), INF) - w.begin();
      check[k] = 1;
    }
  }
  for (ll i = 0; i < N; i++) {
    cout << longest[i] << endl;
    ;
  }

  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;
  if (N % 2)
    for (int i = 0; i < M; i++)
      cout << i + 1 << " " << N - i << endl;
  else {
    for (int i = 0; i < (M + 1) / 2; i++)
      cout << i + 1 << " " << (M + 1) / 2 * 2 - i << endl;
    int r = (M + 1) / 2 * 2;
    for (int i = 0; i < M / 2; i++)
      cout << r + i + 1 << " " << r + M / 2 * 2 + 1 - i << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  if (N % 2)
    for (int i = 0; i < M; i++)
      cout << i + 1 << " " << N - i << endl;
  else {
    vector<bool> used(N + 1, false);
    int pos = 1;
    for (int k = M; k > 0; k--) {
      while (1) {
        if (!used[pos] && !used[pos + k]) {
          cout << pos << " " << pos + k << endl;
          used[pos] = used[pos + k] = true;
          pos++;
          break;
        }
        pos++;
      }
    }
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\\n"
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T> auto compare = [](T x, T y) -> bool { return (x < y); };
const int MOD = 1000000007;

ll N, M;

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\\n"
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T> auto compare = [](T x, T y) -> bool { return (x < y); };
const int MOD = 1000000007;

ll N, M;
bool used[100010];

signed main() {
  cin >> N >> M;
  ll i = 0, k = 1;
  while (k <= M) {
    i %= N;
    if (used[i] || used[(i + k) % N]) {
      i++;
      continue;
    } else {
      cout << i + 1 << " " << i + 1 + k << endl;
      used[i] = used[(i + k) % N] = true;
      k++;
      i++;
    }
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
// #pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x) {
  x = 0;
  char ch = getchar();
  int fh = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  x *= fh;
}
template <typename T> void write(T x) {
  if (x < 0)
    x = -x, putchar('-');
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
  write(x);
  puts("");
}
int n, m;
signed main() {
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 1; i <= m; i++)
      cout << i << ' ' << n - i + 1 << endl;
    return 0;
  } else {
    int l = 1, r = n;
    bool flag = false;
    while (m) {
      cout << l << ' ' << r << endl;
      m--;
      l++;
      r--;
      if (r - l <= n - (r - l) && !flag)
        r--, flag = true;
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
// #pragma GCC optimize(2)
// #define int long long
using namespace std;
template <typename T> void read(T &x) {
  x = 0;
  char ch = getchar();
  int fh = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  x *= fh;
}
template <typename T> void write(T x) {
  if (x < 0)
    x = -x, putchar('-');
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
  write(x);
  puts("");
}
int n, m;
int start = 1;
bool vis[100005];
signed main() {
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 1; i <= m; i++)
      cout << i << ' ' << n - i + 1 << endl;
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    while (vis[start])
      start++;
    int j = start;
    while (vis[j] && vis[j + i])
      j++;
    vis[j] = vis[j + i] = 1;
    cout << j << ' ' << j + i << endl;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

// E.

#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
#ifdef _MSC_VER
  while (true)
#endif
  {
    int n = -1, m;
    cin >> n >> m;
    if (n < 0)
      return 0;
    int r = m;
    if ((n % 2) == 0) {
      for (int i = 0; i < m / 2; ++i) {
        --r;
        cout << (n / 2 - i) << " " << (n / 2 + i + 2) << endl;
      }
    }
    for (int i = 0; i < r; ++i) {
      cout << (i + 1) << " " << (n - i) << endl;
    }
  }
  return 0;
}


Error: WA

Fixed submission:

// E.

#include <algorithm>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> II;
typedef pair<LL, II> LII;

int main(int argc, char *argv[]) {
  cout.precision(20);
#ifdef _MSC_VER
  while (true)
#endif
  {
    int n = -1, m;
    cin >> n >> m;
    if (n < 0)
      return 0;
    vector<vector<int>> f(n, vector<int>(n));
    vector<II> v(m);
    for (int i = 0; i < m; ++i) {
      cout << (m - i) << " " << (m + i + 1) << endl;
    }
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
const long long mod = 1e9 + 7;
//////////////////////////////////

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  if (n % 2 == 0) {
    for (int i = 1; i <= m; i++) {
      if (n / 2 < n + 1 - 2 * i) {
        a[i - 1] = i;
        b[i - 1] = n - i + 1;
      } else {
        a[i - 1] = i;
        b[i - 1] = n - i;
      }
    }
  } else {
    for (int i = 0; i < m; i++) {
      a[i] = i + 1;
      b[i] = n - i;
    }
  }

  for (int i = 0; i < m; i++) {
    cout << a[i] << " " << b[i] << endl;
  }

  return 0;
}

// EOF


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
const long long mod = 1e9 + 7;
//////////////////////////////////

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  if (m % 2 == 0) {
    for (int i = 1; i <= m; i++) {
      if (n / 2 < n + 1 - 2 * i) {
        a[i] = i;
        b[i] = n - i + 1;
      } else {
        a[i] = i;
        b[i] = n - i;
      }
    }
  } else {
    for (int i = 0; i < m; i++) {
      a[i] = i + 1;
      b[i] = n - i;
    }
  }

  for (int i = 0; i < m; i++) {
    cout << a[i] << " " << b[i] << endl;
  }

  return 0;
}

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

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

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 {
    for (int i = 0; i < m; i++) {
      cout << i + 1 << " " << n - i - (2 * i >= m) << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

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

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 {
    vector<bool> check(100005);
    int arrow = 1;
    int dif = 1;
    int cnt = 0;
    while (cnt < m) {
      if (!check[arrow]) {
        cout << arrow << " " << arrow + dif << endl;
        check[arrow] = true;
        check[arrow + dif] = true;
        dif++;
        cnt++;
      }
      arrow++;
    }
  }
  return 0;
}