alexjercan/bugnet huggingface dataset:
Problem p02661 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c)                                                            \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\\n"

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long lint;

using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lint n;
  cin >> n;
  vector<lint> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(all(a));
  sort(all(b));
  lint mmax, mmin;
  if (n % 2 == 0) {
    mmin = a[n / 2 - 1] + a[n / 2];
    mmax = b[n / 2 - 1] + b[n / 2];
    cout << (mmax - mmin) + 1 << endl;
  } else {
    mmin = a[n / 2];
    mmax = b[n / 2];
    cout << (mmax - mmin) + 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c)                                                            \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\\n"

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long lint;

using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lint n;
  cin >> n;
  vector<lint> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(all(a));
  sort(all(b));
  lint max, min;
  min = a[-1 + (n + 1) / 2];
  max = b[-1 + (n + 1) / 2];
  if (n % 2 == 0) {
    set<long double> m;
    for (int i = min; i <= max; i++) {
      for (int j = i; j <= max; j++) {
        m.insert((i + j) / 2.0);
      }
    }
    cout << SZ(m) << endl;
  } else
    cout << max - min + 1 << endl;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
void read(int &x) {
  int f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-')
      f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  x *= f;
}
#define ll long long
ll le[200005];
ll ri[200005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> le[i] >> ri[i];
  }
  sort(le + 1, le + n + 1);
  sort(ri + 1, ri + n + 1);
  if (n % 2 == 1) {
    cout << ri[n / 2 + 1] - le[n / 2 + 1] + 1LL << endl;

  } else {
    cout << ri[n / 2] + ri[n / 2 + 1] - le[n / 2] - le[n / 2 + 1] + 1LL << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
void read(int &x) {
  int f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-')
      f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  x *= f;
}
#define ll long long
ll le[100005];
ll ri[100005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> le[i] >> ri[i];
  }
  sort(le + 1, le + n + 1);
  sort(ri + 1, ri + n + 1);
  if (n % 2 == 1) {
    cout << ri[n / 2 + 1] - le[n / 2 + 1] + 1LL << endl;

  } else {
    cout << ri[n / 2] + ri[n / 2 + 1] - le[n / 2] - le[n / 2 + 1] + 1LL << endl;
  }

  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <vector>

#include <algorithm>

using namespace std;

int main() {
  int N;

  vector<int> va;
  vector<int> vb;

  cin >> N;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;

    va.push_back(a);
    vb.push_back(b);
  }

  if (N % 2 == 1) { // 奇数

    sort(va.begin(), va.end());
    int min = va[(N + 1) / 2 - 1];

    sort(vb.begin(), vb.end());
    int max = vb[(N + 1) / 2 - 1];

    cout << max - min + 1;

  } else {

    sort(va.begin(), va.end());
    int min = va[(N) / 2 - 1];
    int min1 = va[(N) / 2];

    sort(vb.begin(), vb.end());
    int max = vb[(N) / 2 - 1];
    int max1 = vb[(N) / 2];

    int s = -1;
    if ((min + min1) % 2 == 1)
      s--;
    if ((max + max1) % 2 == 1)
      s++;

    min = (min + min1) / 2;
    max = (max + max1) / 2;

    cout << (max - min + 1) * 2 + s;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
#include <vector>

#include <algorithm>

using namespace std;

int main() {
  int N;

  vector<int> va;
  vector<int> vb;

  cin >> N;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;

    va.push_back(a);
    vb.push_back(b);
  }

  if (N % 2 == 1) { // 奇数

    sort(va.begin(), va.end());
    int min = va[(N + 1) / 2 - 1];

    sort(vb.begin(), vb.end());
    int max = vb[(N + 1) / 2 - 1];

    cout << max - min + 1;

  } else {

    sort(va.begin(), va.end());
    int min = va[(N) / 2 - 1];
    int min1 = va[(N) / 2];

    sort(vb.begin(), vb.end());
    int max = vb[(N + 1) / 2 - 1];
    int max1 = vb[(N + 1) / 2];

    set<float> se;
    for (int i = min; i <= max; i++) {
      for (int j = min1; j <= max1; j++) {
        float f = (i + j) / 2.0f;
        se.insert(f);
      }
    }

    cout << se.size();
  }

  cin >> N;

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N = 2e5 + 5;
#define inf 1e18 + 8
const int mod = 1e9 + 7;
#define pii pair<int, int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define vpii vector<pair<int, int>>
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

signed main() {
  int n, m;
  cin >> n;
  vi arr(n);
  vi A(n);
  vi B(n);
  // for(int i=0;i<n;i++) cin>>arr[i];
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  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";
  }
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N = 2e5 + 5;
int dist[200005];
int inf = 1e18;
int arr[N];
int n;

#define float long double
#define vi vector<int>
// count of every prime factor
signed main() {
  int n;
  vi A(n), B(n);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
  }
  if (n & 1) {
    cout << B[(n - 1) / 2] - A[(n - 1) / 2] + 1;

  } else {
    int x = n / 2 - 1;
    int y = n / 2;
    cout << B[x] + B[y] - A[x] - A[y] + 1;
  }
}
Problem p02661 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vec<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  int inf = 2e9 + 1;
  if (N % 2 == 1) {
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int a = A[N / 2], b = B[N / 2];
    cout << b - a + 1 << "\\n";
  } else {
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int a = A[N / 2 - 1] + A[N / 2], b = B[N / 2 - 1] + B[N / 2];
    cout << b - a + 1 << "\\n";
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vec<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  int inf = 2e9 + 1;
  if (N % 2 == 1) {
    int la = 0, ra = inf;
    while (la + 1 < ra) {
      int m = (la + ra) / 2;
      int c = 0;
      for (int i = 0; i < N; i++) {
        if (A[i] <= m)
          c++;
      }
      if (c >= (N + 1) / 2)
        ra = m;
      else
        la = m;
    }
    int lb = 0, rb = inf;
    while (lb + 1 < rb) {
      int m = (lb + rb) / 2;
      int c = 0;
      for (int i = 0; i < N; i++) {
        if (m <= B[i])
          c++;
      }
      if (c >= (N + 1) / 2)
        lb = m;
      else
        rb = m;
    }
    cout << lb - ra + 1 << "\\n";
  } else {
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int a = A[N / 2 - 1] + A[N / 2], b = B[N / 2 - 1] + B[N / 2];
    cout << b - a + 1 << "\\n";
  }
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e5 + 4;
int n;
int A[MAXN], B[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &A[i], &B[i]);
  sort(A + 1, A + n + 1);
  sort(B + 1, B + n + 1);
  if (n & 1) {
    printf("%lld\\n", 1LL + B[(n + 1) / 2] - A[(n + 1) / 2]);
  } else {
    int p = n / 2;
    printf("%lld\\n", 1LL + B[p + 1] - A[p + 1] + B[p] - A[p]);
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1e5 + 4;
int n;
int A[MAXN], B[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &A[i], &B[i]);
  sort(A + 1, A + n + 1);
  sort(B + 1, B + n + 1);
  if (n & 1) {
    printf("%lld\\n", 1LL + B[(n + 1) / 2] - A[(n + 1) / 2]);
  } else {
    int p = n / 2;
    printf("%lld\\n", 1LL + B[p + 1] - A[p + 1] + B[p] - A[p]);
  }
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[200005], b[200005];
int main() {
  ll n;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    scanf("%lld%lld", &a[i], &b[i]);
  }
  sort(a, a + n);
  sort(b, b + n);
  ll low, hi;
  if (n & 1) {
    low = a[(n - 1) / 2];
    hi = b[(n - 1) / 2];
  } else {
    low = a[(n - 2) / 2] + a[(n - 2) / 2 + 1];
    hi = b[(n - 2) / 2] + b[(n - 2) / 2 + 1];
  }
  cout << hi - low + 1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[100005], b[100005];
int main() {
  ll n;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    scanf("%lld%lld", &a[i], &b[i]);
  }
  sort(a, a + n);
  sort(b, b + n);
  ll low, hi;
  if (n & 1) {
    low = a[(n - 1) / 2];
    hi = b[(n - 1) / 2];
  } else {
    low = a[(n - 2) / 2] + a[(n - 2) / 2 + 1];
    hi = b[(n - 2) / 2] + b[(n - 2) / 2 + 1];
  }
  cout << hi - low + 1 << endl;
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i) >> B.at(i);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (N % 2 == 1) {
    ll mid = N / 2;
    cout << B.at(mid) - A.at(mid) + 1 << "\\n";
  } else {
    ll mid = N / 2;
    ll m = A.at(mid) + A.at(mid - 1);
    ll M = B.at(mid) + B.at(mid - 1);
    cout << M - m + 1 << "\\n";
  }
}


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


Fixed submission:

#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  vector<ll> b(N);
  vector<pll> ab(N);
  for (ll i = 0; i < N; ++i) {
    cin >> a.at(i) >> b.at(i);
    ab.at(i) = {a.at(i), b.at(i)};
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(ab.begin(), ab.end());
  vector<pll> com_ab;
  ll l = ab.at(0).first, r = ab.at(0).second;
  for (ll i = 0; i < N; ++i) {
    if (ab.at(i).first >= l && ab.at(i).first <= r) {
      r = max(r, ab.at(i).second);
    } else {
      com_ab.push_back({l, r});
      l = ab.at(i).first;
      r = ab.at(i).second;
    }
  }
  com_ab.push_back({l, r});
  // for (ll i = 0; i < com_ab.size(); ++i) {
  //   cout << com_ab.at(i).first << ' ' << com_ab.at(i).second << "\\n";
  // }
  if (N % 2 == 1) {
    ll m = a.at(N / 2);
    ll M = b.at(N / 2);
    ll ans = 0;
    for (ll i = 0; i < com_ab.size(); ++i) {
      ans += max(0ll,
                 min(M, com_ab.at(i).second) - max(m, com_ab.at(i).first) + 1);
    }
    cout << ans << "\\n";
  } else {
    cout << com_ab.at(com_ab.size()).first << "\\n";
  }
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[200001], b[200001];
  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 << b[(n + 1) / 2] - a[(n + 1) / 2] + 1 << endl;
  } else
    cout << 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 <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100001], b[100001];
  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 << b[(n + 1) / 2] - a[(n + 1) / 2] + 1 << endl;
  } else
    cout << 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;
using ll = long long;
vector<ll> a, b;

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

Error: 1

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> a, b;

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

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

#define int long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

signed main() {
  int n;
  cin >> n;

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

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

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

  return 0;
}


Error: 0

Fixed submission:

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

#define int long long
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

signed main() {
  int n;
  cin >> n;

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

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

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

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define int long long
#define endl "\\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007;

struct fast_io {
  fast_io() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
  };
} fio;

signed main() {
  cout << fixed << setprecision(10);

  int N;
  vector<int> a, b;
  int x = 0, y = 0;

  cin >> N;

  if (N % 2 == 0) {
    x = N / 2 - 1;
    y = N / 2;
  } else {
    x = N / 2;
    y = N / 2;
  }

  for (int i = 0; i < N; i++) {
    int 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)
    cout << b[y] - a[x] + 1 << endl;
  else {
    cout << (b[x] + b[y]) - (a[x] + a[y]) + 1 << endl;
  }
  return 0;
}

Error: 2

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define int long long
#define endl "\\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007;

struct fast_io {
  fast_io() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
  };
} fio;

#define A first
#define B second

signed main() {
  cout << fixed << setprecision(10);

  int N;
  vector<pair<int, int>> in;
  vector<int> a, b;
  int x = 0, y;

  cin >> N;

  in.resize(N);

  if (N % 2 == 0) {
    x = N / 2 - 1;
    y = N / 2;
  } else {
    x = N / 2;
    y = N / 2;
  }

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

    a.push_back(in[i].A);
    b.push_back(in[i].B);
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  if (N % 2)
    cout << b[y] - a[x] + 1 << endl;
  else {
    exit(2);
    cout << (b[y] + a[y]) - (b[x] + a[x]) + 1 << endl;
  }
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n;
  int a[200009], b[200009];
  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 << b[(n + 1) / 2] - a[(n + 1) / 2] + 1;
  else
    cout << b[n / 2] + b[n / 2 + 1] - a[n / 2] - a[n / 2 + 1] + 1;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n;
  int a[100009], b[100009];
  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 << b[(n + 1) / 2] - a[(n + 1) / 2] + 1;
  else
    cout << b[n / 2] + b[n / 2 + 1] - a[n / 2] + a[n / 2 + 1] + 1;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

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

long long a[200000];
long long b[200000];

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

Error: WA

Fixed submission:

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

long long a[100000];
long long b[100000];

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

#include <bits/stdc++.h>
using namespace std;
using f32 = float;
using f64 = double;
using LL = long long;
using ULL = unsigned long long;
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()

signed main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  vector<long long> b(N);
  REP(i, N) { cin >> a[i] >> b[i]; }
  SORT(a);
  SORT(b);
  if (N % 2 == 0) {
    long long mi = a[N / 2 - 1] + a[N / 2];
    long long ma = b[N / 2 - 1] + b[N / 2];
    cout << ma - mi + 1 << endl;
  } else {
    long long mi = a[N / 2], ma = b[N / 2];
    cout << ma - mi + 1 << endl;
  }
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using f32 = float;
using f64 = double;
using LL = long long;
using ULL = unsigned long long;
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()

int main() {
  long long N;
  vector<long long> a;
  vector<long long> b;
  cin >> N;
  REP(i, N) { cin >> a[i] >> b[i]; }
  SORT(a);
  SORT(b);
  if (N % 2 == 0) {
    long long mi = a[N / 2 - 1] + a[N / 2];
    long long ma = b[N / 2 - 1] + b[N / 2];
    cout << ma - mi + 1 << endl;
  } else {
    long long mi = a[N / 2], ma = b[N / 2];
    cout << ma - mi + 1 << endl;
  }
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

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

const int N = 2e5 + 5;

int n;
int A[N], B[N];

vector<int> a[2];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
    a[0].push_back(A[i]);
    a[1].push_back(B[i]);
  }

  sort(a[0].begin(), a[0].end());
  sort(a[1].begin(), a[1].end());

  if (n % 2) {
    int mn = a[0][(n - 1) / 2];
    int mx = a[1][(n - 1) / 2];
    cout << mx - mn + 1 << endl;
  } else {
    int mn = (a[0][n / 2] + a[0][(n / 2) - 1]);
    int mx = (a[1][n / 2] + a[1][(n / 2) - 1]);
    cout << (mx - mn) + 1 << endl;
  }
}

Error: 0

Fixed submission:

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

const int N = 1e5 + 5;

int n;
int A[N], B[N];

vector<int> a[2];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
    a[0].push_back(A[i]);
    a[1].push_back(B[i]);
  }

  sort(a[0].begin(), a[0].end());
  sort(a[1].begin(), a[1].end());

  if (n % 2) {
    int mn = a[0][(n - 1) / 2];
    int mx = a[1][(n - 1) / 2];
    cout << mx - mn + 1 << endl;
  } else {
    long double mn = (a[0][n / 2] + a[0][(n / 2) - 1]) / 2;
    long double mx = (a[1][n / 2] + a[1][(n / 2) - 1]) / 2;
    cout << round(2 * (mx - mn) + 1) << endl;
  }
}