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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\\n"

template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> ostream &operator<<(ostream &s, const complex<T> &d) {
  return s << "(" << d.real() << ", " << d.imag() << ")";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
  return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &d) {
  int len = d.size();
  rep(i, len) {
    s << d[i];
    if (i < len - 1)
      s << " ";
  }
  return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &d) {
  int len = d.size();
  rep(i, len) { s << d[i] << endl; }
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const set<T> &v) {
  s << "{ ";
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    if (itr != v.begin()) {
      s << ", ";
    }
    s << (*itr);
  }
  s << " }";
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const multiset<T> &v) {
  s << "{ ";
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    if (itr != v.begin()) {
      s << ", ";
    }
    s << (*itr);
  }
  s << " }";
  return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
  s << "{" << endl;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    s << " " << (*itr).first << " : " << (*itr).second << endl;
  }
  s << "}" << endl;
  return s;
}

const ll mod = 1e9 + 7;
const ll inf = 1e17;
const int INF = 1e9;
const double EPS = 1e-10;
const double PI = acos(-1);

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  vector<P> g(n), g2(n);
  rep(i, n) {
    cin >> a[i] >> b[i];
    g[i].fi = a[i], g[i].se = b[i];
    g2[i] = g[i];
  }
  sort(begin(g), end(g));
  sort(begin(g2), end(g2), [&](const P &a, const P &b) { return a.se < b.se; });
  ll ans = 0;
  vector<P> cnt(n);
  rep(i, n) { cnt[i] = P(g[i].fi, g2[i].se); }
  if (n % 2) {
    cout << cnt[n / 2].se - cnt[n / 2].fi + 1 << endl;
  } else {
    ll l1 = cnt[n / 2 - 1].fi, l2 = cnt[n / 2].fi;
    ll r1 = cnt[n / 2 - 1].se, r2 = cnt[n / 2].se;
    // chmin(r1,l2);
    ll ans = (r2 - l2 + 1) + (r1 - l1);
    cout << ans << endl;
  }
}

Error: -6
9ce70474-561b-4e1e-851e-1eed11d4c60d.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02661/C++/s946596088.cpp:50: int main(): Assertion `n%2' failed.


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\\n"

template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> ostream &operator<<(ostream &s, const complex<T> &d) {
  return s << "(" << d.real() << ", " << d.imag() << ")";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
  return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &d) {
  int len = d.size();
  rep(i, len) {
    s << d[i];
    if (i < len - 1)
      s << " ";
  }
  return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &d) {
  int len = d.size();
  rep(i, len) { s << d[i] << endl; }
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const set<T> &v) {
  s << "{ ";
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    if (itr != v.begin()) {
      s << ", ";
    }
    s << (*itr);
  }
  s << " }";
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const multiset<T> &v) {
  s << "{ ";
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    if (itr != v.begin()) {
      s << ", ";
    }
    s << (*itr);
  }
  s << " }";
  return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
  s << "{" << endl;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    s << " " << (*itr).first << " : " << (*itr).second << endl;
  }
  s << "}" << endl;
  return s;
}

const ll mod = 1e9 + 7;
const ll inf = 1e17;
const int INF = 1e9;
const double EPS = 1e-10;
const double PI = acos(-1);

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  vector<P> g(n), g2(n);
  rep(i, n) {
    cin >> a[i] >> b[i];
    g[i].fi = a[i], g[i].se = b[i];
    g2[i] = g[i];
  }
  sort(begin(g), end(g));
  sort(begin(g2), end(g2), [&](const P &a, const P &b) { return a.se < b.se; });
  ll ans = 0;
  vector<ll> cnt(n, 0);
  ll r = -1;
  rep(i, n) { cnt[i] = g2[i].se - g[i].fi + 1; }
  assert(n % 2);
  if (n % 2) {
    cout << cnt[n / 2] << endl;
  }
}