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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
struct edge {
  ll to, cost;
};
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define INF 1000000000000
#define ALL(a) (a).begin(), (a).end()
#define large 1000000000000000000

vector<pair<long long, long long>> prime_factorize(long long N) {
  vector<pair<long long, long long>> res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0)
      continue;
    long long ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

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

  ll ref[41];
  ll piyo = 0;
  for (int i = 1; i < 40; i++) {
    ll hoge = 0;
    ll temp = 0;
    for (ll j = 1; j <= i; j++) {
      hoge++;
      temp += j;
      if (i - temp <= j) {
        break;
      }
    }
    ref[i] = hoge;
  }
  const auto &pf = prime_factorize(n);
  long long res = 0;
  for (auto p : pf)
    res += ref[p.second];
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
struct edge {
  ll to, cost;
};
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define INF 1000000000000
#define ALL(a) (a).begin(), (a).end()
#define large 1000000000000000000

int main() {
  ll n;
  cin >> n;
  vector<int> x(n + 1);
  ll num = n;
  for (int i = 2; i <= n; i++) {
    while (num % i == 0) {
      x.at(i)++;
      num /= i;
    }
  }
  ll ans = 0;

  for (int i = 2; i <= n; i++) {
    ll temp = 0;
    ll hoge = 0;
    ll piyo = x.at(i);
    for (ll j = 1; j <= piyo; j++) {
      hoge++;
      temp += j;
      if (piyo - temp <= j) {
        break;
      }
    }
    ans += hoge;
  }
  cout << ans << endl;
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pii pair<int, int>
#define fr(i, a, b) for (int i = a; i < b; i++)
#define frb(i, a, b) for (int i = a; i > b; i--)
#define sz(s) (int)s.size()
#define all(v) (v).begin(), (v).end()
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
#define iset                                                                   \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define oset                                                                   \\
  tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,           \\
       tree_order_statistics_node_update>
#define ll long long
using namespace std;
using namespace __gnu_pbds;

int prg() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  fr(i, 0, n) cin >> a[i] >> b[i];
  srt(a);
  srt(b);
  if (n % 2 == 1)
    cout << b[n / 2] - a[n / 2] + 1;
  else {
    cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1;
  }
  return 0;
}
void multi() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    prg();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  prg();
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pii pair<int, int>
#define fr(i, a, b) for (int i = a; i < b; i++)
#define frb(i, a, b) for (int i = a; i > b; i--)
#define sz(s) (int)s.size()
#define all(v) (v).begin(), (v).end()
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
#define iset                                                                   \\
  tree<int, null_type, less<int>, rb_tree_tag,                                 \\
       tree_order_statistics_node_update>
#define oset                                                                   \\
  tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,           \\
       tree_order_statistics_node_update>
#define ll long long
using namespace std;
using namespace __gnu_pbds;

int prg() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  fr(i, 0, n) cin >> a[i] >> b[i];
  srt(a);
  srt(b);
  if (n % 2 == 1)
    cout << b[n / 2] - a[n / 2] + 1;
  else {
    cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1;
  }
}
void multi() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    prg();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  prg();
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<long> A(N), B(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i) >> B.at(i);
  long long ans;
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (N % 2 == 1) {
    long middle = (N + 1) / 2 - 1;
    ans = B.at(middle) - A.at(middle) + 1;
  } else {
    long low = N / 2 - 1;
    long high = low + 1;
    ans = (B.at(high) + B.at(low)) - (A.at(high) + A.at(low)) + 1;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<long> A(N), B(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i) >> B.at(i);
  long ans;
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (N % 2 == 1) {
    long middle = (N + 1) / 2 - 1;
    ans = B.at(middle) - A.at(middle) + 1;
  } else {
    long low = 2 / N - 1;
    long high = low + 1;
    ans = (B.at(high) + B.at(low)) - (A.at(high) + A.at(low)) + 1;
  }
  cout << ans << endl;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <stdlib.h>

#define LL long long int

int cmpLL(const void *n1, const void *n2) {

  if (*(LL *)n1 > *(LL *)n2) {
    return 1;
  } else if (*(LL *)n1 < *(LL *)n2) {
    return -1;
  }

  return 0;
}

int main(void) {

  int n;
  scanf("%d", &n);
  LL *a = (LL *)malloc(n * sizeof(LL));
  LL *b = (LL *)malloc(n * sizeof(LL));
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &a[i], &b[i]);
  }

  qsort(a, n, sizeof(LL), cmpLL);
  qsort(b, n, sizeof(LL), cmpLL);

  int ret;
  if (n % 2 == 1) {
    ret = b[(n - 1) / 2] - a[(n - 1) / 2] + 1;
  } else {
    ret = (b[n / 2 - 1] + b[n / 2]) - (a[n / 2 - 1] + a[n / 2]) + 1;
  }

  printf("%d", ret);

  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#define LL long long int

/* 値を入れ替える関数 */
void swapLL(LL *x, LL *y) {
  LL temp; // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
 * pivotを決め、
 * 全データをpivotを境目に振り分け、
 * pivotの添え字を返す
 ***/
int partition(LL *array, int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left; // 先頭要素をpivotとする

  do {
    do {
      i++;
    } while (array[i] < array[pivot]);
    do {
      j--;
    } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) {
      swapLL(&array[i], &array[j]);
    }
  } while (i < j);

  swapLL(&array[pivot], &array[j]); // pivotを更新

  return j;
}

/* クイックソート */
void quick_sort(LL *array, int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot - 1); // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot + 1, right);
  }
}

int main(void) {

  int n;
  scanf("%d", &n);
  LL *a = (LL *)malloc(n * sizeof(LL));
  LL *b = (LL *)malloc(n * sizeof(LL));
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &a[i], &b[i]);
  }

  quick_sort(a, 0, n - 1);
  quick_sort(b, 0, n - 1);

  int ret;
  if (n % 2 == 1) {
    ret = b[(n - 1) / 2] - a[(n - 1) / 2] + 1;
  } else {
    ret = (b[n / 2 - 1] + b[n / 2]) - (a[n / 2 - 1] + a[n / 2]) + 1;
  }

  printf("%d", ret);

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

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for (ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for (ll i = (ll)(n - 1); i >= 0; i--)
#define repM1(i, n) for (ll i = (ll)(n - 1); i > 0; i--)
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;
}

int main() {
  cout << fixed << setprecision(18);

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

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

  ll ans;
  if (n % 2 == 1) {
    ans = b[(n + 1) / 2 - 1] - a[(n + 1) / 2 - 1] + 1;
  } else {
    double tmp_a = (a[n / 2 - 1] + a[(n / 2 + 1) - 1]) * 0.5;
    double tmp_b = (b[n / 2 - 1] + b[(n / 2 + 1) - 1]) * 0.5;

    ll aa = tmp_a * 10 + 0.5;
    ll bb = tmp_b * 10 + 0.5;

    ans = (bb - aa) / 5 + 1;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for (ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for (ll i = (ll)(n - 1); i >= 0; i--)
#define repM1(i, n) for (ll i = (ll)(n - 1); i > 0; i--)
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;
}

int main() {
  cout << fixed << setprecision(18);

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

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

  ll ans;
  if (n % 2 == 1) {
    ans = b[(n + 1) / 2 - 1] - a[(n + 1) / 2 - 1] + 1;
  } else {
    double tmp_a = (a[n / 2 - 1] + a[(n / 2 + 1) - 1]) * 0.5;
    double tmp_b = (b[n / 2 - 1] + b[(n / 2 + 1) - 1]) * 0.5;

    ans = 0;
    for (; tmp_a <= tmp_b; tmp_a += 0.5)
      ans++;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 200005
#define inf 1000000009
#define ll long long
#define pii pair<int, int>
#define sz(a) int(a.size())
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

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 % 2 == 1)
    printf("%d", b[(n + 1) / 2] - a[(n + 1) / 2] + 1);
  else {
    int ma = a[n / 2 + 1] + a[n / 2];
    int mb = b[n / 2 + 1] + b[n / 2];
    printf("%d", mb - ma + 1);
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define pii pair<int, int>
#define sz(a) int(a.size())
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

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 % 2 == 1)
    printf("%d", b[(n + 1) / 2] - a[(n + 1) / 2] + 1);
  else {
    int ma = a[n / 2 + 1] + a[n / 2];
    int mb = b[n / 2 + 1] + b[n / 2];
    printf("%d", mb - ma + 1);
  }
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
  int N, A[200000], B[200000];
  cin >> N;
  REP(i, N) cin >> A[i] >> B[i];
  sort(A, A + N);
  sort(B, B + N);
  if (N % 2 == 0)
    cout << B[N / 2] + B[N / 2 - 1] - A[N / 2] - A[N / 2 - 1] + 1 << endl;
  else
    cout << B[N / 2] - A[N / 2] + 1 << endl;
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int N, A[100000], B[100000];
pii AB[100000], BA[100000];

pii get_range(int target, int start, int count) {
  int S[100000], l, r;
  FOR(i, start, N) {
    if (target == 1)
      S[i - start] = AB[i].second;
    else
      S[i - start] = BA[i].second;
  }
  if (target == 1)
    sort(S, S + count);
  else
    sort(S, S + count, [](int const &a, int const &b) { return a > b; });
  if (target == 1) {
    l = AB[start].first;
    r = S[0];
  } else {
    l = S[0];
    r = BA[start].first;
  }

  return {l, r};
}

int main() {
  cin >> N;
  REP(i, N) {
    cin >> A[i] >> B[i];
    AB[i] = {A[i], B[i]};
    BA[i] = {B[i], A[i]};
  }
  sort(AB, AB + N, [](pii const &a, pii const &b) {
    if (a.first == b.first)
      return a.second < b.second;
    else
      return a.first < b.first;
  });
  sort(BA, BA + N, [](pii const &a, pii const &b) {
    if (a.first == b.first)
      return a.second > b.second;
    else
      return a.first > b.first;
  });

  if (N % 2 == 0) {
    int l1, l2, r1, r2;
    pii range11 = get_range(1, (N - 1) / 2, N / 2 + 1);
    pii range12 = get_range(1, N / 2, N / 2);
    l1 = range11.first + range12.first;
    r1 = range11.second + range12.second;

    pii range21 = get_range(2, (N - 1) / 2, N / 2 + 1);
    pii range22 = get_range(2, N / 2, N / 2);
    l2 = range21.first + range22.first;
    r2 = range21.second + range22.second;

    if (l2 <= r1)
      cout << r2 - l1 + 1 << endl;
    else
      cout << r1 - l1 + 1 + r2 - l2 + 1 << endl;
  } else {
    pii range1 = get_range(1, N / 2, (N + 1) / 2);
    pii range2 = get_range(2, N / 2, (N + 1) / 2);
    int l1, l2, r1, r2;
    l1 = range1.first;
    r1 = range1.second;
    l2 = range2.first;
    r2 = range2.second;

    if (l2 <= r1)
      cout << r2 - l1 + 1 << endl;
    else
      cout << r1 - l1 + 1 + r2 - l2 + 1 << endl;
  }
  return 0;
}
Problem p02661 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll, ll>> vp;
typedef pair<ll, ll> Pair;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define inputv(v, n)                                                           \\
  rep(i, n) {                                                                  \\
    ll x;                                                                      \\
    cin >> x;                                                                  \\
    v.push_back(x);                                                            \\
  }

const ll INF = 99999999999999;
const ll MOD = 1000000007;

int main() {
  ll n;
  vl a;
  vl b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x;
    cin >> y;
    a.push_back(x);
    b.push_back(y);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  ll range = b[n - 1] - a[0];
  if (n % 2 == 1) {
    ll middle = (n - 1) / 2;
    printf("%lld", b[middle] - a[middle] + 1);
  }
  if (n % 2 == 0) {
    ll middle_h = n / 2;
    ll middle_l = n / 2 - 1;
    printf("%lld",
           ((b[middle_h] + b[middle_l]) - (a[middle_h] + a[middle_l]) + 1));
  }

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll, ll>> vp;
typedef pair<ll, ll> Pair;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define inputv(v, n)                                                           \\
  rep(i, n) {                                                                  \\
    ll x;                                                                      \\
    cin >> x;                                                                  \\
    v.push_back(x);                                                            \\
  }

const ll INF = 99999999999999;
const ll MOD = 1000000007;

int main() {
  int n;
  int a[n];
  int b[n];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    a[i] = x;
    b[i] = y;
  }
  sort(a, a + n);
  sort(b, b + n);

  int range = b[n - 1] - a[0];
  if (n % 2 == 1) {
    int middle = (n - 1) / 2;
    printf("%d ", b[middle] - a[middle] + 1);
  }
  if (n % 2 == 0) {
    int middle_h = n / 2;
    int middle_l = n / 2 - 1;
    printf("%d",
           ((b[middle_h] + b[middle_l]) - (a[middle_h] + a[middle_l]) + 1));
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll a[200010], b[200010];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i] >> b[i];
    a[i] *= 2;
    b[i] *= 2;
  }

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

  ll medl, medr, ans;

  if (n % 2 == 0) {
    medl = (a[n / 2 - 1] + a[n / 2]) / 2;
    medr = (b[n / 2 - 1] + b[n / 2]) / 2;
    ans = medr - medl + 1;
  } else {
    medl = a[(n - 1) / 2];
    medr = b[(n - 1) / 2];
    ans = (medr - medl) / 2 + 1;
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll a[100010], b[100010];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i] >> b[i];
    a[i] *= 2;
    b[i] *= 2;
  }

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

  ll medl, medr, ans;

  if (n % 2 == 0) {
    medl = (a[n / 2 - 1] + a[n / 2]) / 2;
    medr = (b[n / 2 - 1] + b[n / 2]) / 2;
    ans = medr - medl + 1;
  } else {
    medl = a[(n - 1) / 2];
    medr = b[(n - 1) / 2];
    ans = (medr - medl) / 2 + 1;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template <class T> void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

int a[200000], b[200000];

int main() {
  int n, c, d;
  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) {
    c = a[n / 2];
    d = b[n / 2];
  } else {
    c = a[n / 2 - 1] + a[n / 2];
    d = b[n / 2 - 1] + b[n / 2];
  }
  cout << d - c + 1 << endl;

  return 0;
}

Error: -6
a24cb10a-f155-4c97-b6f9-c44f1b34bbff.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02661/C++/s941133608.cpp:32: int main(): Assertion `false' failed.


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template <class T> void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

pair<int, int> a[200000];
vector<pair<int, int>> b;

int main() {
  int n, ans;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a, a + n);
  if (n % 2) {
    b.push_back(
        make_pair(a[n / 2].first, min(a[n / 2].second, a[n / 2 + 1].second)));
  } else {
    assert(false);
  }

  for (int i = 0; i < n; ++i) {
    swap(a[i].first, a[i].second);
  }
  sort(a, a + n);
  if (n % 2) {
    b.push_back(
        make_pair(max(a[n / 2].second, a[n / 2 - 1].second), a[n / 2].first));
  } else {
  }
  sort(all(b));

  if (b[0].second >= b[1].first) {
    ans = max(b[0].second, b[1].second) - b[0].first + 1;
  } else {
    ans = b[0].second - b[0].first + 1;
    ans += b[1].second - b[1].first + 1;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
const long long inf = 0x3f3f3f3f;
long long a[maxn], b[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  long long n;
  cin >> n;
  for (long long 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) {
    long long x = a[n / 2 + 1];
    long long y = b[n / 2 + 1];
    cout << y - x + 1 << endl;
  } else {
    long long x = a[n / 2] + a[n / 2 + 1];
    long long y = b[n / 2] + b[n / 2 + 1];
    cout << y - x + 1 << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int a[maxn], b[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  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) {
    int x = a[n / 2 + 1];
    int y = b[n / 2 + 1];
    cout << y - x + 1 << endl;
  } else {
    int x = a[n / 2] + a[n / 2 + 1];
    int y = b[n / 2] + b[n / 2 + 1];
    cout << y - x + 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<int, int> pii;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);

  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  ll high, low;
  if (N % 2 == 0) {

    high = B[N / 2] + B[-1 + N / 2];
    low = A[N / 2] + A[-1 + N / 2];
  } else {
    high = B[N / 2];
    low = A[N / 2];
  }
  cout << high - low + 1 << endl;
}


Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  ll N;
  vector<ll> A(N);
  vector<ll> B(N);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  ll high, low;
  if (N % 2 == 0) {

    high = B[N / 2] + B[-1 + N / 2];
    low = A[N / 2] + A[-1 + N / 2];
  } else {
    high = B[N / 2];
    low = A[N / 2];
  }
  cout << high - low + 1 << endl;
}