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

Buggy submission (status: Runtime Error):
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std;

inline void solve() {
  int n;
  cin >> n;
  int res[n];
  for (int i = 1; i <= n; i++) {
    cin >> res[i];
  }
  sort(res + 1, res + n + 1);
  if (res[n / 2] == res[(n / 2) + 1])
    cout << 0 << endl;
  else
    cout << (res[n / 2 + 1] - res[n / 2]) << endl;
}

signed main() {
  int n = 1; // cin>>n;
  while (n--)
    solve();
  return 0;
}


Fixed submission:
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std;

inline void solve() {
  int n;
  cin >> n;
  int res[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> res[i];
  }
  sort(res + 1, res + n + 1);
  if (res[n / 2] == res[(n / 2) + 1])
    cout << 0 << endl;
  else
    cout << (res[n / 2 + 1] - res[n / 2]) << endl;
}

signed main() {
  int n = 1; // cin>>n;
  while (n--)
    solve();
  return 0;
}
Problem p02989 (Python)

Buggy submission (status: Runtime Error):
N = input()

D = sorted([int(v) for v in input().split()])
arc = N // 2
abc = arc - 1
print(D[arc] - D[abc])


Fixed submission:
N = int(input())

D = sorted([int(v) for v in input().split()])
arc = N // 2
abc = arc - 1
print(D[arc] - D[abc])
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {
  int d[10000], n;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  sort(d, d + n);

  cout << abs(d[n / 2 - 1] - d[n / 2]) << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {
  int d[100000], n;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  sort(d, d + n);

  cout << abs(d[n / 2 - 1] - d[n / 2]) << endl;
  return 0;
}
Problem p02989 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int c = 0, cR, cB;
  for (int i = vec.at(0); i <= vec.at(N - 1); i++) {
    cR = 0;
    cB = 0;
    for (int j = 0; j < N; j++) {
      if (i <= vec.at(j))
        cR++;
      else
        cB++;
    }
    if (cR == cB)
      c++;
  }
  cout << c;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  cout << vec.at(N / 2) - vec.at(N / 2 - 1);
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;

int n, arr[10000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  int sum = arr[n / 2] - arr[n / 2 - 1];
  cout << sum;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

int n, arr[100000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  int sum = arr[n / 2] - arr[n / 2 - 1];
  cout << sum;
  return 0;
}
Problem p02989 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
D = list(map(int, input().split()))
D.sort()

count = 0
cur = 0
for i in range(10**5 + 1):
    if cur == N / 2:
        count += 1
    if cur > N / 2:
        break
    if D[cur] < i and cur < N:
        cur += 1
        while D[cur - 1] == D[cur]:
            cur += 1
print(count)


Fixed submission:
N = int(input())
D = list(map(int, input().split()))
D.sort()

ans = D[int(N / 2)] - D[int((N / 2) - 1)]
print(ans)
Problem p02989 (Python)

Buggy submission (status: Runtime Error):
# coding: utf-8


def main():
    N = int(input())
    d = sorted(list(map(int, input().split())))
    ans = 0
    if d[N / 2] != d[N / 2 - 1]:
        ans = d[N / 2] - d[N / 2 - 1]

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
# coding: utf-8


def main():
    N = int(input())
    d = sorted(list(map(int, input().split())))
    ans = 0
    if d[N // 2] != d[N // 2 - 1]:
        ans = d[N // 2] - d[N // 2 - 1]

    print(ans)


if __name__ == "__main__":
    main()
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, a[200];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + 1 + n);
  int l = a[n / 2];
  int r = a[n / 2 + 1];
  // cout<<l<<" "<<r<<endl;
  cout << r - l;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, a[100005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + 1 + n);
  int l = a[n / 2];
  int r = a[n / 2 + 1];
  // cout<<l<<" "<<r<<endl;
  cout << r - l;
}
Problem p02989 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
D = list(map(int, input().split())).sort()
print(D[N // 2] - D[(N // 2) - 1])


Fixed submission:
N = int(input())
D = sorted(list(map(int, input().split())))
print(D[N // 2] - D[(N // 2) - 1])
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N;
  int d[30]; // 最大 100 個ですが余裕をもたせます
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> d[i];

  sort(d, d + N);

  cout << d[N / 2] - d[N / 2 - 1] << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N;
  int d[100100]; // 最大 100 個ですが余裕をもたせます
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> d[i];

  sort(d, d + N);

  cout << d[N / 2] - d[N / 2 - 1] << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef long double ld;
#define pa pair<int, int>
#define sc(n) scanf("%lld", &n)
#define fo(i, a, b) for (int i = a; i < b; i++)
#define mem(a, b) memset(a, b, sizeof a)
using namespace std;
int n, m;
unordered_map<char, int> mp;
int a[50], b[50];
// struct cmp
//{
//	bool operator () (int x, int y)
//	{
//		return x > y;
//	}
// };
int main() {
  int t;
  int cnt = 0;
  sc(n);
  fo(i, 0, n) sc(a[i]);
  sort(a, a + n);
  int l = n / 2 - 1, r = l + 1;
  cout << a[r] - a[l] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef long double ld;
#define pa pair<int, int>
#define sc(n) scanf("%lld", &n)
#define fo(i, a, b) for (int i = a; i < b; i++)
#define mem(a, b) memset(a, b, sizeof a)
using namespace std;
int n, m;
unordered_map<char, int> mp;
int a[N], b[N];
// struct cmp
//{
//	bool operator () (int x, int y)
//	{
//		return x > y;
//	}
// };
int main() {
  int t;
  int cnt = 0;
  sc(n);
  fo(i, 0, n) sc(a[i]);
  sort(a, a + n);
  int l = n / 2 - 1, r = l + 1;
  cout << a[r] - a[l] << endl;
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> v;
  int n;
  int m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    v.push_back(m);
  }
  int up = 0;
  int down = 0;
  int c = 0;
  for (int i = 1; i < v[distance(v.begin(), max_element(v.begin(), v.end()))];
       i++) {
    for (int j = 0; j < n; j++) {
      if (v[j] <= i) {
        up++;
      } else {
        down++;
      }
    }
    if (up == down) {
      c++;
    }
    up = 0;
    down = 0;
  }
  cout << c << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> v;
  int n;
  int m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    v.push_back(m);
  }

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

  int s = n / 2;
  cout << v[s] - v[s - 1] << endl;

  return 0;
}
Problem p02989 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  cout << a.at(n / 2) - a.at(n / 2 - 1) << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  cout << a.at(n / 2) - a.at(n / 2 - 1) << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, p[25], ans;
int main() {
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  sort(p, p + n);
  ans = p[n / 2] - p[(n / 2) - 1];
  if (ans <= 0) {
    ans = 0;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, p[500000], ans;
int main() {
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  sort(p, p + n);
  ans = p[n / 2] - p[(n / 2) - 1];
  if (ans <= 0) {
    ans = 0;
  }
  cout << ans << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                                                              \
  for (int i = 0; i < n; i++)                                                  \
    ;
using ll = long long;
int main() {
  int N;
  cin >> N;
  int a = N / 2;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int s = 0;
  int answer = 0;
  for (int i = d.at(a - 1) + 1; i <= d.at(a); i++) {
    if (s != d.at(i)) {
      answer++;
      s = i;
    }
  }
  cout << answer << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                                                              \
  for (int i = 0; i < n; i++)                                                  \
    ;
using ll = long long;
int main() {
  int N;
  cin >> N;
  int a = N / 2;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int s = 0;
  int answer = 0;
  for (int i = d.at(a - 1) + 1; i <= d.at(a); i++) {
    if (s != i) {
      answer++;
      s = i;
    }
  }
  cout << answer << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++)
    cin >> d.at(i);

  sort(d.begin(), d.end());
  cout << d.at(n / 2 + 1) - d.at(n / 2) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++)
    cin >> d.at(i);

  sort(d.begin(), d.end());
  cout << d.at(n / 2) - d.at((n / 2) - 1) << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define pb push_back
#define mp make_pair
#define test                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef pair<int, int> pii;
typedef unordered_map<int, int> mp;

const int mod = 1e9 + 7;
const int inf = 1e18;

int32_t main() {
  FAST;

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n;
  cin >> n;
  if (n & 1) {
    cout << 0 << endl;
    return 0;
  }
  int a[n];
  for (int x = 0; x < n; x++) {
    cin >> a[x];
  }

  sort(a, a + n);

  int se = a[n / 2], fi = a[n / 2 - 1];

  cout << (se - fi) << '\n';

  return 0;
}


Fixed submission:
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define pb push_back
#define mp make_pair
#define test                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef pair<int, int> pii;
typedef unordered_map<int, int> mp;

const int mod = 1e9 + 7;
const int inf = 1e18;

int32_t main() {
  FAST;

  int n;
  cin >> n;
  if (n & 1) {
    cout << 0 << endl;
    return 0;
  }
  int a[n];
  for (int x = 0; x < n; x++) {
    cin >> a[x];
  }

  sort(a, a + n);

  int se = a[n / 2], fi = a[n / 2 - 1];

  cout << (se - fi) << '\n';

  return 0;
}
Problem p02989 (C++)

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

// #define TEST_CASES
using ll = long long;
#define ff first
#define ss second
const int N = 1e5 + 10;

int n;
int a[N];

void solve() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  int p = 0;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    while (a[p] < i)
      p++;
    if (n - p == p)
      ans++;
    if (p > n - p)
      break;
  }
  cout << ans << endl;
}

int main() {
  int t = 1;
#ifdef TEST_CASES
  cin >> t;
#endif
  while (t--) {
    solve();
  }
}


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

// #define TEST_CASES
using ll = long long;
#define ff first
#define ss second
const int N = 1e5 + 10;

int n;
int a[N];

void solve() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  int p = 0;
  int ans = 0;
  for (int i = 0; p < n and i < N; i++) {
    while (p < n and a[p] < i)
      p++;
    if (n - p == p)
      ans++;
    if (p > n - p)
      break;
  }
  cout << ans << endl;
}

int main() {
  int t = 1;
#ifdef TEST_CASES
  cin >> t;
#endif
  while (t--) {
    solve();
  }
}
Problem p02989 (C++)

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

int main() {
  ll n, a[50000] = {};
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  sort(a, a + n);
  n /= 2;

  cout << (a[n] - a[n - 1]) << "\n";
  return 0;
}


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

int main() {
  ll n, a[100000] = {};
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  sort(a, a + n);
  n /= 2;

  cout << (a[n] - a[n - 1]) << "\n";
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
#include <algorithm>

int main() {

  int N;
  cin >> N;
  int d[N];
  for (int i = 0; i < N; ++i) {
    cin >> d[i];
  }
  sort(d, d + N);
  int res = 0;
  int num_ARC = 0;
  int num_ABC = 0;
  int K_max = d[N - 1];
  for (int i = 0; i < K_max; ++i) {
    for (int j = 0; j < N; ++j) {
      if (i >= d[j]) {
        ++num_ARC;
      } else {
        ++num_ABC;
      }
      if (num_ARC + num_ABC == N) {
        if (num_ARC == num_ABC) {
          ++res;
          num_ARC = 0;
          num_ABC = 0;
          continue;
        } else {
          num_ARC = 0;
          num_ABC = 0;
          continue;
        }
      }
    }
  }
  cout << res;
}

Fixed submission:
#include <iostream>
using namespace std;
#include <algorithm>

int main() {

  int N;
  cin >> N;
  int d[N];
  for (int i = 0; i < N; ++i) {
    cin >> d[i];
  }
  sort(d, d + N);
  int res = 0;
  int num_ABC = d[N / 2 - 1];
  int num_ARC = d[N / 2];
  res = num_ARC - num_ABC;
  cout << res;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  vector<int> d(N);
  int D = 0;
  for (int i = 0; i < N; i++)
    cin >> d[i];
  sort(d.begin(), d.end());
  int ans;
  int diff = d[N / 2] - d[N / 2 - 1];
  if (diff == 0)
    ans = 0;
  else
    ans = diff;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  int D = 0;
  for (int i = 0; i < N; i++)
    cin >> d[i];
  sort(d.begin(), d.end());
  int ans;
  int diff = d[N / 2] - d[N / 2 - 1];
  if (diff == 0)
    ans = 0;
  else
    ans = diff;
  cout << ans << endl;
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, i, ans = 0;
  cin >> N;
  bool a = true;
  vector<int> d(N);
  for (i = 0; i < N; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  for (int K = d.at(0); K < d[N / 2] + 1; K++) {
    i = 0;
    while (d[i] < K) {
      i++;
      if (i > N / 2) {
        a = false;
        break;
      }
    }
    if (i == N / 2)
      ans++;
    if (!a)
      break;
  }
  cout << ans;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, i, ans = 0;
  cin >> N;
  bool a = true;
  vector<int> d(N);
  for (i = 0; i < N; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  if (d.at(N / 2 - 1) != d.at(N / 2))
    ans = d.at(N / 2) - d.at(N / 2 - 1);
  cout << ans;
}
Problem p02989 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++)
    cin >> d.at(i);

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

  int k = 0;

  for (int i = d.at(n / 2); i <= d.at(i + 1); i++)
    k++;

  cout << k << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++)
    cin >> d.at(i);

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

  cout << d.at(n / 2) - d.at(n / 2 - 1) << endl;
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main(void) {
  long long int n, i, j;
  scanf("%lld", &n);
  long long int d[n];
  for (i = 0; i < n; i++) {
    scanf("%lld", &d[i]);
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (d[i] > d[j]) {
        long long int tmp = d[i];
        d[i] = d[j];
        d[j] = tmp;
      }
    }
  }
  printf("%lld", d[n / 2] - d[n / 2 - 1]);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  cout << a[n / 2] - a[n / 2 - 1];
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int N, d[10001], ans;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }

  sort(d, d + N);

  ans = d[N / 2] - d[N / 2 - 1];

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int N, d[100000], ans;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }

  sort(d, d + N);

  ans = d[N / 2] - d[N / 2 - 1];

  cout << ans << endl;

  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

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

  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }

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

  int mid_1st = d.at(0.5 * N - 1);
  int mid_2nd = d.at(0.5 * N);

  int res = 0;
  if (mid_1st != mid_2nd) {
    res = mid_2nd - mid_1st;
    if (mid_2nd == d.at(0.5 * N + 1)) {
      res -= 1;
    }
  }

  cout << res << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

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

  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }

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

  int mid_1st = d.at(0.5 * N - 1);
  int mid_2nd = d.at(0.5 * N);

  int res = 0;
  if (mid_1st != mid_2nd) {
    res = mid_2nd - mid_1st;
  }

  cout << res << endl;
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  int ans = 0;
  for (int i = 0; i < d.size(); i++) {
    cin >> d.at(i);
  }

  for (int K = 0; K <= 100000; K++) {
    int sumR = 0;
    int sumB = 0;
    for (int i = 0; i < d.size(); i++) {
      if (d.at(i) >= K) {
        sumR++;
      } else {
        sumB++;
      }
    }
    if (sumR == sumB) {
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  int ans = 0;
  for (int i = 0; i < d.size(); i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  cout << d.at(N / 2) - d.at(N / 2 - 1) << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N, d[20];
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> d[i];
  sort(d, d + N);
  cout << d[N / 2] - d[N / 2 - 1] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N, d[100000], count = 0;
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> d[i];
  sort(d, d + N);
  cout << d[N / 2] - d[N / 2 - 1] << endl;
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  for (int i = d[N / 2] - 1; i <= d[i]; i++) {
    ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  for (int i = d[(N / 2) - 1] + 1; i <= d[N / 2]; i++) {
    ans++;
  }
  cout << ans << endl;
}
Problem p02989 (C++)

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

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  sort(d.begin(), d.end());
  rep(i, 100000) {
    int cnt = 0;
    rep(j, n) {
      if (i < d[j])
        cnt++;
      else if (cnt > n / 2)
        break;
    }
    if (cnt == n / 2)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  sort(d.begin(), d.end());
  cout << d[n / 2] - d[n / 2 - 1] << endl;
  return 0;
}
Problem p02989 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int med = n / 2;
  int ans = a.at(med + 1) - a.at(med);
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int med = n / 2;
  int ans = a.at(med) - a.at(med - 1);
  cout << ans << endl;
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  long n;
  int d[100000];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (d[i] > d[j]) {
        int tmp = d[i];
        d[i] = d[j];
        d[j] = tmp;
      }
    }
  }

  if (d[n / 2] == d[n / 2 - 1]) {
    cout << 0 << endl;
  } else {
    cout << d[n / 2] - d[n / 2 - 1] << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  long n;
  int d[100000];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  sort(d, d + n);

  if (d[n / 2] == d[n / 2 - 1]) {
    cout << 0 << endl;
  } else {
    cout << d[n / 2] - d[n / 2 - 1] << endl;
  }

  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int cnt = 0, a[10001] = {0}, n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  cout << a[n / 2 + 1] - a[n / 2];
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int cnt = 0, a[100001] = {0}, n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  cout << a[n / 2 + 1] - a[n / 2];
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void swp(int &a, int &b) {
  int tmp = a;
  a = b;
  b = tmp;
}

void quicksort(int a[], int lower, int upper) {
  int bound = a[lower], l = lower, u = upper;
  do {
    while (a[l] < bound)
      l++;
    while (a[u] > bound)
      u--;
    if (l <= u) {
      swp(a[l], a[u]);
      l++;
      u--;
    }
  } while (l < u);
  if (lower < u)
    quicksort(a, lower, u);
  if (l < upper)
    quicksort(a, l, upper);
}

int main() {
  int p[20], num;
  cin >> num;
  for (int i = 0; i < num; i++) {
    cin >> p[i];
  }
  quicksort(p, 0, num - 1);
  cout << p[num / 2] - p[num / 2 - 1] << endl;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void swp(int &a, int &b) {
  int tmp = a;
  a = b;
  b = tmp;
}

void quicksort(int a[], int lower, int upper) {
  int bound = a[lower], l = lower, u = upper;
  do {
    while (a[l] < bound)
      l++;
    while (a[u] > bound)
      u--;
    if (l <= u) {
      swp(a[l], a[u]);
      l++;
      u--;
    }
  } while (l < u);
  if (lower < u)
    quicksort(a, lower, u);
  if (l < upper)
    quicksort(a, l, upper);
}

int main() {
  int p[100000], num;
  cin >> num;
  for (int i = 0; i < num; i++) {
    cin >> p[i];
  }
  quicksort(p, 0, num - 1);
  cout << p[num / 2] - p[num / 2 - 1] << endl;
  return 0;
}
Problem p02989 (C++)

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

using namespace std;

int main() {

  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++)
    cin >> d.at(i);
  sort(d.begin(), d.end());

  int counter = 0;
  for (int K = d.at(0); K <= d.at(N - 1); K++) {
    int ARC = 0;
    for (int i = 0; i < N; i++) {
      if (ARC > N / 2)
        break;
      if (K <= d.at(i))
        ARC++;
    }
    if (ARC == N / 2)
      counter++;
  }
  cout << counter << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

int main() {

  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++)
    cin >> d.at(i);
  sort(d.begin(), d.end());

  cout << d.at(N / 2) - d.at((N / 2) - 1) << endl;
}
Problem p02989 (C++)

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

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

  sort(d, d + n);
  cout << d[n / 2] - d[n / 2 - 1] << endl;
}


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

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

  sort(d, d + n);
  cout << d[n / 2] - d[n / 2 - 1] << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int n, d[10100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  sort(d, d + n);
  cout << d[n / 2] - d[n / 2 - 1] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int n, d[101000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  sort(d, d + n);
  cout << d[n / 2] - d[n / 2 - 1] << endl;
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> d(10001);
  for (int i = 0; i < n; i++)
    cin >> d[i];
  sort(d.begin(), d.begin() + n);
  cout << d[n / 2] - d[n / 2 - 1] << "\n";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> d(100001);
  for (int i = 0; i < n; i++)
    cin >> d[i];
  sort(d.begin(), d.begin() + n);
  cout << d[n / 2] - d[n / 2 - 1] << "\n";
  return 0;
}
Problem p02989 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
    l.at(i) = d.at(i);
  }
  sort(l.begin(), l.end());
  int cnt = 0;
  for (int k = l.at(0); k <= l.at(n - 1); k++) {
    int ARC = 0;
    int ABC = 0;
    for (int j = 0; j < n; j++) {
      if (d.at(j) >= k) {
        ARC++;
      } else {
        ABC++;
      }
    }
    if (ARC == ABC) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++)
    cin >> d[i];
  sort(d.begin(), d.end());
  int ans = d[n / 2] - d[n / 2 - 1];
  cout << ans << endl;
  return 0;
}
Problem p02989 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  int MIN = 1000040, MAX = -1;
  rep(i, n) {
    cin >> d[i];
    MIN = min(MIN, d[i]);
    MAX = max(MAX, d[i]);
  }
  int cnt = 0;
  for (int i = MIN; i <= MAX; i++) {
    int arc = 0, abc = 0;
    rep(j, n) {
      if (d[j] >= i)
        arc++;
      else
        abc++;
    }
    if (arc == abc)
      cnt++;
  }
  cout << cnt << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) { cin >> d[i]; }
  sort(d.begin(), d.end());
  ll right = d[n / 2];
  ll left = d[n / 2 - 1];
  cout << right - left << endl;
}
Problem p02989 (C++)

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

int main() {
  int N, mass, count;
  cin >> N;
  mass = 0;
  count = 0;

  vector<int> diff(N);
  for (int i = 0; i < N; i++) {
    cin >> diff.at(i);
  }
  for (int K = 1; K < 100001; K++) {
    for (int i = 0; i < N; i++) {
      if (K >= diff.at(i)) {
        mass++;
      } else {
        mass--;
      }
    }
    if (mass == 0) {
      count++;
    } else if (mass == N) {
      break;
    }
    mass = 0;
  }
  cout << count << endl;
}


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

int main() {
  int N, mass, count;
  cin >> N;
  mass = 0;
  count = 0;

  vector<int> diff(N);
  for (int i = 0; i < N; i++) {
    cin >> diff.at(i);
  }
  sort(diff.begin(), diff.end());

  count = diff.at(N / 2) - diff.at(N / 2 - 1);

  cout << count << endl;
}
Problem p02989 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++)
    cin >> p.at(i);
  sort(p.begin(), p.end());
  int abc = 0;
  int pat = 0;
  for (int i = p.at(0); i <= p.at(n - 1); i++) {
    for (int j = 0; j < n; j++) {
      if (i > p.at(j))
        abc++;
      else
        break;
    }
    if (abc == n / 2)
      pat++;
    abc = 0;
  }
  cout << pat << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++)
    cin >> p.at(i);
  sort(p.begin(), p.end());

  int ans = 0;
  ans = p.at(n / 2) - p.at(n / 2 - 1);
  cout << ans << endl;
}
Problem p02989 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int d1 = d.at(n / 2), d2 = d.at((n / 2) + 1), k = d2 - d1;
  cout << k << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int d1 = d.at((n / 2) - 1), d2 = d.at(n / 2), k = d2 - d1;
  cout << k << endl;
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define DEBUG 1
#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#endif
  int n;
  cin >> n;
  vi a(n);
  for (int &x : a)
    cin >> x;
  sort(a.begin(), a.end());
  if (a[n / 2] == a[n / 2 - 1])
    cout << "0\n";
  else
    cout << a[n / 2] - a[n / 2 - 1] << '\n';
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define DEBUG 1
#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE

  ios_base::sync_with_stdio(false);
  cin.tie(0);
#endif
  int n;
  cin >> n;
  vi a(n);
  for (int &x : a)
    cin >> x;
  sort(a.begin(), a.end());
  if (a[n / 2] == a[n / 2 - 1])
    cout << "0\n";
  else
    cout << a[n / 2] - a[n / 2 - 1] << '\n';
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
// Divide the Problems

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / __gcd(a, b) * b
#define range(a) (a).begin(), (a).end()
const int inf = 2147483647;

int o = 0;

bool isMin(int d) { return d > o; }

int main() {
  int N, Ans = 0;
  cin >> N;
  vector<int> d(N);
  rep(i, 0, N) cin >> d[i];
  sort(range(d));
  for (o = 0; o < d[N - 1] + 1; o++) {
    if (count_if(range(d), isMin) == N / 2)
      Ans++;
  }
  cout << Ans << endl;
  return 0;
}

Fixed submission:
// Divide the Problems

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / __gcd(a, b) * b
#define range(a) (a).begin(), (a).end()
const int inf = 2147483647;

int o = 0;

bool isMin(int d) { return d > o; }

int main() {
  int N, Ans = 0;
  cin >> N;
  vector<int> d(N);
  rep(i, 0, N) cin >> d[i];
  sort(range(d));
  cout << d[N / 2] - d[N / 2 - 1] << endl;
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int a = vec.at(n / 2 - 1);
  int b = vec.at(n / 2);
  cout << b - a << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int a = vec.at(n / 2 - 1);
  int b = vec.at(n / 2);
  cout << b - a << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[25];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int ans = 0;
  sort(a, a + n);
  cout << a[n / 2] - a[n / 2 - 1] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int ans = 0;
  sort(a, a + n);
  cout << a[n / 2] - a[n / 2 - 1] << endl;
  return 0;
}
Problem p02989 (C++)

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

int main() {
  int N;
  vector<int> D(N);
  for (int i = 0; i < N; i++)
    cin >> D.at(i);
  sort(D.begin(), D.end());
  int ans = D.at(N / 2) - D.at(N / 2 - 1);
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++)
    cin >> D.at(i);
  sort(D.begin(), D.end());
  int ans = D.at(N / 2) - D.at(N / 2 - 1);
  cout << ans << endl;
}
Problem p02989 (C++)

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

int main() {
  int N;
  vector<int> d(N);
  for (int i = 0; i < N; i++)
    cin >> d.at(i);
  sort(d.begin(), d.end());
  int ans = d.at(N / 2) - d.at(N / 2 - 1);
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++)
    cin >> d.at(i);
  sort(d.begin(), d.end());
  int ans = d.at(N / 2) - d.at(N / 2 - 1);
  cout << ans << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int b[10000];
  int a;
  cin >> a;
  int x = a / 2;
  int y = x - 1;
  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  sort(b, b + a);
  cout << (b[x] - b[y]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int b[100000];
  int a;
  cin >> a;
  int x = a / 2;
  int y = x - 1;
  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  sort(b, b + a);
  cout << (b[x] - b[y]);
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
        string s;
        char a=0,b=0;
        int aa=0,bb=0;
        cin>>s;
        for(int i=0;i<4;i++)
        if(a==0) a=s[i];
        else if(s[i]==a) aa++;
        else if(b==0) b=s[i];
        else if(s[i]==b) bb++;
        else
        {
                cout<<"No";
                return 0;
        }
        if(aa!=2||bb!=2)
        {
                cout<<"No";
                return 0;
        }
        cout<<"Yes";
}*/
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
        int f[10010];
        int n;
        cin>>n;
        for(int i=1;i<=n;i++) cin>>f[i];
        int ans=0;
        for(int i=2;i<=n-1;i++)
        if(f[i-1]<f[i]&&f[i]<f[i+1]||f[i+1]<f[i]&&f[i]<f[i-1]) ans++;
        cout<<ans<<endl;
}*/
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int f[10010];
  for (int i = 1; i <= n; i++)
    cin >> f[i];
  sort(f + 1, f + n + 1);
  if (n % 2 != 0) {
    cout << 0;
    return 0;
  }
  cout << f[n / 2 + 1] - f[n / 2];
}

Fixed submission:
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
        string s;
        char a=0,b=0;
        int aa=0,bb=0;
        cin>>s;
        for(int i=0;i<4;i++)
        if(a==0) a=s[i];
        else if(s[i]==a) aa++;
        else if(b==0) b=s[i];
        else if(s[i]==b) bb++;
        else
        {
                cout<<"No";
                return 0;
        }
        if(aa!=2||bb!=2)
        {
                cout<<"No";
                return 0;
        }
        cout<<"Yes";
}*/
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
        int f[10010];
        int n;
        cin>>n;
        for(int i=1;i<=n;i++) cin>>f[i];
        int ans=0;
        for(int i=2;i<=n-1;i++)
        if(f[i-1]<f[i]&&f[i]<f[i+1]||f[i+1]<f[i]&&f[i]<f[i-1]) ans++;
        cout<<ans<<endl;
}*/
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int f[800010];
  for (int i = 1; i <= n; i++)
    cin >> f[i];
  sort(f + 1, f + n + 1);
  if (n % 2 != 0) {
    cout << 0;
    return 0;
  }
  cout << f[n / 2 + 1] - f[n / 2];
}
Problem p02989 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  cout << d.at(N / 2 + 1) - d.at(N / 2) + 1 << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  cout << d.at(N / 2) - d.at(N / 2 - 1) << endl;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> PP;

vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
  int n, d[105];
  cin >> n;
  rep(i, n) cin >> d[i];
  sort(d, d + n);
  int ans = d[n / 2] - d[n / 2 - 1];
  // cout << d[n/2] <<" " <<d[n/2-1] << endl;
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> PP;

vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
  int n, d[100005];
  cin >> n;
  rep(i, n) cin >> d[i];
  sort(d, d + n);
  int ans = d[n / 2] - d[n / 2 - 1];
  // cout << d[n/2] <<" " <<d[n/2-1] << endl;
  cout << ans << endl;

  return 0;
}