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

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

int n, m;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int a = 1, b = n;
  while (a < b && m) {
    cout << a << " " << b << "\\n";
    ++a;
    --b;
    --m;
    if ((n & 1 ^ 1) && n - b + a >= b - a && n - 2 * b + 2 * a <= 2)
      --b;
  }
  cout << flush;
  return 0;
}


Error: WA

Fixed submission:

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

const int M = 50005;
int n, m, fp[M][2];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n / 2; ++i) {
    fp[i][0] = i;
  }
  fp[n / 2][1] = n / 2 + 2;
  fp[n / 2 - 1][1] = n / 2 + 1;
  for (int i = n / 2 - 2; i >= 1; --i) {
    fp[i][1] = n / 2 + n / 2 - i + 1;
  }
  for (int i = 1; i <= m; ++i) {
    cout << fp[i][0] << " " << fp[i][1] << "\\n";
  }
  cout << flush;
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

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

// マクロ
// forループ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x) begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
// 出力
#define PRINT(x) cout << (x) << endl
#define PRINTA(x, n) REP(i, n) PRINT(x[i])
// 定数
#define INF 1000000000000 // 10^12
#define MOD 1000000007    // 10^9+7
// 略記
#define PB push_back
#define MP make_pair

int N, M;

int a[100009], b[100009];

int main() {
  cin >> N >> M;
  if (M % 2 == 0) {
    REP(i, M / 2) {
      a[i] = 1 + i;
      b[i] = M - i;
    }
    REP(i, M / 2) {
      a[i + M / 2] = M + 1 + i;
      b[i + M / 2] = 2 * M + 1 - i;
    }
  } else {
    REP(i, M / 2) {
      a[i] = 1 + i;
      b[i] = M - i;
    }
    REP(i, M / 2 + 1) {
      a[i + M / 2] = M + 1 + i;
      b[i + M / 2] = 2 * M + 1 - i;
    }
  }
  REP(i, M) printf("%d %d\\n", a[i], b[i]);
  return 0;
}

Error: WA

Fixed submission:

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

// マクロ
// forループ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x) begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
// 出力
#define PRINT(x) cout << (x) << endl
#define PRINTA(x, n) REP(i, n) PRINT(x[i])
// 定数
#define INF 1000000000000 // 10^12
#define MOD 1000000007    // 10^9+7
// 略記
#define PB push_back
#define MP make_pair

int N, M;

int a[50000], b[50000];

int main() {
  cin >> N >> M;
  if (M % 2 == 0) {
    REP(i, M / 2) {
      a[i] = 1 + i;
      b[i] = M - i;
    }
    REP(i, M / 2) {
      a[i + M / 2] = M + 1 + i;
      b[i + M / 2] = 2 * M + 1 - i;
    }
  } else {
    REP(i, M) {
      a[i] = 1 + i;
      b[i] = 2 * M - i;
    }
  }
  REP(i, M) printf("%d %d\\n", a[i], b[i]);
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N = 1e6 + 1;
int n, m;
int a[N], b[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  if (n % 2 == 0) {
    int l = 1, r = n / 2;
    int p = 0;
    while (l < r) {
      //	cout << l << ' ' <<r  << endl;
      ++p;
      a[p] = l;
      b[p] = r;
      l++;
      r--;
    }
    l = n / 2 + 1;
    r = n - 1;
    while (l < r) {
      ++p;
      a[p] = l;
      b[p] = r;
      l++;
      r--;
    }
  } else {
    for (int i = 1; i <= n / 2; i++) {
      a[i] = i;
      b[i] = n - i + 1;
    }
  }
  cin >> m;
  for (int i = 1; i <= m; i++)
    cout << a[i] << ' ' << b[i] << '\\n';
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N = 1e6 + 1;
int n, m;
int a[N], b[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  if (n % 2 == 0) {
    int l = 1, r = n / 2;
    int p = 0;
    while (l < r) {
      ++p;
      a[p] = l;
      b[p] = r;
      l++;
      r--;
    }
    l = n / 2 + 1;
    r = n - 1;
    while (l != r) {
      ++p;
      a[p] = l;
      b[p] = r;
      l++;
      r--;
    }
  } else {
    for (int i = 1; i <= n / 2; i++) {
      a[i] = i;
      b[i] = n - i + 1;
    }
  }
  cin >> m;
  for (int i = 1; i <= m; i++)
    cout << a[i] << ' ' << b[i] << '\\n';
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
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++) {
      if (i % 2 == 0) {
        cout << i / 2 + 1 << " " << n - i / 2 << endl;
      } else {
        cout << n / 2 - i / 2 - 1 << " " << n / 2 + i / 2 + 1 << endl;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m, 0), b(m, 0), c(n, 0);

  int interval = (n - 1) / 2, index = 0;
  for (int i = 0; i < m; i++, interval--) {
    a[i] = index;
    b[i] = (index + interval) % n;

    for (int j = 0;; j++) {
      if (c[a[i]] == 0 && c[b[i]] == 0) {
        c[a[i]] = c[b[i]] = 1;
        break;
      }
      a[i] = (a[i] + 1) % n;
      b[i] = (b[i] + 1) % n;
    }

    index = (b[i] + 1) % n;
  }

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

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

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 1001000
#define MOD 1000000007
#define endl "\\n"
lli arr[MAX];
lli N;
lli M;
lli Q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli t;
  t = 1;
  while (t--) {
    lli N, M;
    cin >> N >> M;
    lli a = N / 2;
    lli b = N / 2 + 1;
    if (N % 2 == 0) {
      vector<bool> visited(N + 5, 0);
      lli aeven = 1;
      lli beven = N / 2;
      lli aodd = N;
      lli bodd = N / 2 + 2;
      while (beven > aeven & M > 0) {
        cout << aeven << " " << beven << endl;
        aeven++;
        beven--;
        M--;
      }
      while (aodd > bodd & M > 0) {
        cout << aodd << " " << bodd << endl;
        aodd--;
        bodd++;
        M--;
      }
    } else {
      for (lli i = 0; i < M; i++) {
        cout << a << " " << b << endl;
        a--;
        b++;
      }
    }
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 1001000
#define MOD 1000000007
#define endl "\\n"
lli arr[MAX];
lli N;
lli M;
lli Q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli t;
  t = 1;
  while (t--) {
    lli N, M;
    cin >> N >> M;
    lli a = N / 2;
    lli b = N / 2 + 1;
    if (N % 2 == 0) {
      lli diff = 1;
      lli a = 1;
      lli b = 2;
      lli I = 1;
      vector<bool> visited(N + 5, 0);
      for (lli i = 0; i < M; i++) {
        cout << a << " " << b << endl;
        visited[a] = true;
        visited[b] = true;
        diff += 1;
        for (lli k = I; k <= N; k++) {
          if (visited[k] == false) {
            I = k;
            a = I;
            b = I + diff;
            visited[a] = true;
            visited[b] = true;
            break;
          }
        }
      }
    } else {
      for (lli i = 0; i < M; i++) {
        cout << a << " " << b << endl;
        a--;
        b++;
      }
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define MAXN 100000
using namespace std;

typedef long long int lli;

int N, M;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  int s = 0, e = 1;
  for (int j = 0; j < M; j += 2) {
    cout << min(s + 1, e + 1) << " " << max(s + 1, e + 1) << "\\n";
    s--;
    e++;
    s = (s + N) % N;
    e %= N;
  }
  int m = (s + e) / 2;
  s = m - 1;
  e = m + 1;
  for (int j = 1; j < M; j += 2) {
    cout << min(s + 1, e + 1) << " " << max(s + 1, e + 1) << "\\n";
    s--;
    e++;
    s = (s + N) % N;
    e %= N;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define MAXN 100000
using namespace std;

typedef long long int lli;

int N, M;
bool visit[MAXN + 1];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (int j = 1, cnt = 0; cnt < M; ++j) {
    if (visit[j])
      continue;
    int k = (j + cnt) % N + 1;
    visit[k] = true;
    visit[j] = true;
    cout << j << " " << k << "\\n";
    cnt++;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const ll mod = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  if (n % 2 == 1) {
    int l = 1, r = n;
    while (k--) {
      cout << l << ' ' << r << '\\n';
      l++;
      r--;
    }
  } else {
    int b = k / 2, a = k - b;
    int l = 1, r = (n + 1) / 2;
    while (a--) {
      cout << l << ' ' << r << '\\n';
      l++;
      r--;
    }
    l = (n + 1) / 2 + 1, r = n - 1;
    while (b--) {
      cout << l << ' ' << r << '\\n';
      l++, r--;
    }
  }

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
const ll mod = 998244353;

int vis[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  int ins = 0, dis = 1;
  set<int> s;
  while (k--) {
    for (;;) {
      while (vis[ins] == 1)
        ins++;
      int nins = (ins + dis) % n;
      if (s.count(min(ins, nins) + n - max(ins, nins)) == 1 ||
          s.count(abs(ins - nins)) == 1) {
        dis++;
        continue;
      }
      if (vis[nins] == 1) {
        ins++;
        continue;
      }
      assert(ins < n);
      s.insert(abs(ins - nins));
      s.insert(min(ins, nins) + n - max(ins, nins));
      vis[ins] = 1;
      vis[nins] = 1;
      cout << min(ins, nins) + 1 << ' ' << max(ins, nins) + 1 << '\\n';
      dis++;
      break;
    }
  }

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

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long

using namespace std;

long long MOD = 1000000007;

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

Error: WA

Fixed submission:

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N + 1, 0);
  int cnt = 1;
  for (int i = 1; i <= N; i++) {
    if (vec[i] == 0 && vec[i + cnt] == 0) {
      vec[i] = vec[i + cnt] = 1;
      cout << i << ' ' << i + cnt << endl;
      cnt++;
    }
    // cout << cnt << endl;
    if (cnt == M + 1)
      break;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG // GCC5.4.1で配列の範囲外アクセスをエラーにする

// cmdで g++ test.cpp とするとコンパイルできる
// 制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(), x.end()
typedef long long ll;            // long long
typedef pair<int, int> pii;      // pair<int,int>
typedef vector<int> vi;          // vector<int>
typedef vector<vector<int>> vvi; // vector<vector<int>>
typedef vector<ll> vll;          // vector<long long>
typedef vector<vector<ll>> vvll; // vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int>> gpq; // 逆順priority_queue
typedef priority_queue<int> pq;

// const int MOD=998244353;
const int MOD = 1000000007; // 10^9+7
const double PI = 3.1415926535;

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG // GCC5.4.1で配列の範囲外アクセスをエラーにする

// cmdで g++ test.cpp とするとコンパイルできる
// 制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(), x.end()
typedef long long ll;            // long long
typedef pair<int, int> pii;      // pair<int,int>
typedef vector<int> vi;          // vector<int>
typedef vector<vector<int>> vvi; // vector<vector<int>>
typedef vector<ll> vll;          // vector<long long>
typedef vector<vector<ll>> vvll; // vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int>> gpq; // 逆順priority_queue
typedef priority_queue<int> pq;

// const int MOD=998244353;
const int MOD = 1000000007; // 10^9+7
const double PI = 3.1415926535;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<bool> used_p(N + 10, false);
  ll free_min = 1;
  if (N % 2) {
    ll v1 = N / 2, v2 = N / 2 + 1;
    for (int i = 0; i < M; i++) {
      cout << v1 << " " << v2 << endl;
      v1--;
      v2++;
    }
  } else {
    ll sz = 1;
    for (int i = 0; i < M; i++) {
      cout << free_min << " " << (free_min + sz) << endl;
      used_p[free_min] = true;
      used_p[free_min + sz] = true;
      sz++;
      while (used_p[free_min]) {
        free_min++;
      }
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: 0

Fixed submission:

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

int main() {
  ll N, M;
  cin >> N >> M;
  ll head = 2 * (M / 2) + 1;
  if (M % 2 == 0)
    return 1;
  rep(i, 1, M / 2 + 1) {
    cout << i << " " << head << endl;
    head--;
  }
  head = 2 * (M / 2) + 1 + 2 * (M + 1) / 2;
  rep(i, 1, (M + 1) / 2 + 1) {
    cout << i + 2 * (M / 2) + 1 << " " << head << endl;
    head--;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, n, a) for (int i = n; i >= a; i--)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  if (n & 1) {
    rep(i, 1, m + 1) { cout << i << ' ' << n - i << endl; }
  } else {
    int count = 0;
    int a = 1, b = n / 2;
    while (a < b && count < m) {
      cout << a % (n + 1) << ' ' << b << endl;
      a++;
      b--;
      count++;
    }
    int c = n / 2 + 1, d = n - 1;
    while (c < d && count < m) {
      cout << c << ' ' << d << endl;
      c++;
      d--;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, n, a) for (int i = n; i >= a; i--)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<bool> used(n, 0);
  int st = 0;
  rep(i, 1, m + 1) {
    while (used[st % n] || used[(st + i) % n]) {
      st++;
    }
    cout << st % n + 1 << ' ' << (st + i) % n + 1 << endl;
    used[st % n] = 1;
    used[(st + i) % n] = 1;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

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

bool u[1000010];
long long n, m, x;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  int i = 1;
  int j = n;
  while (m--) {
    x = j - i - 2;
    if (!u[x] && !u[n - x - 2]) {
      u[x] = u[n - x - 2] = true;
      cout << i << ' ' << j << '\\n';
      i++, j--;
    } else
      j--, m++;
  }
}


Error: WA

Fixed submission:

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

bool u[100010];
long long n, m, x;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  int i = 1;
  int j = n;
  while (m--) {
    x = j - i - 2;
    if (!u[x] && !u[n - x - 2]) {
      u[x] = u[n - x - 2] = true;
      cout << i << ' ' << j << '\\n';
      i++, j--;
    } else
      j--, m++;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

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

  if (n % 2) {
    int dif = 1;
    int pivot = n / 2;
    for (int i = 0; i < m; i++) {
      cout << pivot << " " << pivot + dif << endl;
      pivot--;
      dif += 2;
    }
  } else {
    int dif = 1;
    int pivot = n / 2;
    int i = 0;
    for (; i < m; i++) {
      if (i >= n / 4)
        break;
      cout << pivot << " " << pivot + dif << endl;
      pivot--;
      dif += 2;
    }
    dif++;
    for (; i < m; i++) {
      cout << pivot << " " << pivot + dif << endl;
      pivot--;
      dif += 2;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

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

  if (n % 2) {
    int dif = 1;
    int pivot = n / 2;
    for (int i = 0; i < m; i++) {
      cout << pivot << " " << pivot + dif << endl;
      pivot--;
      dif += 2;
    }
  } else {
    vector<bool> used(n + 1, false);
    int dif = 0;
    int pivot = 0;
    for (int i = 0; i < m; i++) {
      pivot = pivot % n + 1;
      int l = pivot;
      int r = (pivot + dif) % n + 1;
      if (used[l] || used[r]) {
        i--;
        continue;
      }
      cout << l << " " << r << endl;
      used[l] = true;
      used[r] = true;
      dif++;
    }
  }

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

#include <iostream>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int i = 1, j = N;
  int dif = j - i;
  for (int k = 0; k < M; k++) {
    if (j - i == N - dif || j - i == N - (j - i))
      i++;
    cout << i << " " << j << endl;
    dif = j - i;
    i++;
    j--;
  }
}


Error: WA

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int dif = 1, first = 1;
  vector<int> Used(N, 0);
  for (int i = 0; i < M; i++) {
    cout << first << " " << first + dif << endl;
    Used[first - 1] = 1;
    Used[first + dif - 1] = 1;
    dif++;
    while (Used[first - 1])
      first++;
  }
}
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 & 1) {
    for (int i = 1; i <= m; i++) {
      cout << i << ' ' << n - i << '\\n';
    }
  } else {
    int t = (m + 1) / 2, t2 = t << 1;
    for (int i = 1; i <= t; i++) {
      int a = t - i + 1, b = a + i * 2 - 1;
      cout << a << ' ' << b << '\\n';
    }
    for (int i = 1; i <= m - t; i++) {
      int a = t2 + m - t - i + 1, b = a + i * 2;
      cout << a << ' ' << b << '\\n';
    }
  }
#ifndef ONLINE_JUDGE
  system("pause");
#endif
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n & 1) {
    for (int i = 1; i <= m; i++) {
      cout << i << ' ' << n - i << '\\n';
    }
  } else {
    vector<int> vec;
    cout << vec[1];
    for (int i = 1, j = 1; i <= m; i++, j = (j + 1) % n + 1) {
      int a = n / 2 - i, b = (a + j - 1) % n + 1;
      cout << a << ' ' << b << '\\n';
      if (j <= n / 2 && j + 2 > n / 2) {
        j++;
      }
    }
  }
#ifndef ONLINE_JUDGE
  system("pause");
#endif
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pi;
#define f first
#define s second
#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
const int maxn = 100010;

int n, m;
int maxeven, maxodd;

int32_t main() {
  FAST cin >> n >> m;

  if (m % 2 == 0) {
    maxeven = m;
    maxodd = m - 1;
  } else {
    maxeven = m - 1;
    maxodd = m;
  }

  int co = 1;
  for (int i = maxodd; i >= 1; i -= 2) {
    cout << co << " " << co + i << "\\n";
    co++;
  }
  co = maxodd + 2;

  for (int i = maxeven; i >= 2; i -= 2) {
    cout << co << " " << co + i << "\\n";
    co++;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pi;
#define f first
#define s second
#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
const int maxn = 100010;

int n, m;
int taken[maxn];

int32_t main() {
  FAST cin >> n >> m;
  int a = 1, b = 0;
  cout << a << " " << n << "\\n";
  int curgoal = 1 + 1;
  taken[1] = taken[n] = 1;

  for (int i = 1; i < m; i++) {
    while (true) {
      a++;
      if (a > n)
        a -= n;
      b = a + curgoal;
      if (b > n)
        b -= n;

      if (!taken[a] and !taken[b])
        break;
    }

    cout << a << " " << b << "\\n";
    taken[a] = taken[b] = 1;
    curgoal++;
  }
}