Problem p02661 (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 < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VP vector<pair<int, int>>
#define VPP vector<pair<int, pair<int, int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)
typedef pair<int, int> P;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1e9 + 7;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != 1)
        ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {

  int n;
  cin >> n;

  vector<pair<ll, ll>> p(n);
  vector<pair<ll, ll>> q(n);

  REP(i, n) {
    int a, b;
    cin >> a >> b;
    p[i] = {a, b};
    q[i] = {b, a};
  }
  sort(ALL(p));
  sort(ALL(q));

  if (n % 2 == 1) {
    ll l = p[n / 2].first;
    ll r = q[n / 2].first;
    cout << r - l + 1 << endl;
    return 0;
  }
  ll l = p[n / 2 - 1].first;
  ll r = q[n / 2 - 1].first;

  ll la = p[n / 2].first;
  ll ra = q[n / 2].first;

  cout << ra + r - la - l + 1 << endl;
}


Error: -6
51ab8969-31d8-4a49-9e46-4453ca71a3eb.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02661/C++/s443124557.cpp:99: int main(): Assertion `n == 0' failed.


Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VP vector<pair<int, int>>
#define VPP vector<pair<int, pair<int, int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)
typedef pair<int, int> P;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1e9 + 7;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != 1)
        ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {

  int n;
  cin >> n;

  vector<pair<ll, ll>> p(n);
  vector<pair<ll, ll>> q(n);

  REP(i, n) {
    int a, b;
    cin >> a >> b;
    p[i] = {a, b};
    q[i] = {b, a};
  }

  sort(ALL(p));
  sort(ALL(q));
  reverse(ALL(q));

  if (n % 2 == 1) {
    ll c = INF;
    ll d = 0;
    REP(i, n) {
      if (i < n / 2) {
        d = max(d, p[i].second);
      } else {
        c = min(c, p[i].first);
        if (d < p[i].first)
          break;
        d = max(d, p[i].second);
      }
    }
    ll e = 0;
    ll f = INF;
    REP(i, n) {
      if (i < n / 2) {
        f = min(f, q[i].second);
      } else {
        if (f > q[i].first)
          break;
        e = max(e, q[i].first);
        f = min(f, q[i].second);
      }
    }
    cout << c << ' ' << d << ' ' << e << ' ' << f << endl;
    if (f <= d) {
      cout << e - c + 1 << endl;
    } else {
      cout << d - c + 1 + e - f + 1 << endl;
    }
    return 0;
  } else {
    assert(n == 0);
  }
}