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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define ll long long
#define pll pair<ll, ll>

#define reps(i, f, n) for (int i = (f); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

const int INF = 1111111111;

using namespace std;

const int N = 1111111;
int a[N];
int b[N];
int n;

void init() {
  cin >> n;
  rep(i, n) { cin >> a[i] >> b[i]; }
}

void solve() {
  sort(a, a + n);
  sort(b, b + n);

  if (n % 2 == 0) {
    int p1 = n / 2 - 1;
    int p2 = n / 2;
    int val = (b[p1] + b[p2] - a[p1] - a[p2] + 1);
    cout << val << endl;
  } else {
    int p = n / 2;
    cout << b[p] - a[p] + 1 << endl;
  }
}

int main() {
  init();
  solve();
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define ll long long
#define pll pair<ll, ll>

#define reps(i, f, n) for (int i = (f); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

const int INF = 1111111111;

using namespace std;

const int N = 111111;
int a[N];
int b[N];
int n;

void init() {
  cin >> n;
  rep(i, n) { cin >> a[i] >> b[i]; }
}

void solve() {
  sort(a, a + n);
  sort(b, b + n);

  if (n % 2 == 0) {
    int p1 = n / 2 - 1;
    int p2 = n / 2;
    int val = (b[p1] + b[p2] - a[p1] - a[p2] + 1);
    cout << val << endl;
  } else {
    int p = n / 2;
    cout << b[p] - a[p] + 1 << endl;
  }
}

int main() {
  init();
  solve();
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i, l, h) for (ll i = l; i < h; i++)
#define fr(i, h, l) for (ll i = h; i >= l; i--)

using namespace std;

typedef pair<ll, ll> pll;
const ll INF = (ll)(1e9 + 7);
typedef vector<ll> vll;

int main() {
  // cout << "Hello world!" << endl;

  ll n;
  cin >> n;
  ll a[n];
  ll b[n];

  f(i, 0, n) { cin >> a[i] >> b[i]; }

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

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

  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i, l, h) for (ll i = l; i < h; i++)
#define fr(i, h, l) for (ll i = h; i >= l; i--)

using namespace std;

typedef pair<ll, ll> pll;
const ll INF = (ll)(1e9 + 7);
typedef vector<ll> vll;

bool compare(pll a, pll b) { return a.second <= b.second; }

int main() {
  // cout << "Hello world!" << endl;

  ll n;
  scanf("%lld", &n);
  vector<pll> a(n);

  f(i, 0, n) { scanf("%lld %lld", a[i].first, a[i].second); }

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

  if (n & 1) {
    ll mn = a[n / 2].first;
    sort(a.begin(), a.end(), compare);
    ll mx = a[n / 2].second;
    printf("%lld\\n", mx - mn + 1);
  } else {
    ll mn = a[n / 2 - 1].first + a[n / 2].first;
    sort(a.begin(), a.end(), compare);
    ll mx = a[n / 2 - 1].second + a[n / 2].second;
    printf("%lld\\n", mx - mn + 1);
  }

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

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int a[200000], b[200000], cnt;
int n, left[2], right[2], mid;
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 % 2) {
    cout << b[n / 2] - a[n / 2] + 1 << endl;
  } else {
    cout << b[(n - 1) / 2] + b[(n - 1) / 2 + 1] -
                (a[(n - 1) / 2] + a[(n - 1) / 2 + 1]) + 1
         << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int a[100000], b[100000], cnt;
int main() {
  int n, left[2], right[2], mid;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  left[0] = left[1] = 0;
  right[0] = right[1] = 1000000000;
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2) {
    cout << b[n / 2] - a[n / 2] + 1 << endl;
  } else {
    cout << b[(n - 1) / 2] + b[(n - 1) / 2 + 1] -
                (a[(n - 1) / 2] + a[(n - 1) / 2 + 1]) + 1
         << endl;
  }
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>

using namespace std;

#define MAX_N 200005

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

void solve() {
  sort(A, A + N);
  sort(B, B + N);
  printf("%d\\n", (N % 2 == 1 ? B[N / 2] - A[N / 2]
                             : (B[N / 2] + B[(N - 1) / 2] - A[N / 2] -
                                A[(N - 1) / 2])) +
                     1);
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", A + i, B + i);
  }
  solve();
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;

#define MAX_N 100005

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

void solve() {
  sort(A, A + N);
  sort(B, B + N);
  printf("%d\\n", (N % 2 == 1 ? B[N / 2] - A[N / 2]
                             : (B[N / 2] + B[(N - 1) / 2] - A[N / 2] -
                                A[(N - 1) / 2])) +
                     1);
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", A + i, B + i);
  }
  solve();
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
double mn, mx;
struct num {
  int A, B;
} a[1000009];
bool cmp1(const num &a, const num &b) { return a.A < b.A; }
bool cmp2(const num &a, const num &b) { return a.B < b.B; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i].A, &a[i].B);
  sort(a + 1, a + n + 1, cmp1);
  mn = (a[(n + 1) / 2].A + a[(n + 2) / 2].A) / 2.;
  sort(a + 1, a + n + 1, cmp2);
  mx = (a[(n + 1) / 2].B + a[(n + 2) / 2].B) / 2.;
  if (n & 1)
    printf("%d", (int)(mx - mn + 1));
  else
    printf("%d", (int)(2 * (mx - mn + 0.5)));
  return 0;
}

Error: WA

Fixed submission:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
const ll mod = 998244353;
inline ll read() {
  ll x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}
const int N = 3e3 + 10;
ll dp[N][N];
int a[N], n, s;
void add(ll &x, ll y) { x = (x + y) % mod; }
int main() {
  n = read(), s = read();
  rep(i, 1, n) a[i] = read();
  dp[0][0] = 1;
  rep(i, 1, n) {
    for (int j = 0; j <= s; ++j)
      dp[i][j] = dp[i - 1][j] * 2 % mod;

    for (int j = s; j >= a[i]; --j) {
      add(dp[i][j], dp[i - 1][j - a[i]]);
    }
  }
  printf("%lld\\n", dp[n][s]);
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PL;

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

  } else {
    LL m = n / 2 - 1;
    cout << b[m] + b[m + 1] - a[m] - a[m + 1] + 1 << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PL;

const int MOD = 1000000007;
int INF = 100100100;
int main() {
  LL n;
  cin >> n;
  LL a[100010], b[100010];
  for (LL i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2 != 0) {
    LL m = n / 2;
    cout << b[m] - a[m] + 1 << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt, e) for (ll cnt = 0; cnt < e; cnt++)
#define allsort(X) sort(X.begin(), X.end())

typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll INF = INT64_MAX;

ll i, j, k;

int main() {
  ll N;
  cin >> N;
  V A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];
  allsort(A);
  allsort(B);
  if (N % 2 == 1)
    cout << B[(N - 1) / 2] - A[(N - 1) / 2] + 1 << endl;
  else {
    cout << (B[N / 2 - 1] + B[N / 2] - A[N / 2] - A[N / 2 - 1]) + 1 << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt, e) for (ll cnt = 0; cnt < e; cnt++)
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll INF = INT64_MAX;
typedef tuple<ll, ll, ll> T;

ll i, j, k;

int main() {
  ll N;
  cin >> N;
  V A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];

  vector<P> kukana(N), kukanb(N);
  rep(i, N) kukana.at(i) = P(A.at(i), B.at(i));
  rep(i, N) kukanb.at(i) = P(-B.at(i), -A.at(i));
  sort(kukana.begin(), kukanb.end());
  sort(kukanb.begin(), kukanb.end());
  if (N % 2 == 1) {
    ll shita = kukana.at((N - 1) / 2).first;
    ll ue = kukanb.at((N - 1) / 2).first;
    ll ans = kukana.at((N - 1) / 2).second + kukanb.at((N - 1) / 2).second + 1;
    cout << ans << endl;

  } else {
    ll shita = kukana.at(N / 2 - 1).first;
    ll ue = kukanb.at(N / 2 - 1).first;
    if (1) {
      cout << kukana.at(N / 2 - 1).second - kukanb.at(N / 2 - 1).first -
                  kukana.at(N / 2 - 1).first + kukanb.at(N / 2 - 1).second + 1
           << endl;
    } else {
    }
  }
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll gcd(ll n, ll m) {
  ll tmp;
  while (m != 0) {
    tmp = n % m;
    n = m;
    m = tmp;
  }
  return n;
}

ll lcm(ll n, ll m) {
  return abs(n) / gcd(n, m) * abs(m); // gl=xy
}

using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(all(a));
  sort(all(b));
  int x = n / 2;
  if (n % 2 == 1)
    cout << b[x] - a[x] + 1;
  else {
    cout << (b[x] + b[x - 1] - (a[x] + a[x - 1])) + 1;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}


Error: -6
fe8df200-c447-4b17-9dd9-504763cc9ab5.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02661/C++/s309189499.cpp:51: void solve(): Assertion `n%2==1' failed.


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll gcd(ll n, ll m) {
  ll tmp;
  while (m != 0) {
    tmp = n % m;
    n = m;
    m = tmp;
  }
  return n;
}

ll lcm(ll n, ll m) {
  return abs(n) / gcd(n, m) * abs(m); // gl=xy
}

using namespace std;

void solve() {
  int n;
  cin >> n;
  if (n % 2 == 0) {
    assert(n % 2 == 1);
    return;
  }
  vector<pair<ll, ll>> p(n), sum(n);
  rep(i, n) cin >> p[i].first >> p[i].second;
  rep(i, n) {
    sum[i].first = p[i].first + p[i].second;
    sum[i].second = i;
  }
  sort(all(sum));
  int x = n / 2;
  if (n % 2 == 1)
    cout << p[sum[x].second].second - p[sum[x].second].first + 1;
  else {
    cout << (p[sum[x].second].second + p[sum[x - 1].second].second -
             (p[sum[x].second].first + p[sum[x - 1].second].first)) +
                1;
  }
}

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod = 1000 * 1000 * 1000 + 7;
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  map<ll, ll> m;
  vector<ll> v, v1;
  ll s1 = 0, s2 = 0;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    v.push_back(x);
    v1.push_back(y);
  }
  sort(v.begin(), v.end());
  sort(v1.begin(), v1.end());
  reverse(v.begin(), v.end());
  if (n % 2) {
    ll x = v[n / 2];
    ll y = v1[n / 2];
    x = y - x + 1;
    cout << x;
  } else {
    ll x = v[n / 2] + v[(n / 2) - 1];
    ll y = v1[n / 2] + v1[(n / 2) - 1];
    x = y - x + 1;
    cout << x;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod = 1000 * 1000 * 1000 + 7;
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  map<ll, ll> m;
  vector<ll> v, v1;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    v.push_back(x);
    v1.push_back(y + 1);
    m[x]++;
    m[y + 1]--;
  }
  sort(v.begin(), v.end());
  vector<ll> a;
  for (auto it = m.begin(); it != m.end(); it++) {
    // cout<<s<<" "<<it->first<<"\\n";
    auto itt = upper_bound(v.begin(), v.end(), (it->first));
    ll j = itt - v.begin();
    auto ittt = lower_bound(v1.begin(), v1.end(), (it->first));
    ll j1 = ittt - v1.begin();
    j1 = v1.size() - j1;
    if (j >= (n + 1) / 2 && j1 >= (n + 1) / 2) {
      a.push_back((it->first));
    }
  }
  ll out = 0;
  sort(a.begin(), a.end());
  out = a[a.size() - 1] - a[0];

  cout << out;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

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

int a[200001], b[200001];

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);

  long long ans;
  if (n % 2 == 0)
    ans = b[n / 2] + b[(n / 2) + 1] - a[n / 2] - a[(n / 2) + 1] + 1;
  else
    ans = b[(n + 1) / 2] - a[(n + 1) / 2] + 1;

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int a[100001], b[100001];

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);

  long long ans;
  if (n % 2 == 0)
    ans = b[n / 2] + b[(n / 2) + 1] - a[n / 2] - a[(n / 2) + 1] + 1;
  else
    ans = b[(n + 1) / 2] - a[(n + 1) / 2] + 1;

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

#include <bits/stdc++.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}

/*-------------------------------------------*/

int n;
ll a[200009], b[200009];

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

  cin >> n;
  rep(i, n) cin >> a[i] >> b[i];

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

  if (n & 1) {
    cout << b[n >> 1] - a[n >> 1] + 1 << endl;
    return 0;
  }

  cout << ((b[n / 2 - 1] + b[n / 2]) - (a[n / 2 - 1] + a[n / 2])) + 1 << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}

/*-------------------------------------------*/

int n;
ll a[100009], b[100009];

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

  cin >> n;
  rep(i, n) cin >> a[i] >> b[i];

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

  if (n & 1) {
    cout << b[n >> 1] - a[n >> 1] + 1 << endl;
    return 0;
  }

  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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define f first
#define s second
#define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i)
#define DEC(i, s, e) for (ll i = s; i >= ll(e); --i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i, x) for (auto i : x)
#define mem(x, i) memset(x, i, sizeof x)
#define fast ios_base::sync_with_stdio(false), cin.tie(0)
#define maxn 200001
typedef pair<pi, int> pii;
int N;
int A[maxn], B[maxn];

int main() {
  fast;

  cin >> N;
  vi vect;
  FOR(i, 0, N - 1) { cin >> A[i] >> B[i]; }

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

  if (N % 2 == 0)
    cout << 1 - A[N / 2 - 1] - A[N / 2] + B[N / 2 - 1] + B[N / 2];
  else
    cout << B[N / 2] - A[N / 2] + 1;
}


Error: WA

Fixed submission:

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

typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define f first
#define s second
#define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i)
#define DEC(i, s, e) for (ll i = s; i >= ll(e); --i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i, x) for (auto i : x)
#define mem(x, i) memset(x, i, sizeof x)
#define fast ios_base::sync_with_stdio(false), cin.tie(0)
#define maxn 100001
typedef pair<pi, int> pii;
int N;
int A[maxn], B[maxn];

int main() {
  fast;

  cin >> N;
  vi vect;
  FOR(i, 0, N - 1) { cin >> A[i] >> B[i]; }

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

  if (N % 2 == 0)
    cout << 1 - A[N / 2 - 1] - A[N / 2] + B[N / 2 - 1] + B[N / 2];
  else
    cout << B[N / 2] - A[N / 2] + 1;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int)2e5 + 7;
int n;
int a[N];
int b[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  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) {
    int f = a[n / 2 + 1], s = b[n / 2 + 1];
    cout << s - f + 1 << "\\n";
  } else {
    int f = a[n / 2] + a[n / 2 + 1], s = b[n / 2] + b[n / 2 + 1];
    cout << s - f + 1 << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int)1e5 + 7;
int n;
int a[N];
int b[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  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) {
    int f = a[n / 2 + 1], s = b[n / 2 + 1];
    cout << s - f + 1 << "\\n";
  } else {
    int f = a[n / 2] + a[n / 2 + 1], s = b[n / 2] + b[n / 2 + 1];
    cout << s - f + 1 << "\\n";
  }
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 7;

long long n;
long long a[N], b[N];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in.in" , "r" , stdin) ;
  cin >> n;
  for (int 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;
  } else {
    long long d1 = b[n / 2] + b[n / 2 - 1];
    long long d2 = a[n / 2] + a[n / 2 - 1];
    cout << (d1 - d2 + 1);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 7;

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in.in" , "r" , stdin) ;
  cin >> n;
  for (int 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;
  } else {
    double d1 = b[n / 2] + b[n / 2 - 1];
    double d2 = a[n / 2] + a[n / 2 - 1];
    cout << (d1 - d2 + 1);
  }
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int n;
  long long int a[1000010], b[1000010];
  cin >> n;

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

  if (n % 2 == 1) {
    sort(a, a + n);
    sort(b, b + n);

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

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

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  int a[10010], b[100010];
  cin >> n;

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

  if (n % 2 == 1) {
    sort(a, a + n);
    sort(b, b + n);

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

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

    cout << (b[(n / 2)] - a[(n / 2) - 1]) * 2 - 1 << endl;
  }
}