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

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map<int, int>
#define mll map<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vd vector<double>
#define vll vector<ll>
#define fi first
#define se second
#define si set<int>
#define sll set<ll>
#define spii set<pii>
#define vs vector<string>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long, long long>>
#define vvi vector<vector<int>>
#define vvpii vector<vector<pii>>
#define mp make_pair
#define vvll vector<vll>
#define vsi vector<si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const ll INFLL = 1e18;
const int MAXN = 1e6 + 100;
const ll INF = 1e9;
const ll mod1 = 1e9 + 7;
const ll mod2 = 2e9 + 11;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  int n, m;
  cin >> n >> m;
  vector<pii> a;
  int left = 0, right = 1;
  int now = 0;
  a.pb(mp(left, right));
  if (n % 2 == 1) {
    for (int i = 0; i < (n - 1) / 2 - 1; i++)
      a.pb({(left - 1 + n) % n, (right + 1 + n) % n}), now += 2, left--,
          right++;
  } else {
    while (now + 3 <= (n - 1) / 2)
      a.pb({(left - 1 + n) % n, (right + 1 + n) % n}), now += 2, left--,
          right++;
    left--;
    now = 1;
    while (now + 2 <= (n - 1) / 2 + 1)
      a.pb({(left - 1 + n) % n, (right + 1 + n) % n}), now += 2, left--,
          right++;
  }
  for (int i = 0; i < m; i++) {
    if (a[i].fi != 0 && a[i].se != 0)
      cout << a[i].fi << " " << a[i].se << '\\n';
    else {
      if (a[i].fi == 0)
        cout << n << " " << a[i].se << '\\n';
      else
        cout << a[i].fi << " " << n << '\\n';
    }
  }
  //    set <int> s;
  //    for (int i=0;i<a.size();i++)
  //        s.insert(abs((a[i].fi-a[i].se)%n));
  //    cout<<s.size()<<'\\n';
}


Error: WA

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map<int, int>
#define mll map<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vd vector<double>
#define vll vector<ll>
#define fi first
#define se second
#define si set<int>
#define sll set<ll>
#define spii set<pii>
#define vs vector<string>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long, long long>>
#define vvi vector<vector<int>>
#define vvpii vector<vector<pii>>
#define mp make_pair
#define vvll vector<vll>
#define vsi vector<si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const ll INFLL = 1e18;
const int MAXN = 1e6 + 100;
const ll INF = 1e9;
const ll mod1 = 1e9 + 7;
const ll mod2 = 2e9 + 11;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  int n, m;
  cin >> n >> m;
  vector<pii> a;
  assert(n % 2 == 0);
  int left = 0, right = 1;
  int now = 0;
  a.pb(mp(left, right));
  if (n % 2 == 1) {
    for (int i = 0; i < (n - 1) / 2 - 1; i++)
      a.pb({(left - 1 + n) % n, (right + 1 + n) % n}), now += 2, left--,
          right++;
  } else {
    while (now + 2 <= (n - 2) / 2)
      a.pb({(left - 1 + n) % n, (right + 1 + n) % n}), now += 2, left--,
          right++;
    left--;
    now = 1;
    while (now + 2 <= (n - 2) / 2)
      a.pb({(left - 1 + n) % n, (right + 1 + n) % n}), now += 2, left--,
          right++;
  }
  for (int i = 0; i < m; i++) {
    if (a[i].fi != 0 && a[i].se != 0)
      cout << a[i].fi << " " << a[i].se << '\\n';
    else {
      if (a[i].fi == 0)
        cout << n << " " << a[i].se << '\\n';
      else
        cout << a[i].fi << " " << n << '\\n';
    }
  }
  //    set <int> s;
  //    for (int i=0;i<a.size();i++)
  //        s.insert(abs((a[i].fi-a[i].se)%n));
  //    cout<<s.size()<<'\\n';
}