prithivMLmods/Coder-Stat huggingface dataset:
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n;
  cin >> n;
  int k = 2;
  int s = 0;
  while (k * k <= n) {
    if (n % k == 0) {
      int x = 0;
      while (n % k == 0) {
        x += 1;
        n = n / k;
      }
      int i = 1;
      while (x >= (i + 2) * (i + 1) / 2)
        i += 1;
      // cout << k << " " << i << endl;
      s += i;
    }
    k += 1;
  }
  if (n > 1)
    s += 1;
  cout << s;
}


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

int main() {
  long long n;
  cin >> n;
  long long k = 2;
  int s = 0;
  while (k * k <= n) {
    if (n % k == 0) {
      int x = 0;
      while (n % k == 0) {
        x += 1;
        n = n / k;
      }
      int i = 1;
      while (x >= (i + 2) * (i + 1) / 2)
        i += 1;
      // cout << k << " " << i << endl;
      s += i;
    }
    k += 1;
  }
  if (n > 1)
    s += 1;
  cout << s;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long A;
int res = 0, ans[1000004];
int main() {
  cin >> A;
  ans[1] = 1;
  for (int i = 1; i <= 1e6; i++) {
    ans[i] = max(ans[i], ans[i - 1]);
    if (i + ans[i] + 1 <= 1e6)
      ans[i + ans[i] + 1] = ans[i] + 1;
  }
  for (int i = 2; i * i <= A; i++) {
    int cnt = 0;
    while (A % i == 0)
      cnt++, A /= i;
    res += ans[cnt];
  }
  if (A > 1) {
    res++;
  }
  cout << res;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long A;
int res = 0, ans[1000004];
int main() {
  cin >> A;
  ans[1] = 1;
  for (int i = 1; i <= 1e6; i++) {
    ans[i] = max(ans[i], ans[i - 1]);
    if (i + ans[i] + 1 <= 1e6)
      ans[i + ans[i] + 1] = ans[i] + 1;
  }
  for (int i = 2; 1ll * i * i <= A; i++) {
    int cnt = 0;
    while (A % i == 0)
      cnt++, A /= i;
    res += ans[cnt];
  }
  if (A > 1) {
    res++;
  }
  cout << res;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, int>> fs;
  for (int i = 2; i * i <= n; i++) {
    int x = 0;
    while (n % i == 0) {
      n /= i;
      x++;
    }
    if (x != 0)
      fs.emplace_back(i, x);
  }
  if (n != 1)
    fs.emplace_back(n, 1);
  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, int>> fs;
  for (ll i = 2; i * i <= n; i++) {
    int x = 0;
    while (n % i == 0) {
      n /= i;
      x++;
    }
    if (x != 0)
      fs.emplace_back(i, x);
  }
  if (n != 1)
    fs.emplace_back(n, 1);
  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
// In the name of GOD

#include <bits/stdc++.h>
#define ll long long
#define pp pair<int, int>
using namespace std;
const ll N = 1e9, MOD = 998244353;

void solve() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0;
    return;
  }
  int ans = 0;
  for (int i = 2; i * i <= n; ++i) {
    int count = 0;
    while (n % i == 0) {
      count++;
      n /= i;
    }
    int x = 0;
    while (x * (x + 1) / 2 <= count)
      x++;
    ans += --x;
  }
  if (n > 2)
    ans++;
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tt = 1;
  // cin >> tt;
  for (int tc = 1; tc <= tt; ++tc) {
    solve();
  }
}


Fixed submission:
// In the name of GOD

#include <bits/stdc++.h>
#define ll long long
#define pp pair<int, int>
using namespace std;
const ll N = 1e9, MOD = 998244353;

void solve() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0;
    return;
  }
  int ans = 0;
  for (ll i = 2; i * i <= n; ++i) {
    int count = 0;
    while (n % i == 0) {
      count++;
      n /= i;
    }
    int x = 0;
    while (x * (x + 1) / 2 <= count)
      x++;
    ans += --x;
  }
  if (n > 2)
    ans++;
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tt = 1;
  // cin >> tt;
  for (int tc = 1; tc <= tt; ++tc) {
    solve();
  }
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout << "##" << x << "##" << endl;
void solve() {
  ll n, count1 = 0, ans = 0;
  cin >> n;
  while (n % 2 == 0) {
    n = n / 2;
    count1++;
  }
  ans += (sqrt(1.0 + 8 * count1) - 1) / 2;
  for (int i = 3; i * i <= n; i += 2) {
    count1 = 0;
    if (n == 1)
      break;
    while (n % i == 0) {
      n = n / i;
      count1++;
    }
    ans += (sqrt(1.0 + 8 * count1) - 1) / 2;
  }
  if (n != 1) {
    ans++;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int tt = 1;
  // cin>>tt;
  while (tt--)
    solve();
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout << "##" << x << "##" << endl;
void solve() {
  ll n, count1 = 0, ans = 0;
  cin >> n;
  while (n % 2 == 0) {
    n = n / 2;
    count1++;
  }
  ans += (sqrt(1.0 + 8 * count1) - 1) / 2;
  for (int i = 3; i <= sqrt(n); i += 2) {
    count1 = 0;
    if (n == 1)
      break;
    while (n % i == 0) {
      n = n / i;
      count1++;
    }
    ans += (sqrt(1.0 + 8 * count1) - 1) / 2;
  }
  if (n != 1) {
    ans++;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int tt = 1;
  // cin>>tt;
  while (tt--)
    solve();
  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, ans = 0, p;
  cin >> n;
  for (int i = 2; i * i <= n; i++) {
    ll cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    for (int j = 1;; j++) {
      if (cnt < j) {
        break;
      }
      cnt = cnt - j;
      ans++;
    }
  }
  if (n > 1) {
    ans++;
  }
  cout << ans << "\n";
}

Fixed submission:
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, ans = 0, p;
  cin >> n;
  for (int i = 2; i < 1000010; i++) {
    ll cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    for (int j = 1;; j++) {
      if (cnt < j) {
        break;
      }
      cnt = cnt - j;
      ans++;
    }
  }
  if (n > 1) {
    ans++;
  }
  cout << ans << "\n";
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define dbg(a) cerr << __LINE__ << ": " << #a << " = " << a << '\n'
typedef long long ll;

const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const ll MXN = 1e18;

map<ll, int> mp;
void factor(ll n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      while (n % i == 0) {
        mp[i]++;
        n /= i;
      }
    }
  }
  if (n > 1) {
    mp[n]++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  factor(n);
  int ans = 0;
  for (auto aa : mp) {
    long double p = aa.second;
    int val = (sqrt(1 + 8 * p) - 1) / 2;
    ans += val;
  }
  cout << ans << endl;
  return 0;
}

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

#define dbg(a) cerr << __LINE__ << ": " << #a << " = " << a << '\n'
typedef long long ll;

const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const ll MXN = 1e18;

map<ll, int> mp;
void factor(ll n) {
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      while (n % i == 0) {
        mp[i]++;
        n /= i;
      }
    }
  }
  if (n > 1) {
    mp[n]++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  factor(n);
  int ans = 0;
  for (auto aa : mp) {
    long double p = aa.second;
    int val = (sqrt(1 + 8 * p) - 1) / 2;
    ans += val;
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

void solve_test() {
  LL n;
  cin >> n;

  int ops = 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
      }

      int j = 1;
      while (cnt >= j) {
        cnt -= j;
        j++;
        ops++;
      }
    }
  }
  if (n > 1)
    ops++;

  cout << ops << '\n';
}

int main() {
  int T;
  T = 1;
  for (int t = 1; t <= T; t++)
    solve_test();

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

void solve_test() {
  LL n;
  cin >> n;

  int ops = 0;
  for (LL i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
      }

      int j = 1;
      while (cnt >= j) {
        cnt -= j;
        j++;
        ops++;
      }
    }
  }
  if (n > 1)
    ops++;

  cout << ops << '\n';
}

int main() {
  int T;
  T = 1;
  for (int t = 1; t <= T; t++)
    solve_test();

  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"

#define rep(i, N) for (int i = 0; i < N; i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

map<ll, int> factor(ll n) {
  map<ll, int> f;
  for (int i = 2; i * i < n; i++) {
    int x = 0;
    while (n % i == 0)
      n /= i, x++;
    if (x != 0)
      f[i] = x;
  }
  if (n != 1)
    f[n] = 1;
  return f;
}

int main(void) {
  ll N;
  cin >> N;

  auto f = factor(N);

  ll ans = 0;

  for (auto x : f) {
    int i = 1;
    int y = x.second;
    while (y >= i) {
      y -= i;
      i++;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

#define rep(i, N) for (int i = 0; i < N; i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

map<ll, int> factor(ll n) {
  map<ll, int> f;
  for (ll i = 2; i * i < n; i++) {
    int x = 0;
    while (n % i == 0)
      n /= i, x++;
    if (x != 0)
      f[i] = x;
  }
  if (n != 1)
    f[n] = 1;
  return f;
}

int main(void) {
  ll N;
  cin >> N;

  auto f = factor(N);

  ll ans = 0;

  for (auto x : f) {
    int i = 1;
    int y = x.second;
    while (y >= i) {
      y -= i;
      i++;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

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

  ll ans = 0;
  for (int i = 2; i * i < n; i++) {
    int cnt = 0, j = 1;
    while (n % i == 0)
      n /= i, cnt++;
    while (cnt >= j)
      cnt -= j, ans++, j++;
  }

  if (n != 1)
    ans++;
  cout << ans << endl;
  return 0;
}


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

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

  ll ans = 0;
  for (ll i = 2; i * i < n; i++) {
    int cnt = 0, j = 1;
    while (n % i == 0)
      n /= i, cnt++;
    while (cnt >= j)
      cnt -= j, ans++, j++;
  }

  if (n != 1)
    ans++;
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<ll> p;
  for (int a = 2; a * a <= n; a++) {
    if (n % a == 0) {
      p.push_back(0);
      while (n % a == 0) {
        p.back()++;
        n /= a;
      }
    }
  }
  if (n != 1)
    p.push_back(1);
  int cnt = 0;
  for (int i = 0; i < (int)p.size(); i++) {
    int num = 1;
    while (p[i] - num >= 0) {
      cnt++;
      p[i] -= num;
      num++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<ll> p;
  for (ll a = 2; a * a <= n; a++) {
    if (n % a == 0) {
      p.push_back(0);
      while (n % a == 0) {
        p.back()++;
        n /= a;
      }
    }
  }
  if (n != 1)
    p.push_back(1);
  int cnt = 0;
  for (int i = 0; i < (int)p.size(); i++) {
    int num = 1;
    while (p[i] - num >= 0) {
      cnt++;
      p[i] -= num;
      num++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
map<ll, ll> prime_factorization(long long n) {
  // map<ll,ll> first=素因数 second=first素因数の数
  map<ll, ll> res;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}
int main() {
  ll N;
  cin >> N;
  map<ll, ll> mp = prime_factorization(N);
  ll ans = 0;
  for (auto s : mp) {
    for (int i = 1; i <= s.second; i++) {
      ans++;
      s.second -= i;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
map<ll, ll> prime_factorization(long long n) {
  // map<ll,ll> first=素因数 second=first素因数の数
  map<ll, ll> res;
  for (int i = 2; i <= n / i; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}
int main() {
  ll N;
  cin >> N;
  map<ll, ll> mp = prime_factorization(N);
  ll ans = 0;
  for (auto s : mp) {
    for (int i = 1; i <= s.second; i++) {
      ans++;
      s.second -= i;
    }
  }
  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[70] = {};
int main() {
  ll n;
  cin >> n;
  vector<int> v;
  a[1] = 1;
  for (int i = 2; i < 70; i++) {
    a[i] = a[i - 1] + i;
  }
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      v.push_back(cnt);
    }
  }
  if (n > 1)
    v.push_back(1);
  sort(v.begin(), v.end());
  int ans = 0;
  int p = 1;
  for (int i = 0; i < (int)v.size(); i++) {
    while (a[p] <= v[i])
      p++;
    ans += p - 1;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[70] = {};
int main() {
  ll n;
  cin >> n;
  vector<int> v;
  a[1] = 1;
  for (int i = 2; i < 70; i++) {
    a[i] = a[i - 1] + i;
  }
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      v.push_back(cnt);
    }
  }
  if (n > 1)
    v.push_back(1);
  sort(v.begin(), v.end());
  int ans = 0;
  int p = 1;
  for (int i = 0; i < (int)v.size(); i++) {
    while (a[p] <= v[i])
      p++;
    ans += p - 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (int i = 2; i * i <= N; i++) {
    if (N % i != 0)
      continue;

    ll cnt = 0;
    while (N % i == 0) {
      N /= i;
      cnt++;
    }
    res.push_back(make_pair(i, cnt));
  }

  if (N != 1) {
    res.push_back(make_pair(N, 1));
  }
  return res;
}

int main(void) {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> res = prime_factorize(N);

  ll cnt = 0;
  for (int i = 0; i < res.size(); i++) {
    for (int j = 1; j <= res.at(i).second; j++) {

      ll tmp = pow(res.at(i).first, j);
      if (N % tmp == 0) {
        N /= tmp;
        cnt++;
      }

      if (N < tmp)
        break;
    }
  }
  cout << cnt << endl;
}


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

typedef long long ll;

vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= N; i++) {
    if (N % i != 0)
      continue;

    ll cnt = 0;
    while (N % i == 0) {
      N /= i;
      cnt++;
    }
    res.push_back(make_pair(i, cnt));
  }

  if (N != 1) {
    res.push_back(make_pair(N, 1));
  }
  return res;
}

int main(void) {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> res = prime_factorize(N);

  ll cnt = 0;
  for (int i = 0; i < res.size(); i++) {
    for (int j = 1; j <= res.at(i).second; j++) {

      ll tmp = pow(res.at(i).first, j);
      if (N % tmp == 0) {
        N /= tmp;
        cnt++;
      }

      if (N < tmp)
        break;
    }
  }
  cout << cnt << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)

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

  int ans = 0;

  for (int i = 2; i * i <= n; i++) {
    int e = 0;
    while (n % i == 0) {
      n /= i;
      e++;
    }
    int a = 1;
    while ((e - a) >= 0) {
      e -= a;
      a++;
      ans++;
    }
  }
  if (n != 1) {
    ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)

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

  int ans = 0;

  for (long long i = 2; i * i <= n; i++) {
    int e = 0;
    while (n % i == 0) {
      n /= i;
      e++;
    }
    int a = 1;
    while ((e - a) >= 0) {
      e -= a;
      a++;
      ans++;
    }
  }
  if (n != 1) {
    ans++;
  }
  cout << ans << endl;
}
Problem p02660 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

int main(int argc, const char *argv[]) {
  ios_base::sync_with_stdio(false);
  ll N;
  cin >> N;

  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }

  map<ll, int> Map;
  for (int n = 2; n * n <= N; ++n) {
    while (N % n == 0) {
      Map[n]++;
      N /= n;
    }
  }
  if (N != 1) {
    Map[N] = 1;
  }

  vector<int> Sum(11);
  for (int i = 1; i <= 10; ++i) {
    Sum[i] = Sum[i - 1] + i;
  }
  int Ans = 0;
  for (auto &z : Map) {
    int k = z.second;
    for (int i = 1; i <= 10; ++i) {
      if (k < Sum[i]) {
        Ans += i - 1;
        break;
      }
    }
  }
  cout << Ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

int main(int argc, const char *argv[]) {
  ios_base::sync_with_stdio(false);
  ll N;
  cin >> N;

  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }

  map<ll, int> Map;
  for (ll n = 2; n * n <= N; ++n) {
    while (N % n == 0) {
      Map[n]++;
      N /= n;
    }
  }
  if (N != 1) {
    Map[N] = 1;
  }

  vector<int> Sum(11);
  for (int i = 1; i <= 10; ++i) {
    Sum[i] = Sum[i - 1] + i;
  }
  int Ans = 0;
  for (auto &z : Map) {
    int k = z.second;
    for (int i = 1; i <= 10; ++i) {
      if (k < Sum[i]) {
        Ans += i - 1;
        break;
      }
    }
  }
  cout << Ans << endl;

  return 0;
}
Problem p02660 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
const ll inf = 1LL << 60;
const int pp = 1e6 + 10;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // cout << fixed << setprecision(15);
  ll N;
  cin >> N;
  vector<bool> is_prime(pp + 1, true);
  REP(i, pp + 1) {
    if (i == 0 || i == 1) {
      is_prime[i] = false;
    }
    if (is_prime[i] == true) {
      for (int k = 2 * i; k <= pp; k += i) {
        is_prime[k] = false;
      }
    }
  }
  vector<int> prime(pp + 1, 0);
  int itr = 0;
  for (int i = 2; i * i <= N; i++) {
    if (is_prime[i]) {
      while (N % i == 0) {
        N /= i;
        prime[itr]++;
      }
      itr++;
      if (N == 1)
        break;
    }
  }
  if (N > 1) {
    prime[itr]++;
    itr++;
  }

  int ans = 0;
  REP(i, itr) {
    int k = 1;
    while (k * (k + 1) / 2 <= prime[i]) {
      k++;
    }
    k--;
    ans += k;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
const ll inf = 1LL << 60;
const int pp = 1e6 + 10;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // cout << fixed << setprecision(15);
  ll N;
  cin >> N;
  vector<bool> is_prime(pp + 1, true);
  REP(i, pp + 1) {
    if (i == 0 || i == 1) {
      is_prime[i] = false;
    }
    if (is_prime[i] == true) {
      for (int k = 2 * i; k <= pp; k += i) {
        is_prime[k] = false;
      }
    }
  }
  vector<int> prime(pp + 1, 0);
  int itr = 0;
  for (ll i = 2; i * i <= N; i++) {
    if (is_prime[i]) {
      while (N % i == 0) {
        N /= i;
        prime[itr]++;
      }
      itr++;
      if (N == 1)
        break;
    }
  }
  if (N > 1) {
    prime[itr]++;
    itr++;
  }

  int ans = 0;
  REP(i, itr) {
    int k = 1;
    while (k * (k + 1) / 2 <= prime[i]) {
      k++;
    }
    k--;
    ans += k;
  }
  cout << ans << endl;
}
Problem p02661 (C++)

Buggy submission (status: 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;
  }
}
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;
}

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;
  }
  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;
}
Problem p02661 (C++)

Buggy submission (status: 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 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;
}


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 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;
}
Problem p02661 (C++)

Buggy submission (status: 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)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;
}


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)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;
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
int n, a[N], b[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a, a + n);
  sort(b, b + n);
  reverse(b, b + n);
  if (n & 1) {
    cout << b[n / 2] - a[n / 2] + 1;
  } else {
    assert(false);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
int n, a[N], b[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a, a + n);
  sort(b, b + n);
  reverse(b, b + n);
  if (n & 1) {
    cout << b[n / 2] - a[n / 2] + 1;
  } else {
    pair<ll, ll> le = {a[n / 2 - 1], b[n / 2]};
    pair<ll, ll> re = {a[n / 2], b[n / 2 - 1]};
    cout << (le.second + re.second) - (le.first + re.first) + 1;
  }
  return 0;
}
Problem p02661 (C++)

Buggy submission (status: 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[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;
}

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[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;
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02661 (C++)

Buggy submission (status: 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 -1;
}

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 0;
}
Problem p02661 (C++)

Buggy submission (status: 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, 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;
}


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(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;
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#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;
}


Fixed submission:
#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;
}
Problem p02661 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A, B = [], []
for i in range(N):
    tm, p = map(int, input().split())
    A.append(tm), B.append(p)
A.sort(), B.sort()

a = A[N // 2] * 2 if N % 2 == 1 else A[N // 2] + A[N // 2 + 1]
b = B[N // 2] * 2 if N % 2 == 1 else B[N // 2] + B[N // 2 + 1]
print((b - a) // 2 + 1)


Fixed submission:
N = int(input())
A, B = [], []
for i in range(N):
    tm, p = map(int, input().split())
    A.append(tm), B.append(p)
A.sort(), B.sort()

a = A[N // 2] * 2 if N % 2 == 1 else A[N // 2 - 1] + A[N // 2]
b = B[N // 2] * 2 if N % 2 == 1 else B[N // 2 - 1] + B[N // 2]

print((b - a) // 2 + 1 if N % 2 == 1 else b - a + 1)
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#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();
}


Fixed submission:
#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();
}
Problem p02661 (C++)

Buggy submission (status: 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 < 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;
  }
}

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 < 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;
  }
}
Problem p02661 (C++)

Buggy submission (status: 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 = 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();
}


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 = 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();
}
Problem p02661 (C++)

Buggy submission (status: 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[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;
}

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[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;
}
Problem p02661 (C++)

Buggy submission (status: 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 = 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;
}

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 = 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;
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#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;
  }
}


Fixed submission:
#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;
  }
}