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

#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
typedef signed long long ll;
#define FOR(i, to) for (i = 0; i < (to); i++)

int64_t n;

int main() {
  int i, j, k, l, r, x, y;
  string s;

  ll N;
  cin >> N;
  ll a[N];
  ll b[N];
  FOR(i, N) cin >> a[i] >> b[i];

  sort(a, a + N);
  sort(b, b + N);

  ll ans;
  if (N % 2 == 0) {
    if (N == 2) {
      ans = (b[0] - a[0] + 1) + (b[1] - a[1] + 1) - 1;
      std::cout << ans << "\\n";
    } else {
      ans = (b[N / 2 - 1] - a[N / 2 - 1] + 1) + (b[N / 2] - a[N / 2] + 1) - 1;
      std::cout << ans << "\\n";
    }
  } else {
    std::cout << b[(N + 1) / 2 - 1] - a[(N + 1) / 2 - 1] + 1 << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
typedef signed long long ll;
#define FOR(i, to) for (i = 0; i < (to); i++)

int64_t n;

int main() {
  int i, j, k, l, r, x, y;
  string s;
  ll N;
  cin >> N;
  ll a[N];
  ll b[N];
  FOR(i, N) cin >> a[i] >> b[i];

  sort(a, a + N);
  sort(b, b + N);

  ll min;
  ll max;
  ll ans;
  if (N % 2 == 0) {
    if (N == 2) {
      ans = (b[0] - a[0] + 1) + (b[1] - a[1] + 1) - 1;
      std::cout << ans << "\\n";
    } else {
      for (i = N / 2 - 2; i >= 0; i--) {
        if (a[N / 2 - 1] < (a[i] + a[N / 2]) / 2) {
          min = i + 1;
        }
      }
      for (i = N / 2 + 1; i < N; i++) {
        if ((b[N / 2 - 1] + b[i]) / 2 > a[N / 2]) {
          max = i - 1;
        }
      }
      ans = (b[N / 2 - 1] - a[min] + 1) + (b[max] - a[N / 2] + 1) - 1;
      std::cout << ans << "\\n";
    }
  } else {
    std::cout << b[(N + 1) / 2 - 1] - a[(N + 1) / 2 - 1] + 1 << "\\n";
  }
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll, ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\\n"
#define MOD 1000000007
using namespace std;

ll const N = 2e5 + 1;
pll req[N];
ll n;

bool myCompare(const pll &a, const pll &b) {
  if (a.ff != b.ff)
    return (a.ff < b.ff);

  return a.snd < b.snd;
}

bool sortbysec(const pll &a, const pll &b) { return a.snd < b.snd; }

void solve() {
  cin >> n;

  for (int i = 0; i < n; i++)
    cin >> req[i].ff >> req[i].snd;

  if (n == 1) {
    cout << req[0].snd - req[0].ff + 1;
    return;
  }

  if (n & 1) {
    sort(req, req + n, myCompare);

    ll st = req[n / 2].ff;

    sort(req, req + n, sortbysec);

    ll end = req[n / 2].snd;

    cout << end - st + 1 << endl;
    return;
  }

  sort(req, req + n, myCompare);
  double st = (double(req[n / 2].ff + req[(n / 2) - 1].ff) / 2.0);

  sort(req, req + n, sortbysec);
  double end = (double(req[n / 2].snd + req[(n / 2) - 1].snd) / 2.0);

  double p = end - st + 1;

  ll k = p;
  if (p == k) {
    cout << k + k - 1;
  } else {
    cout << k + k;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  //	    cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll, ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5 + 1, inf = 1e9;
pll req[N];
ll n;

bool myCompare(const pll &a, const pll &b) {
  if (a.ff != b.ff)
    return (a.ff < b.ff);

  return a.snd < b.snd;
}

bool sortbysec(const pll &a, const pll &b) { return a.snd < b.snd; }

void solve() {
  cin >> n;

  for (int i = 0; i < n; i++)
    cin >> req[i].ff >> req[i].snd;

  if (n == 1) {
    cout << req[0].snd - req[0].ff + 1;
    return;
  }

  if (n & 1) {
    sort(req, req + n, myCompare);
    ll st = req[n / 2].ff;
    sort(req, req + n, sortbysec);
    ll end = req[n / 2].snd;
    cout << end - st + 1 << endl;
    return;
  }

  sort(req, req + n, myCompare);
  double st = (double(req[n / 2].ff + req[n / 2 - 1].ff) / 2.0);

  sort(req, req + n, sortbysec);
  double end = (double(req[n / 2].snd + req[n / 2 - 1].snd) / 2.0);

  double p = ceil(end - st + 1);

  p += p - 1;
  cout << p;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  //	    cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
constexpr int MX = 200005;
int n, a[MX], b[MX], ans;
int main() {
  scanf("%d", &n);
  rep(i, n) scanf("%d%d", a + i, b + i);
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2)
    ans = b[n / 2] - a[n / 2] + 1;
  else
    ans = b[n / 2 - 1] - a[n / 2 - 1] + b[n / 2] - a[n / 2] + 1;
  printf("%d\\n", ans);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
constexpr int MX = 100005;
int n, a[MX], b[MX], ans;
int main() {
  scanf("%d", &n);
  rep(i, n) scanf("%d%d", a + i, b + i);
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2)
    ans = b[n / 2] - a[n / 2] + 1;
  else
    ans = b[n / 2 - 1] - a[n / 2 - 1] + b[n / 2] - a[n / 2] + 1;
  printf("%d\\n", ans);
}
Problem p02661 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n, a[200003], b[200003];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  sort(a, a + n);
  sort(b, b + n);
  if (n & 1)
    cout << b[n / 2] - a[n / 2] + 1 << "\\n";
  else
    cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1 << "\\n";
}

// 1 2
// 2 4
// 5 5
// 7 9
// 9 10

Error: TLE

Fixed submission:

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

int n, ans = 0;
map<int, pair<int, int>> seg; // first add, second remove

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    seg[a].first++;
    seg[b + 1].second++;
  }
  int l = 0, r = n, start = -1, cnt = 0;
  bool startcnt = 1;
  for (int i = 1; i <= (int)1e9; i++) {
    l += seg[i].first;
    r -= seg[i].second;
    cnt += seg[i].first;
    cnt -= seg[i].second;
    if ((n % 2 == 1 && l > (n / 2) && r > (n / 2)) ||
        (n % 2 == 0 && l >= (n / 2) && r >= (n / 2))) {
      if (cnt > 0)
        ans++;
    }
  }
  cout << ans << "\\n";
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

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

const int nm = 2e5;
int n, a[nm], b[nm];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];

  sort(a, a + n);
  sort(b, b + n);

  if (n & 1) {
    cout << b[n / 2] - a[n / 2] + 1 << endl;
  } else {
    cout << b[n / 2 - 1] + b[n / 2] - a[n / 2 - 1] - a[n / 2] + 1 << endl;
  }
}


Error: 0

Fixed submission:

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

const int nm = 1e5;
int n, a[nm], b[nm];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];

  sort(a, a + n);
  sort(b, b + n);

  if (n & 1) {
    cout << b[n / 2] - a[n / 2] + 1 << endl;
  } else {
    cout << b[n / 2 - 1] + b[n / 2] - a[n / 2 - 1] - a[n / 2] + 1 << endl;
  }
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll M = 1e9 + 7;
const ll INF = 1e9 + 7;

ll n;
ll a[220000], b[220000];

int main() {
  cin >> n;

  for (ll i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  sort(a, a + n);
  sort(b, b + n);

  if (n % 2) {
    cout << b[n / 2] - a[n / 2] + 1 << endl;
  } else {
    cout << b[n / 2 - 1] + b[n / 2] - a[n / 2 - 1] - a[n / 2] + 1 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll M = 1e9 + 7;
const ll INF = 1e9 + 7;

ll n;
ll a[110000], b[110000];

int main() {
  cin >> n;

  for (ll i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  sort(a, a + n);
  sort(b, b + n);

  if (n % 2) {
    cout << b[n / 2] - a[n / 2] + 1 << endl;
  } else {
    cout << b[n / 2 - 1] + b[n / 2] - a[n / 2 - 1] - a[n / 2] + 1 << endl;
  }

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

#include <algorithm>
#include <iostream>
using namespace std;

typedef long long ll;
ll a[200005], b[200005];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  if (n % 2 == 1) {
    cout << (ll)(b[n / 2 + 1] - a[n / 2 + 1] + 1) << endl;
  } else {
    cout << (ll)(b[n / 2] + b[n / 2 + 1] - a[n / 2] - a[n / 2 + 1] + 1) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

typedef long long ll;
ll a[100005], b[100005];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  if (n % 2 == 1) {
    cout << (ll)(b[n / 2 + 1] - a[n / 2 + 1] + 1) << endl;
  } else {
    cout << (ll)(b[n / 2] + b[n / 2 + 1] - a[n / 2] - a[n / 2 + 1] + 1) << endl;
  }
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

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

long long N;
vector<long long> A;
vector<long long> B;
int main() {
  cin >> N;
  for (long long i = 0; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  if (N % 2 == 1) {
    long long left = A[N / 2];
    long long right = B[N / 2];
    // cout << "left: " << left << endl;
    // cout << "right: " << right << endl;
    cout << right - left + 1 << endl;
    return 0;
  }

  long long left1 = A[N / 2 - 1];
  long long right1 = B[N / 2 - 1];
  long long left2 = A[N / 2];
  long long right2 = B[N / 2];
  // cout << "left1: " << left1 << endl;
  // cout << "right1: " << right1 << endl;
  // cout << "left2: " << left2 << endl;
  // cout << "right2: " << right2 << endl;
  cout << right1 + right2 - left1 - left2 + 1 << endl;
  return 0;
}

Error: 255

Fixed submission:

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

long long N;
vector<long long> A;
vector<long long> B;
int main() {
  cin >> N;
  for (long long i = 0; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  if (N % 2 == 1) {
    long long left = A[N / 2];
    long long right = B[N / 2];
    // cout << "left: " << left << endl;
    // cout << "right: " << right << endl;
    cout << right - left + 1 << endl;
    return 0;
  }

  long long left1 = A[N / 2 - 1];
  long long right1 = B[N / 2 - 1];
  long long left2 = A[N / 2];
  long long right2 = B[N / 2];
  // cout << "left1: " << left1 << endl;
  // cout << "right1: " << right1 << endl;
  // cout << "left2: " << left2 << endl;
  // cout << "right2: " << right2 << endl;
  cout << right1 + right2 - left1 - left2 + 1 << endl;
  return -1;
}
Problem p02661 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void Main() {
  int N;
  cin >> N;

  int A[N], B[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  sort(A, A + N);
  sort(B, B + N);

  if (N % 2) {
    int a = A[(N + 1) / 2 - 1];
    int b = B[(N + 1) / 2 - 1];
    cout << b - a + 1 << endl;
  } else {
    double a = (A[(N / 2) - 1] + A[N / 2]) / 2.0;
    double b = (B[(N / 2) - 1] + B[N / 2]) / 2.0;
    cout << (int)((b - a) / 0.5 + 1) << endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: TLE

Fixed submission:

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

void Main() {
  int N;
  cin >> N;

  int A[N], B[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  sort(A, A + N);
  sort(B, B + N);

  long long ans = 0;
  if (N % 2) {
    int a = A[(N + 1) / 2 - 1];
    int b = B[(N + 1) / 2 - 1];
    for (int i = a; i <= b; i++) {
      ans++;
    }
  } else {
    double a = (A[(N / 2) - 1] + A[N / 2]) / 2.0;
    double b = (B[(N / 2) - 1] + B[N / 2]) / 2.0;
    for (double i = a; i <= b; i += 0.5) {
      ans++;
    }
  }

  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int maxn = 2e5 + 5;
int n;
int a[maxn], b[maxn];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d %d", a + i, b + i);
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2 == 1) {
    printf("%lld\\n", (ll)b[n / 2] - a[n / 2] + 1);
  } else {
    printf("%lld\\n", (ll)b[n / 2 - 1] + b[n / 2] - a[n / 2 - 1] - a[n / 2] + 1);
  }

  return 0;
}

Error: -6
f1b72001-3589-4859-b308-6b8bd7d4caab.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02661/C++/s205363837.cpp:10: int main(): Assertion `n % 2 == 1' failed.


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 5;
int a[maxn], b[maxn];

int main() {
  int n;
  scanf("%d", &n);
  assert(n % 2 == 1);
  for (int i = 0; i < n; i++)
    scanf("%d %d", a + i, b + i);
  sort(a, a + n);
  sort(b, b + n);
  int ans = b[n / 2] - a[n / 2] + 1;
  printf("%d\\n", ans);
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    cin >> b.at(i);
  }
  // debug a,b
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ll res;
  if (n % 2 == 1)
    res = b.at((n) / 2) - a.at((n) / 2) + 1;
  else
    res = b.at(n / 2 - 1) + b.at(n / 2) - a.at(n / 2 - 1) - a.at(n / 2) + 1;
  cout << res << endl;
  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

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

#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a, b;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    cin >> b.at(i);
  }
  // debug a,b
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ll res;
  if (n % 2 == 1)
    res = b.at((n) / 2) - a.at((n) / 2) + 1;
  else
    res = b.at(n / 2 - 1) + b.at(n / 2) - a.at(n / 2 - 1) - a.at(n / 2) + 1;
  cout << res << endl;
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

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

#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)

typedef long long ll;

const int N = 2e5 + 5;

template <typename T> void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  x *= f;
}

int n;
int l[N], r[N];
int p, q;

int main() {
  read(n);
  Rep(i, 1, n) read(l[i]), read(r[i]);
  sort(l + 1, l + n + 1);
  sort(r + 1, r + n + 1);
  if (n % 2 == 0) {
    p = l[n >> 1] + l[(n >> 1) + 1], q = r[n >> 1] + r[(n >> 1) + 1];
    printf("%d\\n", q - p + 1);
  } else {
    p = l[n + 1 >> 1], q = r[n + 1 >> 1];
    printf("%d\\n", q - p + 1);
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)

typedef long long ll;

const int N = 1e5 + 5;

template <typename T> void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  x *= f;
}

int n;
int l[N], r[N];
int p, q;

int main() {
  read(n);
  Rep(i, 1, n) read(l[i]), read(r[i]);
  sort(l + 1, l + n + 1);
  sort(r + 1, r + n + 1);
  if (n % 2 == 0) {
    p = l[n >> 1] + l[(n >> 1) + 1], q = r[n >> 1] + r[(n >> 1) + 1];
    printf("%d\\n", q - p + 1);
  } else {
    p = l[n + 1 >> 1], q = r[n + 1 >> 1];
    printf("%d\\n", q - p + 1);
  }
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;

typedef long long ll;

ll l[200005], r[200005];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
  }
  sort(l, l + n);
  sort(r, r + n);
  if (n % 2 == 1) {
    cout << abs(r[n / 2] - l[n / 2]) + 1 << '\\n';
  } else {
    ll l1 = l[n / 2];
    ll l2 = l[n / 2 - 1];
    ll r1 = r[n / 2];
    ll r2 = r[n / 2 - 1];
    cout << r1 + r2 - l1 - l2 + 1 << '\\n';
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

typedef long long ll;

ll l[100005], r[100005];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
  }
  sort(l, l + n);
  sort(r, r + n);
  if (n % 2 == 1) {
    cout << abs(r[n / 2] - l[n / 2]) + 1 << '\\n';
  } else {
    ll l1 = l[n / 2];
    ll l2 = l[n / 2 - 1];
    ll r1 = r[n / 2];
    ll r2 = r[n / 2 - 1];
    cout << r1 + r2 - l1 - l2 + 1 << '\\n';
  }
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

// AtCoder template
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)

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

  int n;
  cin >> n;
  ll a, b;
  vector<pair<ll, ll>> p1(n), p2(n);
  rep(i, n) {
    cin >> a >> b;
    p1[i] = make_pair(a, b);
    p2[i] = make_pair(a, b);
  }
  sort(p1.begin(), p1.end());
  sort(p2.begin(), p2.end(), [](pair<ll, ll> a, pair<ll, ll> b) {
    if (a.second == b.second) {
      return a.first < b.first;
    } else {
      return a.second < b.second;
    }
  });
  if (n % 2) {
    cout << p2[n / 2].second - p1[n / 2].first + 1 << endl;
  } else {
    cout << (p2[n / 2].second + p2[n / 2 - 1].second) -
                (p1[n / 2].first + p1[n / 2 - 1].first) + 1
         << endl;
  }
}

Error: 0

Fixed submission:

// AtCoder template
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)

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

  int n;
  cin >> n;
  ll a, b;
  vector<pair<ll, ll>> p1(n), p2(n);
  rep(i, n) {
    cin >> a >> b;
    p1[i] = make_pair(a, b);
    p2[i] = make_pair(a, b);
  }
  sort(p1.begin(), p1.end());
  sort(p2.begin(), p2.end(), [](pair<ll, ll> a, pair<ll, ll> b) {
    if (a.second == b.second) {
      return a.first < a.second;
    } else {
      return a.second < b.second;
    }
  });
  if (n % 2) {
    cout << p2[n / 2].second - p1[n / 2].first + 1 << endl;
  } else {
    cout << (p2[n / 2].second + p2[n / 2 - 1].second) -
                (p1[n / 2].first + p1[n / 2 - 1].first) + 1
         << endl;
  }
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

// nani?
#include <bits/stdc++.h>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i, a, b) for (int i = a; i < b; i++)
#define sor(a) sort(a.begin(), a.end())
#define rsor(a) sort(a.rbegin(), a.rend())
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
// #define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
const ll inf = 1e10 + 6;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
// ac cmtr;
const int MAX_N = 2e5 + 5;
const int LG = 25;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
//---------------------------

// pair <ll,ll> a[MAX_N];

int main() {
  fastio;
  ll n;
  cin >> n;
  vector<ll> v;
  vector<ll> g;
  f(i, 0, n) {
    ll a, b;
    cin >> a >> b;
    v.pb(a);
    g.pb(b);
  }
  sor(v);
  sor(g);
  ll ans = 0;
  if (n & 1) {
    ans = g[n / 2] - v[n / 2] + 1;
  } else {
    ans = (g[n / 2 - 1] + g[n / 2]) - (v[n / 2 - 1] + v[n / 2]) + 1;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

// nani?
#include <bits/stdc++.h>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i, a, b) for (int i = a; i < b; i++)
#define sor(a) sort(a.begin(), a.end())
#define rsor(a) sort(a.rbegin(), a.rend())
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
// #define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
const ll inf = 1e10 + 6;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
// ac cmtr;
const int MAX_N = 1e5 + 5;
const int LG = 25;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
//---------------------------

pair<ll, ll> a[MAX_N];

int main() {
  fastio;
  ll n;
  cin >> n;
  f(i, 0, n) { cin >> a[i].fs >> a[i].sc; }
  sort(a, a + n);
  ll ans = 0;
  if (n & 1) {
    ans = a[n / 2].sc - a[n / 2].fs + 1;
  } else {
    ans = (a[n / 2 - 1].sc + a[n / 2].sc) - (a[n / 2 - 1].fs + a[n / 2].fs) + 1;
  }
  cout << ans << endl;
}