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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define initdp(a, b)                                                           \\
  for (int i = 0; i <= a; i++)                                                 \\
    for (int j = 0; j <= b; j++)                                               \\
      dp[i][j] = -1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define ppi pair<pii, int>
#define pip pair<int, pii>
#define ll long long
#define pll pair<ll, ll>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void mad(ll &a, ll b) {
  a = (a + b) % mod;
  if (a < 0)
    a += mod;
}
ll gcd(ll a, ll b) {
  if (!a)
    return b;
  return gcd(b % a, a);
}
int mk[100005];
void solve() {
  int n, m;
  cin >> n >> m;
  int i = 1;
  while (m--) {
    int j = n - i + 1;
    if (n % 2 == 0 && i > n / 4)
      j--;
    cout << i << " " << j << "\\n";
    i++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define initdp(a, b)                                                           \\
  for (int i = 0; i <= a; i++)                                                 \\
    for (int j = 0; j <= b; j++)                                               \\
      dp[i][j] = -1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define ppi pair<pii, int>
#define pip pair<int, pii>
#define ll long long
#define pll pair<ll, ll>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void mad(ll &a, ll b) {
  a = (a + b) % mod;
  if (a < 0)
    a += mod;
}
ll gcd(ll a, ll b) {
  if (!a)
    return b;
  return gcd(b % a, a);
}
int mk[100005];
void solve() {
  int n, m;
  cin >> n >> m;
  int i = 1, j = 0;
  while (m--) {
    while (mk[i])
      i++;
    int u = i;
    int v = (i + j) % n + 1;
    cout << u << " " << v << "\\n";
    mk[u] = mk[v] = 1;
    j++;
    // cout<<i<<" "<<n+1-i<<"\\n";
    // i++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
}