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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  string s;
  cin >> s;

  if (count(s.begin(), s.end(), s.at(0)) == 2 &&
      count(s.begin(), s.end(), s.at(1)) == 2 &&
      count(s.begin(), s.end(), s.at(2)) == 2 &&
      count(s.begin(), s.end(), s.at(3)) == 2) {
    cout << "Yes"
         << "\n";
    return 0;
  }
  cout << "No"
       << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  //  #ifndef ONLINE_JUDGE
  //  // for getting input from input.txt
  //  freopen("input.txt", "r", stdin);
  //  // for writing output to output.txt
  //  freopen("output.txt", "w", stdout);
  // #endif
  string s;
  cin >> s;

  if (count(s.begin(), s.end(), s.at(0)) == 2 &&
      count(s.begin(), s.end(), s.at(1)) == 2 &&
      count(s.begin(), s.end(), s.at(2)) == 2 &&
      count(s.begin(), s.end(), s.at(3)) == 2) {
    cout << "Yes"
         << "\n";
    return 0;
  }
  cout << "No"
       << "\n";
  return 0;
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main(void) {
  char *S;
  scanf("%s", S);

  int cnt = 0;
  for (int j = 0; j < 4; j++) {
    for (int i = 0; i < 4; i++) {
      if (S[j] == S[i]) {
        cnt++;
      }
    }
    if (cnt != 2) {
      printf("No");
      return 0;
    }
    cnt = 0;
  }

  printf("Yes");
  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  char S[4];
  scanf("%s", S);

  int cnt = 0;
  for (int j = 0; j < 4; j++) {
    for (int i = 0; i < 4; i++) {
      if (S[j] == S[i]) {
        cnt++;
      }
    }
    if (cnt != 2) {
      printf("No");
      return 0;
    }
    cnt = 0;
  }

  printf("Yes");
  return 0;
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define inf 2147483647
#define llinf 9223372036854775807
#define ll long long
using namespace std;
const int maxn = 1e5 + 10;

char s[5];
int cnt = 0, vis[26];

int main() {
  scanf("%s", s);
  for (int i = 0; i < 4; i++) {
    if (vis[s[i] - 'A'] != 0)
      continue;
    vis[s[i] - 'a'] = 1;
    cnt++;
  }
  if (cnt == 2)
    return puts("Yes"), 0;
  puts("No");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define inf 2147483647
#define llinf 9223372036854775807
#define ll long long
using namespace std;
const int maxn = 1e5 + 10;

char s[5];
int cnt = 0, vis[26];

int main() {
  scanf("%s", s);
  for (int i = 0; i < 4; i++) {
    if (vis[s[i] - 'A'] != 0)
      continue;
    vis[s[i] - 'A'] = 1;
    cnt++;
  }
  if (cnt == 2)
    return puts("Yes"), 0;
  puts("No");
  return 0;
}
Problem p02987 (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
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  cout << ((s[0] == s[1] && s[2] == s[3] && s[0] != s[3]) ? "Yes\n" : "No\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
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  cout << ((s[0] == s[1] && s[2] == s[3] && s[0] != s[3]) ? "Yes\n" : "No\n");
  return 0;
}
Problem p02987 (C++)

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

// A
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  string s;
  cin >> s;
  map<char, ll> m;
  ll i;
  for (i = 0; i < s.length(); i++) {
    m[s[i]]++;
  }
  if (m.size() != 2) {
    cout << "No";
  } else {
    map<char, ll>::iterator it;
    for (it = m.begin(); it != m.end(); it++) {
      if (it->second != 2) {
        cout << "No";
        return 0;
      }
    }
    cout << "Yes";
  }
}

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

// A
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  string s;
  cin >> s;
  map<char, ll> m;
  ll i;
  for (i = 0; i < s.length(); i++) {
    m[s[i]]++;
  }
  if (m.size() != 2) {
    cout << "No";
  } else {
    map<char, ll>::iterator it;
    for (it = m.begin(); it != m.end(); it++) {
      if (it->second != 2) {
        cout << "No";
        return 0;
      }
    }
    cout << "Yes";
  }
}
Problem p02987 (C++)

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

int main() {
  string s;
  cin >> s;

  sort(s.begin(), s.end());
  int cnt = 0;
  rep(i, 4) {
    if (s.at(i) != s.at(i + 1))
      cnt++;
  }

  if (cnt == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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

int main() {
  string s;
  cin >> s;

  map<char, int> mp;
  rep(i, s.size()) { mp[s.at(i)]++; }
  if (mp.size() == 2 && mp[s.at(0)] == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p02987 (C++)

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

int main() {
  vector<char> s;
  for (int i = 0; i < 4; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  if (s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
  vector<char> s(4);
  for (int i = 0; i <= 3; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  if (s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <stdio.h>
#include <time.h>
#include <unordered_set>
#include <vector>

#define prev askdnsajd
#define rank asasdmdnasd
#define next lsjndajbs
#define hash asmdklansd
#define index asdklnas
#define right sld
#define left sldl
using namespace std;

typedef long long ll;
typedef long double dbl;

template <class T> void print(vector<T> s) {
  for (T x : s)
    cout << x << " ";
  cout << endl;
}

void solve() {}

int main() {
  srand(17);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  freopen("a.in", "r", stdin);
  string s;
  cin >> s;
  map<char, int> cnt;
  for (int i = 0; i < 4; i++)
    cnt[s[i]]++;
  for (int i = 0; i < 4; i++) {
    if (cnt[s[i]] != 2) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}

Fixed submission:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <stdio.h>
#include <time.h>
#include <unordered_set>
#include <vector>

#define prev askdnsajd
#define rank asasdmdnasd
#define next lsjndajbs
#define hash asmdklansd
#define index asdklnas
#define right sld
#define left sldl
using namespace std;

typedef long long ll;
typedef long double dbl;

template <class T> void print(vector<T> s) {
  for (T x : s)
    cout << x << " ";
  cout << endl;
}

void solve() {}

int main() {
  srand(17);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("a.in", "r", stdin);
  string s;
  cin >> s;
  map<char, int> cnt;
  for (int i = 0; i < 4; i++)
    cnt[s[i]]++;
  for (int i = 0; i < 4; i++) {
    if (cnt[s[i]] != 2) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  sort(&s, &s + 4);
  if (s[0] == s[1] && s[2] == s[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if (s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p02987 (C++)

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

int main(int argc, char *argv[]) {
  if ((argv[1][0] == argv[1][1] && argv[1][2] == argv[1][3]) ||
      (argv[1][0] == argv[1][2] && argv[1][1] == argv[1][3]) ||
      (argv[1][0] == argv[1][3] && argv[1][1] == argv[1][2])) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}

Fixed submission:
#include <iostream>

int main(int argc, char *argv[]) {
  char c[5];
  std::cin >> c;
  if ((c[0] == c[1] && c[2] == c[3] && c[0] != c[2]) ||
      (c[0] == c[2] && c[1] == c[3] && c[0] != c[1]) ||
      (c[0] == c[3] && c[1] == c[2] && c[0] != c[1])) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}
Problem p02987 (C++)

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

int main() {

  string s;
  cin >> s;

  if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(0) != s.at(2) ||
      s.at(0) == s.at(2) && s.at(1) == s.at(3) && s.at(0) != s.at(1) ||
      s.at(0) == s.at(4) && s.at(1) == s.at(3) && s.at(0) != s.at(1))

    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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

int main() {

  string s;
  cin >> s;

  if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(0) != s.at(2) ||
      s.at(0) == s.at(2) && s.at(1) == s.at(3) && s.at(0) != s.at(1) ||
      s.at(0) == s.at(3) && s.at(1) == s.at(2) && s.at(0) != s.at(1))

    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define db(x) cout << #x << "=" << x << endl;
using namespace std;
char a[10];
int cnt[27];
int main() {
  scanf("%s", a);
  for (int i = 0; i < 4; i++)
    cnt[a[i] - 'a']++;
  bool flg = 0;
  for (int i = 0; i < 26; i++)
    if (cnt[i] && cnt[i] != 2)
      flg = 1;
  puts(flg ? "No" : "Yes");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define db(x) cout << #x << "=" << x << endl;
using namespace std;
char a[10];
int cnt[27];
int main() {
  scanf("%s", a);
  for (int i = 0; i < 4; i++)
    cnt[a[i] - 'A']++;
  bool flg = 0;
  for (int i = 0; i < 26; i++)
    if (cnt[i] && cnt[i] != 2)
      flg = 1;
  puts(flg ? "No" : "Yes");
  return 0;
}
Problem p02987 (Python)

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

print("Yes" if all(S.count(s) == 2 for s in input()) else "No")


Fixed submission:
S = input()

print("Yes" if all(S.count(s) == 2 for s in S) else "No")
Problem p02987 (C++)

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

int main() {
  string S;
  sort(S.begin(), S.end());
  if (S.at(0) == S.at(1) && S.at(1) != S.at(2) && S.at(2) == S.at(3))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  vector<char> S(4);
  for (int i = 0; i < 4; i++)
    cin >> S.at(i);
  sort(S.begin(), S.end());
  if (S.at(0) == S.at(1) && S.at(1) != S.at(2) && S.at(2) == S.at(3))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02987 (Python)

Buggy submission (status: Runtime Error):
from collections import defaultdict

S = defaultdict(int)
for i in input():
    S[i] += 1

a, b, *_ = S.values()
if a == b == 2:
    print("Yes")
else:
    print("No")


Fixed submission:
from collections import defaultdict

S = defaultdict(int)
for i in input():
    S[i] += 1

if len(S.values()) == 2:
    a, b = S.values()
    if a == b == 2:
        print("Yes")
        exit()
print("No")
Problem p02987 (Python)

Buggy submission (status: Runtime Error):
S = input()
if S[0] == S[1] and S[2] == S[3] and len(set(S)) == 2:
    print("Yes")
elif S[0] == S[2] and S[1] == S[4] and len(set(S)) == 2:
    print("Yes")
elif S[0] == S[3] and S[1] == S[2] and len(set(S)) == 2:
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
if S[0] == S[1] and S[2] == S[3] and len(set(S)) == 2:
    print("Yes")
elif S[0] == S[2] and S[1] == S[3] and len(set(S)) == 2:
    print("Yes")
elif S[0] == S[3] and S[1] == S[2] and len(set(S)) == 2:
    print("Yes")
else:
    print("No")
Problem p02987 (Python)

Buggy submission (status: Runtime Error):
s = list(input())
t = set[s]
if len(t) == 2 and s.count(t[0]) == 2:
    print("Yes")
else:
    print("No")


Fixed submission:
s = list(input())
t = list(set(s))
if len(t) == 2 and s.count(t[0]) == 2:
    print("Yes")
else:
    print("No")
Problem p02987 (Python)

Buggy submission (status: Runtime Error):
S = input()
S = S.strip(S[0])

if len(S[0]) > 0:
    S = S.strip(S[0])
    if len(S) == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Fixed submission:
S = input()
S = S.replace(S[0], "")
if len(S) > 0:
    S = S.replace(S[0], "")
    if len(S) == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")
Problem p02987 (Python)

Buggy submission (status: Runtime Error):
s = input()
s.sort()
ans = "No"
if s[0] == s[1] and s[2] == s[3]:
    if s[1] != s[2]:
        ans = "Yes"
print(ans)


Fixed submission:
s = list(input())
s.sort()
ans = "No"
if s[0] == s[1] and s[2] == s[3]:
    if s[1] != s[2]:
        ans = "Yes"
print(ans)
Problem p02987 (Python)

Buggy submission (status: Runtime Error):
S = input()
S2 = set(list(S))
print("Yes") if len(S2) == 2 and S.count(S2[0]) == S.count(S2[1]) else print("No")


Fixed submission:
S = input()
S2 = list(set(S))
print("Yes") if len(S2) == 2 and S.count(S2[0]) == S.count(S2[1]) else print("No")
Problem p02987 (Python)

Buggy submission (status: Runtime Error):
from collections import Counter


s = input()
c = Counter(s)
if len(c) == 2 and c.most_common(1)[1] == 2:
    print("Yes")
else:
    print("No")


Fixed submission:
from collections import Counter


s = input()
c = Counter(s)
if len(c) == 2 and c.most_common(1)[0][1] == 2:
    print("Yes")
else:
    print("No")
Problem p02987 (Python)

Buggy submission (status: Runtime Error):
import sys


s = sys.argv[1]

if len(s) == 4:
    if s.count(s[0]) == 2:
        if s.count(s[1]) == 2:
            if s.count(s[2]) == 2:
                if s.count(s[3]) == 2:
                    print("Yes")
                    exit()
print("No")
exit()


Fixed submission:
import sys


# s = sys.argv[1]
s = input()
if len(s) == 4:
    if s.count(s[0]) == 2:
        if s.count(s[1]) == 2:
            if s.count(s[2]) == 2:
                if s.count(s[3]) == 2:
                    print("Yes")
                    exit()
print("No")
exit()
Problem p02988 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

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

  vi p(n);
  rep(i, n) cin >> p.at(i);

  int ans = 0;
  rep1(i, n - 1) {
    if (p.at(i - 1) < p.at(i) && p.at(i) < p.at(i + 1))
      ans++;
    else if (p.at(i - 1) > p.at(i) && p.at(i) > p.at(i + 1))
      ans++;
  }

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

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

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

  vi p(n);
  rep(i, n) cin >> p.at(i);

  int ans = 0;
  rep1(i, n - 2) {
    if (p.at(i - 1) < p.at(i) && p.at(i) < p.at(i + 1))
      ans++;
    else if (p.at(i - 1) > p.at(i) && p.at(i) > p.at(i + 1))
      ans++;
  }

  cout << ans << endl;
  return 0;
}
Problem p02988 (C++)

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

using namespace std;

int main(void) {
  int n;
  vector<int> p;

  cin >> n;

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

  int cnt = 0;
  for (int i = 1; i < n - 1; i++) {
    if (p[i - 1] < p[i] && p[i] < p[i + 1])
      cnt++;
    else if (p[i - 1] > p[i] && p[i] > p[i + 1])
      cnt++;
  }
  cout << cnt << endl;
}

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

using namespace std;

int main(void) {
  int n;
  vector<int> p;

  cin >> n;

  p.resize(n + 1);

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

  int cnt = 0;
  for (int i = 1; i < n - 1; i++) {
    if (p[i - 1] < p[i] && p[i] < p[i + 1])
      cnt++;
    else if (p[i - 1] > p[i] && p[i] > p[i + 1])
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02988 (C++)

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

  int count = 0;
  for (int k = 0; k < N - 1; k++) {
    if ((P.at(k) - P.at(k - 1)) * (P.at(k + 1) - P.at(k)) > 0) {
      count++;
    }
  }

  cout << count << 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);
  }

  int count = 0;
  for (int k = 1; k < N - 1; k++) {
    if ((P.at(k) - P.at(k - 1)) * (P.at(k + 1) - P.at(k)) > 0) {
      count++;
    }
  }

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

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

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

  for (int i = 1; i < n - 1; i++) {
    if (data.at(i + 1) < max(data.at(i - 1), data.at(i + 2)) &&
        data.at(i + 1) > min(data.at(i - 1), data.at(i + 2))) {
      count++;
    }
  }
  cout << count << endl;
}


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

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

  for (int i = 0; i < n - 2; i++) {
    int a = max(data.at(i), data.at(i + 2));
    int b = min(data.at(i), data.at(i + 2));

    if (data.at(i + 1) < a && data.at(i + 1) > b) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02988 (C++)

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

// B
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n;
  cin >> n;
  ll i;
  ll a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll c = 0;
  for (i = 1; i < n - 1; i++) {
    if ((a[i] > a[i - 1] && a[i] < a[i + 1]) ||
        (a[i] < a[i - 1] && a[i] > a[i + 1]))
      c++;
  }
  cout << c;
}

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

// B
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n;
  cin >> n;
  ll i;
  ll a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll c = 0;
  for (i = 1; i < n - 1; i++) {
    if ((a[i] > a[i - 1] && a[i] < a[i + 1]) ||
        (a[i] < a[i - 1] && a[i] > a[i + 1]))
      c++;
  }
  cout << c;
}
Problem p02988 (C++)

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

int main() {
  int n, ans;
  ans = 0;
  cin >> n;
  vector<int> P(n);
  rep(i, n) cin >> P[i];
  rep(i, n - 1) if (P[i] < P[i + 1] && P[i + 1] < P[i + 2]) ans += 1;
  cout << ans << endl;
}

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

int main() {
  int n, ans;
  ans = 0;
  cin >> n;
  vector<int> P(n);
  rep(i, n) cin >> P[i];
  rep(i, n - 2) if (P[i] < P[i + 1] && P[i + 1] < P[i + 2]) ans++;
  else if ((P[i] > P[i + 1]) && (P[i + 1] > P[i + 2])) ans++;
  cout << ans << endl;
}
Problem p02988 (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 p(n);
  for (int &x : p)
    cin >> x;
  int cnt = 0;
  fore(i, 1, n - 1) if ((p[i - 1] <= p[i] && p[i] <= p[i + 1]) ||
                        (p[i - 1] >= p[i] && p[i] >= p[i + 1]))++ cnt;
  cout << cnt << '\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 p(n);
  for (int &x : p)
    cin >> x;
  int cnt = 0;
  fore(i, 1, n - 1) if ((p[i - 1] <= p[i] && p[i] <= p[i + 1]) ||
                        (p[i - 1] >= p[i] && p[i] >= p[i + 1]))++ cnt;
  cout << cnt << '\n';
  return 0;
}
Problem p02988 (C++)

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

int main() {
  int num;
  int i;
  int pn[4];
  int count = 0;

  cin >> num;
  for (i = 0; i < num; i++)
    cin >> pn[i];

  for (i = 1; i < num - 1; i++) {
    if (pn[i - 1] < pn[i] && pn[i] < pn[i + 1])
      count++;
    else if (pn[i + 1] < pn[i] && pn[i] < pn[i - 1])
      count++;
  }
  cout << count << endl;
}


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

int main() {
  int num;
  int i;
  int pn[20];
  int count = 0;

  cin >> num;
  for (i = 0; i < num; i++)
    cin >> pn[i];

  for (i = 1; i < num - 1; i++) {
    if (pn[i - 1] < pn[i] && pn[i] < pn[i + 1])
      count++;
    else if (pn[i + 1] < pn[i] && pn[i] < pn[i - 1])
      count++;
  }
  cout << count << endl;
}
Problem p02988 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    if (i > 1) {
      if (((vec.at(i) < vec.at(i - 1)) && (vec.at(i - 1) < vec.at(i - 2)) ||
           ((vec.at(i) > vec.at(i - 1))) && (vec.at(i - 1) > vec.at(i + 2)))) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    if (i > 1) {
      if (((vec.at(i) < vec.at(i - 1)) && (vec.at(i - 1) < vec.at(i - 2)) ||
           ((vec.at(i) > vec.at(i - 1))) && (vec.at(i - 1) > vec.at(i - 2)))) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02988 (C++)

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

  int k = 0;

  for (int i = 0; i < n - 2; i++) {
    if (p.at(i - 1) < p.at(i) && p.at(i) < p.at(i + 1))
      k++;
    else if (p.at(i + 1) < p.at(i) && p.at(i) < p.at(i - 1))
      k++;
  }
  cout << k << 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);

  int k = 0;

  for (int i = 1; i < n - 1; i++) {
    if (p.at(i - 1) < p.at(i) && p.at(i) < p.at(i + 1))
      k++;
    else if (p.at(i + 1) < p.at(i) && p.at(i) < p.at(i - 1))
      k++;
  }
  cout << k << endl;
}
Problem p02988 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 0; i < n - 2; i) {
    if (p[i] < p[i + 1] < p[i + 2]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) {
      ans++;
    } else if (p[i] > p[i + 1] && p[i + 1] > p[i + 2]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02988 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

#define max(a, b) (a < b ? b : a)
#define min(a, b) (a < b ? a : b)

int main(void) {
  int N;
  scanf("%d", &N);

  int p[20];
  for (int i = 0; i < N; i++) {
    scanf("%d", p[i]);
  }

  int cnt = 0;
  for (int i = 1; i < N - 1; i++) {
    int ma = max(max(p[i - 1], p[i]), p[i + 1]);
    int mi = min(min(p[i - 1], p[i]), p[i + 1]);
    if ((ma != p[i]) && (mi != p[i])) {
      cnt++;
    }
  }

  printf("%d", cnt);
}

Fixed submission:
#include <stdio.h>

#define max(a, b) (a < b ? b : a)
#define min(a, b) (a < b ? a : b)

int main(void) {
  int N;
  scanf("%d", &N);

  int p[20];
  for (int i = 0; i < N; i++) {
    scanf("%d", &p[i]);
  }

  int cnt = 0;
  for (int i = 1; i < N - 1; i++) {
    int ma = max(max(p[i - 1], p[i]), p[i + 1]);
    int mi = min(min(p[i - 1], p[i]), p[i + 1]);
    if ((ma != p[i]) && (mi != p[i])) {
      cnt++;
    }
  }

  printf("%d", cnt);
}
Problem p02988 (C++)

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

#define int long long

typedef long long li;
typedef long double ld;

void solve();
int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
const int N = 2e5;
int n;
int p[N];
void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  int ans = 0;
  for (int i = 2; i < n; ++i) {
    vector<int> lol;
    lol.push_back(p[i]);
    lol.push_back(p[i - 1]);
    lol.push_back(p[i + 1]);
    sort(lol.begin(), lol.end());
    if (lol[1] == p[i])
      ans++;
  }
  cout << ans;
}

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

#define int long long

typedef long long li;
typedef long double ld;

void solve();
int32_t main() {
#ifndef ONLINE_JUDGE
  //  freopen("input.txt", "r", stdin);
#endif
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
const int N = 2e5;
int n;
int p[N];
void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  int ans = 0;
  for (int i = 2; i < n; ++i) {
    vector<int> lol;
    lol.push_back(p[i]);
    lol.push_back(p[i - 1]);
    lol.push_back(p[i + 1]);
    sort(lol.begin(), lol.end());
    if (lol[1] == p[i])
      ans++;
  }
  cout << ans;
}
Problem p02988 (C++)

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

int main() {
  int n;
  vector<int> s(n);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int ans = 0;

  for (int i = 1; i < n - 1; i++) {
    if (s[i] < s[i + 1] || s[i] < s[i - 1]) {
      if (s[i] > s[i + 1] || s[i] > s[i - 1]) {
        ++ans;
        // cout<<s[i]<<endl;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  vector<int> s(30);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int ans = 0;

  for (int i = 1; i < n - 1; i++) {
    if (s[i] < s[i + 1] || s[i] < s[i - 1]) {
      if (s[i] > s[i + 1] || s[i] > s[i - 1]) {
        ++ans;
        // cout<<s[i]<<endl;
      }
    }
  }
  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)
using namespace std;
using ll = long long;

int index(vector<int> d, int x) {
  rep(i, d.size()) {
    if (d[i] >= x)
      return i;
  }
  return -1;
}

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> d(n);
  int halfn = n / 2;

  rep(i, n) cin >> d[i];

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

  int maximum = d[n - 1];
  for (int i = 1; i <= maximum; i++) {
    int kindex = index(d, i);
    if (kindex == halfn)
      ans++;
    else if (kindex > halfn) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

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

int index(vector<int> d, int x) {
  rep(i, d.size()) {
    if (d[i] >= x)
      return i;
  }
  return -1;
}

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> d(n);
  int halfn = n / 2;

  rep(i, n) cin >> d[i];

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int n, i;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  cout << a[n / 2] - a[(n / 2) - 1];
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, i;
  cin >> n;
  int a[n];
  for (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 <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define rep(a, b, c) for (int a = b, a##end = c; a <= a##end; ++a)
#define drep(a, b, c) for (int a = b, a##end = c; a >= a##end; --a)

char IO;
int rd() {
  int s = 0, f = 0;
  while (IO = getchar(), IO < '0' || IO > '9')
    if (IO == '-')
      f = 1;
  do
    s = (s << 1) + (s << 3) + (IO ^ '0');
  while (IO = getchar(), IO >= '0' && IO <= '9');
  return f ? -s : s;
}

const int N = 300, K = 50;

int n;
int a[N];

int main() {
  rep(i, 1, n = rd()) a[i] = rd();
  sort(a + 1, a + n + 1);
  if (n & 1)
    return puts("0"), 0;
  int mid = n / 2;
  printf("%d\n", a[mid + 1] - a[mid]);
}


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

typedef long long ll;

#define rep(a, b, c) for (int a = b, a##end = c; a <= a##end; ++a)
#define drep(a, b, c) for (int a = b, a##end = c; a >= a##end; --a)

char IO;
int rd() {
  int s = 0, f = 0;
  while (IO = getchar(), IO < '0' || IO > '9')
    if (IO == '-')
      f = 1;
  do
    s = (s << 1) + (s << 3) + (IO ^ '0');
  while (IO = getchar(), IO >= '0' && IO <= '9');
  return f ? -s : s;
}

const int N = 1e5 + 10, K = 50;

int n;
int a[N];

int main() {
  rep(i, 1, n = rd()) a[i] = rd();
  sort(a + 1, a + n + 1);
  if (n & 1)
    return puts("0"), 0;
  int mid = n / 2;
  printf("%d\n", a[mid + 1] - a[mid]);
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a, b) memset((a), (b), sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e3 + 10;
int a[N];
int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int n;
  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] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a, b) memset((a), (b), sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int a[N];
int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int n;
  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] << endl;
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

char N;
int d[100005];
int ans = 0;
signed main() {
  scanf("%lld", &N);
  rep(i, N) { scanf("%lld", &d[i]); }
  sort(d, d + N);
  ans = d[(N / 2)] - d[(N / 2) - 1];
  printf("%lld\n", ans);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

int N;
int d[100005];
int ans = 0;
signed main() {
  scanf("%lld", &N);
  rep(i, N) { scanf("%lld", &d[i]); }
  sort(d, d + N);
  ans = d[(N / 2)] - d[(N / 2) - 1];
  printf("%lld\n", ans);
}
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);
  for (int i = 0; i < N; i++)
    cin >> d.at(i);

  int count = 0;
  sort(d.begin(), d.end());
  for (int i = d.at(N / 2 - 1); i < d.at(N / 2); i++) {
    int r = 0, b = 0;
    for (int j = 0; j < N; j++) {
      if (i < d.at(j))
        r++;
      else
        b++;
    }
    if (r == b)
      count++;
  }
  cout << count << 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);

  int count = 0;
  sort(d.begin(), d.end());
  count = d.at(N / 2) - d.at(N / 2 - 1);

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  ll d[n];
  for (ll i = 0; i < n; i++)
    cin >> d[i];
  sort(d, d + n);
  cout << d[n / 2] - d[n / 2 - 1];
}

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

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

int main() {
  int N;
  cin >> N;
  int arr[N];
  int temp;
  for (int i = 0; i < N; i++) {
    cin >> arr[i];
  }
  int length = sizeof(arr) / sizeof(arr[0]);
  for (int i = 0; i < length; i++) {
    for (int j = i + 1; j < length; j++) {
      if (arr[i] > arr[j]) {
        temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
      }
    }
  }
  int mid = length / 2;
  int result;
  if (arr[mid - 1] == arr[mid]) {
    result = 0;
  } else {
    result = arr[mid] - arr[mid - 1];
  }
  cout << result;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int arr[N];
  int temp;
  for (int i = 0; i < N; i++) {
    cin >> arr[i];
  }
  int length = sizeof(arr) / sizeof(arr[0]);
  sort(arr, arr + length);
  int mid = length / 2;
  int result;
  if (arr[mid - 1] == arr[mid]) {
    result = 0;
  } else {
    result = arr[mid] - arr[mid - 1];
  }
  cout << result;
  return 0;
}
Problem p02989 (C++)

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

template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}

int main(void) {
  int n;
  cin >> n;
  vector<int> d(n);
  for (auto &i : d)
    cin >> i;
  sort(d.begin(), d.end());
  cout << d.at(n / 2 + 1) - d.at(n / 2) << endl;
  return 0;
}


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

template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}

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

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++)
    cin >> v[N];

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

  int answer = v[v.size() / 2] - v[v.size() / 2 - 1];

  cout << answer << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++)
    cin >> v[i];

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

  int answer = v[v.size() / 2] - v[v.size() / 2 - 1];

  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> vec(N);
  for (int X = 0; X < N; X++) {
    cin >> vec.at(N);
  }
  sort(vec.begin(), vec.end());
  cout << vec.at(N / 2) - vec.at(N / 2 - 1) << endl;
}

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9')
    c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x;
}
const int N = 1e5 + 9;
int a[25], n, ans;
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= 100000; i++) {
    int p = lower_bound(a + 1, a + n + 1, i) - a;
    int num1 = p - 1, num2 = n - p + 1;
    if (num1 == num2)
      ans++;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9')
    c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x;
}
const int N = 1e5 + 9;
int a[N], n, ans;
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= 100000; i++) {
    int p = lower_bound(a + 1, a + n + 1, i) - a;
    int num1 = p - 1, num2 = n - p + 1;
    if (num1 == num2)
      ans++;
  }
  cout << ans;
}
Problem p02989 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define pi 3.14159265358979323846264338327950

int main() {
  int N;
  std::cin >> N;
  std::vector<int> D(N);
  for (auto &r : D)
    std::cin >> r;
  int ans = 0;
  for (int i = 1; i <= 100000; ++i) {
    int count_e = 0;
    int count_h = 0;
    for (auto &r : D) {
      if (r > i)
        ++count_e;
      if (r <= i)
        ++count_h;
    }
    if (count_e == count_h)
      ++ans;
  }
  std::cout << ans << std::endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define pi 3.14159265358979323846264338327950

int main() {
  int N;
  std::cin >> N;
  std::vector<int> D(N);
  for (auto &r : D)
    std::cin >> r;
  std::sort(D.begin(), D.end());
  std::cout << D[N / 2] - D[N / 2 - 1] << std::endl;

  return 0;
}
Problem p02989 (C++)

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

ll n;
vector<ll> d;

bool solve(ll k) {
  ll abc = 0, arc = 0;
  for (auto v : d) {
    if (v >= k) {
      arc++;
    } else {
      abc++;
    }
  }

  return abc == arc;
}

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

  cin >> n;

  d.resize(n);
  for (auto &v : d) {
    cin >> v;
  }
  sort(begin(d), end(d));

  ll left = *min_element(begin(d), end(d));
  ll right = *max_element(begin(d), end(d));

  ll ans = 0;

  bool isFrist = true;
  for (ll i = left; i <= right; i++) {
    if (solve(i)) {
      ans++;

      isFrist = false;
      continue;
    }

    if (!isFrist) {
      break;
    }
  }

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


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

ll n;
vector<ll> d;

bool solve(ll k) {
  ll abc = 0, arc = 0;
  for (auto v : d) {
    if (v >= k) {
      arc++;
    } else {
      abc++;
    }
  }

  return abc == arc;
}

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

  cin >> n;

  d.resize(n);
  for (auto &v : d) {
    cin >> v;
  }
  sort(begin(d), end(d));
  ll ans = d[n / 2] - d[n / 2 - 1];
  cout << ans << endl;
  return 0;
}
Problem p02989 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for (int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

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

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for (int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
  int n;
  int d[100010];
  cin >> n;
  imfor(i, n) { cin >> d[i]; }
  sort(d, d + n);
  int ans = d[(n / 2)] - d[(n / 2) - 1];
  cout << ans << endl;
}
Problem p02989 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for k in range(1, max(p) + 1):
    abc = 0
    arc = 0
    for i in p:
        if i < k:
            abc += 1
        else:
            arc += 1
    if abc == arc:
        ans += 1
print(ans)


Fixed submission:
n = int(input())
p = sorted(list(map(int, input().split())))
a = int(len(p) / 2)
if p[a - 1] == p[a]:
    print(0)
else:
    print(p[a] - p[a - 1])