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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define fore(i, a) for (auto &i : a)
#define REP(i, n) for (int i = 0; i < n; i++)
#define eREP(i, n) for (int i = 0; i <= n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define eFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define SORT(c) sort((c).begin(), (c).end())
#define rSORT(c) sort((c).rbegin(), (c).rend())
#define LB(x, a) lower_bound((x).begin(), (x).end(), (a))
#define UB(x, a) upper_bound((x).begin(), (x).end(), (a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
// priority_queue<int,vector<int>, greater<int> > q2;

int N, M;

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

  cin >> N >> M;
  int a = 1, b = N;
  bool F[200010] = {false};
  int m = N;
  while (M--) {
    if (F[b - a - 1] || F[a + N - b - 1] || a + N - b - 1 == b - a - 1)
      b--;
    F[b - a - 1] = F[a + N - b - 1] = 1;
    cout << a << " " << b << endl;
    a++;
    b--;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define fore(i, a) for (auto &i : a)
#define REP(i, n) for (int i = 0; i < n; i++)
#define eREP(i, n) for (int i = 0; i <= n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define eFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define SORT(c) sort((c).begin(), (c).end())
#define rSORT(c) sort((c).rbegin(), (c).rend())
#define LB(x, a) lower_bound((x).begin(), (x).end(), (a))
#define UB(x, a) upper_bound((x).begin(), (x).end(), (a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
// priority_queue<int,vector<int>, greater<int> > q2;

int N, M;

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

  cin >> N >> M;
  int a = 1, b = N;
  bool F[100010] = {false};
  int m = N;
  while (M--) {
    if (F[b - a - 1] || F[a + N - b - 1])
      b--;
    F[b - a - 1] = F[a + N - b - 1] = 1;
    cout << a << " " << b << endl;
    a++;
    b--;
    if (F[b - a - 1] || F[a + N - b - 1])
      b--;
  }

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

#include <cstdio>
using namespace std;
int m, n;
int main() {
  scanf("%d%d", &n, &m);
  int l1 = 1, r1 = l1 + m, l2 = r1 + 1, r2 = l2 + m - 1;
  while (true) {
    if (l1 >= r1)
      break;
    printf("%d %d\\n", l1, r1);
    if (l2 >= r2)
      break;
    printf("%d %d\\n", l2, r2);
    l1++, l2++;
    r1--, r2--;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#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;

const int maxn = 1e5 + 7;

int n, m;
int used[maxn];

int main() {
  cin >> n >> m;
  int l = 1, r = 2;
  for (int i = 1; i <= m; i++) {
    r = l + i;
    cout << l << " " << r << endl;
    used[l] = 1;
    used[r] = 1;
    while (used[l])
      l++;
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

void solve(int n, int m) {
  set<int> s;
  int l = 1;
  int r = n;
  vector<pair<int, int>> v;
  for (int i = 0; i < m; i++) {
    if (s.count(r - l) || s.count(n - (r - l)) || 2 * (r - l) == n)
      l++;
    // cerr << l << ' ' << r << ' ' << r - l <<  ' ' << n - (r - l) << '\\n';
    v.push_back({l, r});
    s.insert(r - l);
    s.insert(n - (r - l));
    l++;
    r--;
    l = (l + n) % n;
    r = (r + n) % n;
    if (l > r)
      swap(l, r);
  }
  if ((int)s.size() != 2 * m) {
    assert(false);
    cerr << "WA " << n << ' ' << m << endl;
  }
  for (auto t : v) {
    cout << t.first << ' ' << t.second << endl;
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  solve(n, m);
  // for (int m = 1; m < 100; m++) {
  // 	for (int n = 2 * m + 1; n <= 100; n++) {
  // 		solve(n, m);
  // 	}
  // }
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

void solve(int n, int m) {
  set<int> s;
  int l = 1;
  int r = n;
  vector<pair<int, int>> v;
  for (int i = 0; i < m; i++) {
    v.push_back({l, r});
    s.insert(r - l);
    s.insert(n - (r - l));
    l++;
    r--;
  }
  if ((int)s.size() != 2 * m) {
    assert(false);
  }
  for (auto t : v) {
    cout << t.first << ' ' << t.second << endl;
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  solve(n, m);
  // srand(3);
  // while (true) {
  // 	for (int n = 3; n <= 10; n++) {
  // 		int m = rand() % ((n - 1) / 2);
  // 		assert(2 * m + 1 <= n);
  // 		solve(n, m);
  // 	}
  // }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;

int main() {
  fastio;
  int n, m;
  cin >> n >> m;
  if (n % 2 == 1) {
    for (int i = 1; i <= m; ++i) {
      cout << i << " " << n - i << "\\n";
    }
  } else {
    int num = (m + 1) / 2;
    for (int i = 1; i <= num; ++i) {
      cout << i << " " << n - i + 1 << "\\n";
    }
    for (int i = num + 1; i <= m; ++i) {
      cout << i << " " << n - i << "\\n";
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;

int main() {
  fastio;
  int n, m, num = 1;
  cin >> n >> m;
  vector<int> vis(n + 1, false);
  for (int i = 1; i <= n; ++i) {
    if (m == 0)
      break;
    if (vis[i])
      continue;
    vis[i] = true;
    vis[i + num] = true;
    cout << i << " " << i + num << "\\n";
    num++;
    m--;
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using ll = long long int;

constexpr int MAX_N = 1e5 + 1;

bool used[MAX_N];

int main() {
  int n, m;

  std::cin >> n >> m;

  if (n % 2) {
    for (int i = 1; i <= m; ++i) {
      std::cout << i << ' ' << n + 1 - i << std::endl;
    }
  } else {
    int x = n - ((n + 2) / 4 * 2 + 1);
    x = (x + 1) / 2;
    for (int i = 1; i <= m && i <= x; ++i) {
      std::cout << i << ' ' << n + 1 - i << std::endl;
    }

    for (int i = x + 1; i <= m; ++i) {
      std::cout << i << ' ' << n - i << std::endl;
    }
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>

using ll = long long int;

constexpr int MAX_N = 1e5 + 1;

bool used[MAX_N];

int main() {
  int n, m;

  std::cin >> n >> m;

  int pos = 0, c = 0;

  while (c < m) {
    ++pos;
    if (used[pos]) {
      continue;
    }

    ++c;
    std::cout << pos << ' ' << pos + c << std::endl;
    used[pos] = used[pos + c] = 1;
  }

  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 k = (n + 1) / 2;
  for (int i = 0; i < m; i++) {
    if (i & 1)
      cout << (k + i / 2) % n + 1 << ' ' << (k - i / 2 - 2 + n) % n + 1 << '\\n';
    else
      cout << (n - i / 2 - 1) % n + 1 << ' ' << i / 2 + 1 << '\\n';
  }
  return 0;
}


Error: WA

Fixed submission:

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

int d[111111];
int main() {
  int n, m, j = 1;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    while (d[j])
      j++;
    d[j] = d[j + i + 1] = 1;
    cout << j << ' ' << j + i + 1 << '\\n';
  }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

bool U[100005];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  vector<pll> ans;
  if (N % 2 == 1) {
    REP(i, M) { ans.push_back(pll(i + 1, N - 1 - i)); }
  } else {
    ll es = 1, os = N;
    for (ll m = M; m > 0; --m) {
      if (m % 2 == 0) {
        ans.push_back(pll(es, es + m));
        es++;
      } else {
        ans.push_back(pll(os, os - m));
        os--;
      }
    }
  }

  REP(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

bool U[100005];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  vector<pll> ans;
  if (N % 2 == 1) {
    REP(i, M) { ans.push_back(pll(i + 1, N - 1 - i)); }
  } else {

    memset(U, 0, sizeof(U));
    for (ll i = 1; i <= M; i += 2) {
      ans.push_back(pll(i, i * 2));
      U[i] = U[i * 2] = true;
    }

    ll m = (M / 2) * 2;
    for (ll i = 2; i <= N; i += 2) {
      if (i + m > N)
        break;
      if (U[i] || U[i + m])
        continue;
      ans.push_back(pll(i, i + m));
      U[i] = U[i + m] = true;
      m -= 2;
    }
    for (ll i = ((M / 2) * 2) + 1; i <= N; i += 2) {
      if (i + m > N)
        break;
      if (U[i] || U[i + m])
        continue;
      ans.push_back(pll(i, i + m));
      U[i] = U[i + m] = true;
      m -= 2;
    }
  }

  REP(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
// Use above if bruteforcing with lots of small operations. Or just use it
// anytime, there's no downside. AVX is better slightly
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))

const ll inf = (1LL << 62);
const int iinf = (1 << 30);
// CLOCKS_PER_SEC

int n, m;
unordered_map<int, bool> mp;

int main() {
  // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  // ios_base::sync_with_stdio(0); cin.tie(0);
  // ifstream cin ("test.in");
  cin >> n >> m;
  bool flag = 1;
  for (int i = 1; i <= m; i++) {
    int oth = n - i + flag;
    if (mp[oth - i] || mp[n + i - oth] || oth - i == n + i - oth) {
      oth--;
      flag = 0;
    }
    cout << i << ' ' << oth << '\\n';
    mp[oth - i] = 1;
    mp[n + i - oth] = 1;
  }

  return 0;
}


Error: -6
2c6fa968-5f60-4762-b4bb-d0ccaaef8f8c.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02697/C++/s821700708.cpp:32: int main(): Assertion `n % 2' failed.


Fixed submission:

#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
// Use above if bruteforcing with lots of small operations. Or just use it
// anytime, there's no downside. AVX is better slightly
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))

const ll inf = (1LL << 62);
const int iinf = (1 << 30);
// CLOCKS_PER_SEC

int n, m;

int main() {
  // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  // ios_base::sync_with_stdio(0); cin.tie(0);
  // ifstream cin ("test.in");
  cin >> n >> m;
  assert(n % 2);
  for (int i = 1; i <= m; i++)
    cout << i << ' ' << n - i + 1 << '\\n';
  return 0;
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y) {
  if (x < y)
    return x;
  return y;
}
ull max(ull x, ull y) {
  if (x < y)
    return y;
  return x;
}
ll min(ll x, ll y) {
  if (x < y)
    return x;
  return y;
}
ll max(ll x, ll y) {
  if (x < y)
    return y;
  return x;
}
double min(double x, double y) {
  if (x < y)
    return x;
  return y;
}
double max(double x, double y) {
  if (x < y)
    return y;
  return x;
}
ull gcd(ull x, ull y) {
  if (!x)
    return y;
  if (!y)
    return x;
  if (x > y)
    swap(x, y);
  return gcd(x, y % x);
}
ull inv(ull a, ull c) { // a,c are coprime and a<c
  if (a == 1) {
    return 1;
  }
  return ((c - (c / a)) * inv(c % a, c)) % c;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

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

  int d = (n - 1) / 2, i = 1;
  while ((m > 0) && (d > 0)) {
    cout << i << " " << i + d << "\\n";
    d -= 2;
    i++;
    m--;
  }
  d = ((n - 1) / 2) - 1;
  i = ((n + 1) / 2) + 1;
  while ((m > 0) && (d > 0)) {
    cout << i << " " << i + d << "\\n";
    d -= 2;
    i++;
    m--;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y) {
  if (x < y)
    return x;
  return y;
}
ull max(ull x, ull y) {
  if (x < y)
    return y;
  return x;
}
ll min(ll x, ll y) {
  if (x < y)
    return x;
  return y;
}
ll max(ll x, ll y) {
  if (x < y)
    return y;
  return x;
}
double min(double x, double y) {
  if (x < y)
    return x;
  return y;
}
double max(double x, double y) {
  if (x < y)
    return y;
  return x;
}
ull gcd(ull x, ull y) {
  if (!x)
    return y;
  if (!y)
    return x;
  if (x > y)
    swap(x, y);
  return gcd(x, y % x);
}
ull inv(ull a, ull c) { // a,c are coprime and a<c
  if (a == 1) {
    return 1;
  }
  return ((c - (c / a)) * inv(c % a, c)) % c;
}

int a[100005] = {0};

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

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

  if (n & 1) {
    for (int i = 1; i <= m; i++) {
      cout << i << " " << n - i + 1 << "\\n";
    }
  } else {
    int j = 1;
    for (int i = 1; i <= m; i++) {
      while (a[j])
        j++;
      cout << j << " " << j + i << "\\n";
      a[j]++;
      a[j + i]++;
    }
  }

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

#include <bits/stdc++.h>
#define m_k make_pair
#define inf 0x3f3f3f3f
using namespace std;
const int N = 200100;
int n, m, vi[N];
signed main() {
  scanf("%d%d", &n, &m);
  if (n & 1) {
    int l, r;
    l = 1;
    r = n;
    for (int i = 1; i <= m; i++) {
      printf("%d %d\\n", l, r);
      l++;
      r--;
    }
  } else {
    int l, r;
    l = 1;
    r = n;
    while (m > 0) {
      if (r - l + 1 == n + 2 - (r - l + 1) || vi[r - l + 1] ||
          vi[n + 2 - (r - l + 1)])
        break;
      vi[r - l + 1] = vi[n + 2 - (r - l + 1)] = 1;
      printf("%d %d\\n", l, r);
      m--;
      l++;
      r--;
    }
    if (m > 0) {
      r--;
      while (m > 0) {
        printf("%d %d\\n", l, r);
        m--;
        l++;
        r--;
      }
    }
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define m_k make_pair
#define inf 0x3f3f3f3f
using namespace std;
const int N = 100100;
int n, m, vi[N];
signed main() {
  scanf("%d%d", &n, &m);
  if (n & 1) {
    int l, r;
    l = 1;
    r = n;
    for (int i = 1; i <= m; i++) {
      printf("%d %d\\n", l, r);
      l++;
      r--;
    }
  } else {
    int l, r;
    l = 1;
    r = n;
    while (m > 0) {
      if (r - l + 1 == n + 2 - (r - l + 1) || vi[r - l + 1] ||
          vi[n + 2 - (r - l + 1)])
        break;
      vi[r - l + 1] = vi[n + 2 - (r - l + 1)] = 1;
      printf("%d %d\\n", l, r);
      m--;
      l++;
      r--;
    }
    if (m > 0) {
      r--;
      printf("%d %d\\n", l, r);
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <assert.h>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
vector<pair<int, int>> ans;
int main() {
  int i, n, m, index = 1;
  scanf("%d%d", &n, &m);
  if (n & 1) {
    int len = n;
    for (i = 1; i <= m; i++) {
      printf("%d %d\\n", index, index + len - 1);
      index++;
      len -= 2;
    }
  } else {
    for (i = 1; i <= n / 4; i++)
      ans.emplace_back(i, n - i + 1);
    for (; i < n - i; i++)
      ans.emplace_back(i, n - i);
    for (i = 0; i < m; i++)
      printf("%d %d\\n", ans[i].first, ans[i].second);
  }
}


Error: WA

Fixed submission:

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <assert.h>
#include <set>
#include <stdio.h>
using namespace std;
set<int> s;
int main() {
  int i, n, m, index = 1;
  scanf("%d%d", &n, &m);
  if (n & 1) {
    int len = n;
    for (i = 1; i <= m; i++) {
      printf("%d %d\\n", index, index + len - 1);
      index++;
      len -= 2;
    }
  } else {
    for (i = 1; i <= n; i++)
      s.insert(i);
    int len = 1;
    for (i = 1; i <= m; i++) {
      int index = *s.begin();
      s.erase(index);
      s.erase(index + len);
      assert(index + len <= n);
      printf("%d %d\\n", index, index + len);
      len++;
    }
  }
}
Problem p02697 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int m, n, tr, cnta, cntb;
int a[100005], b[100005];

int lo(int start, int step) { return (start + step + n - 1) % n + 1; }

int main() {
  cin >> n >> m;
  cnta = 1;
  cntb = n;
  for (int i = 0; i < m; i++) {
    if (i % 2 == 0) {
      a[i] = cnta;
      b[i] = lo(cnta, m - i);
      cnta++;
    } else {
      a[i] = cntb;
      b[i] = lo(cntb, i - m);
      cntb--;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << a[i] << ' ' << b[i] << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int m, n, tr, cnta, cntb;
int a[50005], b[50005];

int lo(int start, int step) { return (start + step + n - 1) % n + 1; }

int main() {
  cin >> n >> m;
  cnta = 1;
  cntb = n;
  for (int i = 0; i < m; i++) {
    if (i % 2 == 0) {
      a[i] = cnta;
      b[i] = lo(cnta, m - i);
      cnta++;
    } else {
      a[i] = cntb;
      b[i] = lo(cntb, i - m);
      cntb--;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << a[i] << ' ' << b[i] << endl;
  }
  return 0;
}
Problem p02698 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <list>
#include <vector>
using namespace std;
typedef long long li;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); i++)
#define df 0
template <class T> void print(const T &t) { cout << t << "\\n"; }
template <class T, class... Ts> void print(const T &t, const Ts &...ts) {
  cout << t;
  if (sizeof...(ts))
    cout << " ";
  print(ts...);
}

void dfs(vector<vector<int>> &adj, vector<int> &ans, const vector<li> &a,
         int parent = -1, int v = 0) {
  static vector<li> lis;

  auto itr = lower_bound(lis.begin(), lis.end(), a[v]);
  int flag = (itr != lis.end());
  int k = itr - lis.begin();
  li memo;
  if (flag) {
    memo = lis[k];
    lis[k] = a[v];
  } else
    lis.push_back(a[v]);

  ans[v] = lis.size();
  for (int x : adj[v]) {
    if (x == parent)
      continue;
    dfs(adj, ans, a, v, x);
  }

  if (flag)
    lis[k] = memo;
  else
    lis.pop_back();
}

int main() {
  int n;
  cin >> n;
  vector<li> a(n);
  rep(i, n) cin >> a[i];
  vector<vector<int>> adj(n);
  rep(i, n - 1) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<int> ans(n, -1);
  dfs(adj, ans, a);

  rep(i, n) print(ans[i]);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <vector>
using namespace std;
typedef long long li;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); i++)
#define df 0
template <class T> void print(const T &t) { cout << t << "\\n"; }
template <class T, class... Ts> void print(const T &t, const Ts &...ts) {
  cout << t;
  if (sizeof...(ts))
    cout << " ";
  print(ts...);
}
// Container コンテナ型, map以外
template <template <class...> class Ctn, class T>
std::ostream &operator<<(std::ostream &os, const Ctn<T> &v) {
  // ここでストリームに obj を書き込みます。
  auto itr = v.begin();
  while (itr != v.end()) {
    if (itr != v.begin())
      cout << " ";
    cout << *(itr++);
  }
  return os;
}

void dfs(vector<vector<int>> &adj, vector<int> &ans, const vector<li> &a,
         int parent = -1, int v = 0) {
  static vector<li> lis;

  auto itr = lower_bound(lis.begin(), lis.end(), a[v]);
  int flag = (itr != lis.end());
  li memo;
  if (flag) {
    memo = *itr;
    *itr = a[v];
  } else
    lis.push_back(a[v]);

  ans[v] = lis.size();
  for (int x : adj[v]) {
    if (x == parent)
      continue;
    dfs(adj, ans, a, v, x);
  }

  if (flag)
    *itr = memo;
  else
    lis.pop_back();
}

int main() {
  int n;
  cin >> n;
  vector<li> a(n);
  rep(i, n) cin >> a[i];
  vector<vector<int>> adj(n);
  rep(i, n - 1) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<int> ans(n, -1);
  dfs(adj, ans, a);

  rep(i, n) print(ans[i]);
}