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

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
  char a[200];
  int i = 0, cnt = 0, start = 0, e = 0, sum = 0;
  scanf("%s", &a);
  while (a[i] != 0) {
    cnt += 1;
    i++;
  }
  i--;
  for (i = cnt; i > 0; i--) {
    if (a[i] == 'Z') {
      e = i;
      break;
    }
  }
  for (i = 0; i < 200000; i++) {
    if (a[i] == 'A') {
      start = i;
      break;
    }
  }
  sum = (e - start) + 1;
  printf("%d", sum);
}


Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
  char a[200000];
  int i = 0, cnt = 0, start = 0, e = 0, sum = 0;
  scanf("%s", &a);
  while (a[i] != 0) {
    cnt += 1;
    i++;
  }
  i--;
  for (i = cnt; i > 0; i--) {
    if (a[i] == 'Z') {
      e = i;
      break;
    }
  }
  for (i = 0; i < 200000; i++) {
    if (a[i] == 'A') {
      start = i;
      break;
    }
  }
  sum = (e - start) + 1;
  printf("%d", sum);
}
Problem p03814 (Python)

Buggy submission (status: Runtime Error):
s = input()
a = s.fin("A")
z = s.find("Z")
print(z - a + 1)


Fixed submission:
s = input()
a_index = s.find("A")
z_index = s.rfind("Z")
print(z_index - a_index + 1)
Problem p03814 (Python)

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

start = s.index("A")

for i in range(len(s), start, -1):
    if s[i] == "Z":
        print(i - start + 1)
        break


Fixed submission:
s = input()

start = s.index("A")

for i in range(len(s) - 1, start, -1):
    if s[i] == "Z":
        print(i - start + 1)
        break
Problem p03814 (C++)

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

int main() {
  string s;
  int i, j, k, l, mx, mx1, a[100005], b[100005];
  while (cin >> s) {

    k = 0;
    l = 0;
    for (i = 0; i < s.size(); i++) {
      if (s[i] == 'A') {
        a[k++] = i;
      }
      if (s[i] == 'Z') {
        b[l++] = i;
      }
    }
    sort(a, a + k);
    sort(b, b + l);
    cout << b[l - 1] - a[0] + 1 << endl;
  }
  return 0;
}


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

int main() {
  string s;
  int i, j, k, l, mx, mx1, a[200005], b[200005];
  while (cin >> s) {

    k = 0;
    l = 0;
    for (i = 0; i < s.size(); i++) {
      if (s[i] == 'A') {
        a[k++] = i;
      }
      if (s[i] == 'Z') {
        b[l++] = i;
      }
    }
    sort(a, a + k);
    sort(b, b + l);
    cout << b[l - 1] - a[0] + 1 << endl;
  }
  return 0;
}
Problem p03814 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int i = 0;
  int j = n - 1;
  while (s[i] != 'A')
    i++;
  while (s[i] != 'Z')
    j--;
  int ans = j - i + 1;

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int i = 0;
  int j = n - 1;
  while (s[i] != 'A')
    i++;
  while (s[j] != 'Z')
    j--;
  int ans = j - i + 1;

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = {0, 0, 1, -1};
const int c_Dy[4] = {1, -1, 0, 0};
const int c_div = 1000000007; // 10^9 + 7

char S[300000];
int A[300000], Z[300000];

int main() {

  scanf("%s", S);

  int inA = 0;
  int inZ = 0;

  for (int i = 0; i < strlen(S); i++) {
    if (S[i] == 'A') {
      A[inA] = i;
      inA++;
    } else if (S[i] == 'Z') {
      Z[inZ] = i;
      inZ++;
    }
  }

  int ans = 0;
  for (int i = 0; i < inA; i++) {
    for (int j = 0; j < inZ; j++) {
      if (Z[j] > A[i]) {
        ans = max(Z[j] - A[i] + 1, ans);
      }
    }
  }

  printf("%d", ans);
}


Fixed submission:
#include <algorithm>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = {0, 0, 1, -1};
const int c_Dy[4] = {1, -1, 0, 0};
const int c_div = 1000000007; // 10^9 + 7

char S[300000];
int A[300000], Z[300000];

int main() {

  scanf("%s", S);

  int inA = 0;
  int inZ = 0;

  for (int i = 0; i < strlen(S); i++) {
    if (S[i] == 'A') {
      A[inA] = i;
      inA++;
    } else if (S[i] == 'Z') {
      Z[inZ] = i;
      inZ++;
    }
  }

  int ans = 0;
  for (int i = 0; i < inA; i++) {
    ans = max(Z[inZ - 1] - A[i] + 1, ans);
  }

  printf("%d", ans);
}
Problem p03814 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
using namespace std;
signed main() {
  string s;
  int a, b;
  rep(i, s.size()) {
    if (s.at(i) == 'A') {
      a = i;
      break;
    }
  }
  for (int i = s.size() - 1; -300000 < i; i--) {
    if (s.at(i) == 'Z') {
      b = i;
      break;
    }
  }
  cout << b - a + 1;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
using namespace std;
signed main() {
  string s;
  cin >> s;
  int a, b;
  rep(i, s.size()) {
    if (s.at(i) == 'A') {
      a = i;
      break;
    }
  }
  for (int i = s.size() - 1; -300000 < i; i--) {
    if (s.at(i) == 'Z') {
      b = i;
      break;
    }
  }
  cout << b - a + 1;
}
Problem p03814 (C++)

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

int main() {
  string s;
  cin >> s;
  int a = 0;
  int c = 0;
  for (int i = 0; i < 1000000; i++) {
    if (s.at(i) == 'A') {
      a = i;
      break;
    }
  }
  for (int i = s.size() - 1; i < 1000000; i++) {
    if (s.at(i) == 'Z') {
      c = i;
      break;
    }
  }
  cout << c - a + 1 << endl;
}


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

int main() {
  string s;
  cin >> s;
  int a = 0;
  int c = 0;
  for (int i = 0; i < 1000000; i++) {
    if (s.at(i) == 'A') {
      a = i;
      break;
    }
  }
  for (int i = s.size() - 1; i < 1000000; i--) {
    if (s.at(i) == 'Z') {
      c = i;
      break;
    }
  }
  cout << c - a + 1 << endl;
}
Problem p03814 (C++)

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

int main() {
  string a;
  cin >> a;
  int i = 0;
  int j = a.size();

  while (1) {
    if (a.at(i) == 'A')
      break;
    else
      i++;
  }

  while (1) {
    if (a.at(j) == 'Z')
      break;
    else
      j--;
  }

  cout << j - i + 1 << endl;
}

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

int main() {
  string a;
  cin >> a;
  int i = 0;
  int j = a.size() - 1;

  while (1) {
    if (a.at(i) == 'A')
      break;
    else
      i++;
  }

  while (1) {
    if (a.at(j) == 'Z')
      break;
    else
      j--;
  }

  cout << j - i + 1 << endl;
}
Problem p03814 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define N 112345
using namespace std;
int n, m, sum, res, flag;
char s[N];
int main() {
  int i, j, k, T, cas, x, y, t;
  scanf("%s", s);
  res = 0;
  n = strlen(s);
  x = n;
  y = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == 'A')
      x = min(x, i);
    if (s[i] == 'Z')
      y = max(y, i);
    res = max(res, y - x + 1);
  }
  printf("%d\n", res);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define N 212345
using namespace std;
int n, m, sum, res, flag;
char s[N];
int main() {
  int i, j, k, T, cas, x, y, t;
  scanf("%s", s);
  res = 0;
  n = strlen(s);
  x = n;
  y = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == 'A')
      x = min(x, i);
    if (s[i] == 'Z')
      y = max(y, i);
    res = max(res, y - x + 1);
  }
  printf("%d\n", res);
  return 0;
}
Problem p03814 (C++)

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

int main() {
  string s;
  cin >> s;
  int maxi = 0;
  for (int i = 0; i < s.length();) {
    if (s[i] == 'A') {
      int j = i + 1;
      while (s[j] != 'Z')
        j++;
      maxi = max(maxi, j - i + 1);
      i = j + 1;
    } else
      i++;
  }
  cout << maxi << "\n";

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  int i, j;
  for (i = 0; i < s.length(); i++)
    if (s[i] == 'A')
      break;
  for (j = s.length() - 1; j >= 0; j--)
    if (s[j] == 'Z')
      break;
  cout << j - i + 1 << "\n";

  return 0;
}
Problem p03814 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define INFLL (1ll << 60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

ll sq(ll x) { return x * x; }

void mul_mod(ll &a, ll b) {
  a *= b;
  a %= MOD;
}

bool isvowel(char c) {
  int i;
  string v = "aeiou";
  for (i = (v.size() - 1); i >= 0; --i) {
    if (c == v[i]) {
      return true;
    }
  }
  return false;
}

int main(void) {
  int l, r;
  string s;
  l = 0;
  r = s.length() - 1;
  while (s[l] != 'A') {
    ++l;
  }
  while (s[r] != 'Z') {
    --r;
  }
  cout << (r - l + 1) << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define INFLL (1ll << 60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

ll sq(ll x) { return x * x; }

void mul_mod(ll &a, ll b) {
  a *= b;
  a %= MOD;
}

bool isvowel(char c) {
  int i;
  string v = "aeiou";
  for (i = (v.size() - 1); i >= 0; --i) {
    if (c == v[i]) {
      return true;
    }
  }
  return false;
}

int main(void) {
  int l, r;
  string s;
  cin >> s;
  l = 0;
  r = s.length() - 1;
  while (s[l] != 'A') {
    ++l;
  }
  while (s[r] != 'Z') {
    --r;
  }
  cout << (r - l + 1) << endl;
  return 0;
}
Problem p03814 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL << 29;
const ll mod = 1e9 + 7;
#define rep(i, n) for (int(i) = 0; (i) < (ll)(n); ++(i))
#define repd(i, n, d) for (ll(i) = 0; (i) < (ll)(n); (i) += (d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset((m), (v), sizeof(m))
#define chmin(x, y) (x = min(x, y))
#define chmax(x, y) (x = max(x, y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end())
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  int n = v.size();
  rep(i, n) os << v[i] << (i == n - 1 ? "" : " ");
  return os;
}

int main() {
  string s;
  int l = 0, r = s.size() - 1;
  while (s[l] != 'A')
    l++;
  while (s[r] != 'Z')
    r--;
  cout << r - l + 1 << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL << 29;
const ll mod = 1e9 + 7;
#define rep(i, n) for (int(i) = 0; (i) < (ll)(n); ++(i))
#define repd(i, n, d) for (ll(i) = 0; (i) < (ll)(n); (i) += (d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset((m), (v), sizeof(m))
#define chmin(x, y) (x = min(x, y))
#define chmax(x, y) (x = max(x, y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end())
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  int n = v.size();
  rep(i, n) os << v[i] << (i == n - 1 ? "" : " ");
  return os;
}

int main() {
  string s;
  cin >> s;
  int l = 0, r = s.size() - 1;
  while (s[l] != 'A')
    l++;
  while (s[r] != 'Z')
    r--;
  cout << r - l + 1 << endl;
  return 0;
}
Problem p03814 (C++)

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

int main() {
  string s;
  cin >> s;
  vector<int> a, z;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'A')
      a.push_back(i);
    else if (s[i] == 'Z')
      z.push_back(i);
  }
  int ans = 0;
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < z.size(); j++) {
      ans = max(ans, z[j] - a[i]);
    }
  }
  cout << ans + 1 << endl;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  cout << s.rfind('Z') - s.find('A') + 1 << endl;
  return 0;
}
Problem p03814 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  int a, z;
  a = s.find("A");
  s = s.substr(a - 1);
  z = s.find("Z") + a;
  cout << z - a + 1;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k = s.size() - 1, z = -1, a = -1;
  bool flag1 = true;
  bool flag2 = true;
  for (int i = 0; i < s.size();) {
    if (s[i] == 'A') {
      a = i;
      flag1 = false;
    }
    if (s[k] == 'Z') {
      z = k;
      flag2 = false;
    }
    if (flag1)
      i++;
    if (flag2)
      k--;
    if (flag1 == false && flag2 == false)
      break;
  }
  cout << z - a + 1;
}
Problem p03814 (C++)

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

int main() {
  string s;
  cin >> s;
  int b, e;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      b = i;
      break;
    }
  }
  for (int i = s.size() - 1; i >= 0; i++) {
    if (s[i] == 'Z') {
      e = i;
      break;
    }
  }
  cout << e - b + 1 << "\n";
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int b, e;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      b = i;
      break;
    }
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == 'Z') {
      e = i;
      break;
    }
  }
  cout << e - b + 1 << "\n";
  return 0;
}
Problem p03814 (C++)

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

int main() {
  string s;
  cin >> s;
  size_t a = s.find("A");
  size_t b = s.rfind("Z");
  cout << b - a + 1 << endl;
  return 1;
}


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

int main() {
  string s;
  cin >> s;
  size_t a = s.find("A");
  size_t b = s.rfind("Z");
  cout << b - a + 1 << endl;
  return 0;
}
Problem p03814 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a, z;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      a = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i++) {
    if (s[i] == 'Z') {
      z = i;
      break;
    }
  }
  cout << (z - a + 1) << endl;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a, z;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      a = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'Z') {
      z = i;
      break;
    }
  }
  cout << (z - a + 1) << endl;
}
Problem p03814 (C++)

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

int main() {
  string s;
  cin >> s;
  int f, t;
  rep(i, s.size()) {
    if (s[i] == 'A') {
      f = i;
      break;
    }
  }
  per(i, s.size()) {
    if (s[i] == 'Z') {
      t = i;
      break;
    }
  }

  cout << t - f + 1 << endl;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int f, t;
  rep(i, s.size()) {
    if (s[i] == 'A') {
      f = i;
      break;
    }
  }
  per(i, s.size()) {
    if (s[i] == 'Z') {
      t = i;
      break;
    }
  }

  cout << t - f + 1 << endl;
  return 0;
}
Problem p03815 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define erep(i, n) for (int i = 0; i <= n; i++)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define erep1(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

ll gcm(ll a, ll b);
ll lcm(ll a, ll b);
ll fac(ll a);

int main() {
  ll x;
  cin >> x;
  ll ans = 0;
  while (x >= 11) {
    x -= 11;
    ans += 2;
  }
  if (x >= 6) {
    x -= 6;
    ans++;
  }
  if (x >= 1) {
    x -= 5;
    ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define erep(i, n) for (int i = 0; i <= n; i++)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define erep1(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

ll gcm(ll a, ll b);
ll lcm(ll a, ll b);
ll fac(ll a);

int main() {
  ll x;
  cin >> x;
  ll ans = 0;
  ans = x / 11 * 2;
  x %= 11;
  if (x >= 6) {
    x -= 6;
    ans++;
  }
  if (x >= 1) {
    x -= 5;
    ans++;
  }
  cout << ans << endl;
}
Problem p03815 (Python)

Buggy submission (status: Runtime Error):
N, M = [int(i) for i in input().split()]
road = [list() for i in range(N + 1)]
for i in range(M):
    a, b = [int(i) for i in input().split()]
    road[a].append(b)
    road[b].append(a)


def solve(before, visited, now):
    visited.append(now)
    print(visited)
    if len(visited) is N:
        return 1
    pattern = 0
    for way in road[now]:
        if way is now:
            continue
        if way in visited:
            continue
        pattern += solve(now, visited[:], way)
    return pattern


print(solve(0, [], 1))


Fixed submission:
x = int(input())
if x < 7:
    print(1)
    exit()
elif x % 11 is 0:
    print((x // 11) * 2)
elif x % 11 < 7:
    print((x // 11) * 2 + 1)
else:
    print((x // 11) * 2 + 2)
Problem p03815 (C++)

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

long long int gcd(long long int a, long long int b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
long long int fac(long long int n) {
  if (n == 0) {
    return 1;
  } else {
    return n * (fac(n - 1)) % 1000000007;
  }
}

int main() {
  long long int n, k, ans = 0;
  for (long long int i = 0;; i++) {
    if (i % 2 == 0) {
      n -= 5;
    } else {
      n -= 6;
    }
    if (n <= 0) {
      ans = i + 1;
    }
  }
  cout << ans << endl;
  return 0;
}

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

long long int gcd(long long int a, long long int b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
long long int fac(long long int n) {
  if (n == 0) {
    return 1;
  } else {
    return n * (fac(n - 1)) % 1000000007;
  }
}

int main() {
  long long int n, k, ans = 0;
  cin >> n;
  ans += 2 * ((n - 1) / 11);
  if (n % 11 < 7 && n % 11 > 0) {
    ans++;
  } else {
    ans++;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03815 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x;
  cin >> x;
  long long ans = 0, sum = 0;
  while (true) {
    sum += 6;
    ans++;
    if (sum >= x) {
      break;
    }
    sum += 5;
    ans++;
    if (sum >= x) {
      break;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x;
  cin >> x;
  long long ans;
  if (x % 11 > 6) {
    ans = (x / 11) * 2 + 2;
  } else if (x % 11 == 0) {
    ans = (x / 11) * 2;
  } else {
    ans = (x / 11) * 2 + 1;
  }
  cout << ans << endl;
}
Problem p03815 (C++)

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

static const int INF = 1001001001;

using namespace std;

int main() {
  long long x, count;
  cin >> x;
  for (count = 0; x > 0; ++count) {
    if (count % 2 == 0) {
      x -= 6;
    } else {
      x -= 5;
    }
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

static const int INF = 1001001001;

using namespace std;

int main() {
  long long x, count;
  cin >> x;
  count = (x / 11) * 2;
  if (x % 11 > 0 && x % 11 <= 6) {
    count += 1;
  } else if (x % 11 > 6) {
    count += 2;
  }
  cout << count << endl;
  return 0;
}
Problem p03816 (C++)

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

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> checked(10005);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (checked[a] > 0) {
      ans++;
    }
    checked[a]++;
  }
  cout << n - ans - ans % 2 << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> checked(100005);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (checked[a] > 0) {
      ans++;
    }
    checked[a]++;
  }
  cout << n - ans - ans % 2 << endl;
  return 0;
}
Problem p03816 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
int n, i;
vector<int> a;
int cc[10010];
int main() {
  scanf("%d\n", &n);
  for (i = 0; i < n; i++) {
    int tmp;
    scanf("%d\n", &tmp);
    a.push_back(tmp);
  }
  sort(a.begin(), a.end());
  int tmp = a[0], c = 0, j = 0;
  for (i = 1; i < n; i++) {
    if (tmp != a[i]) {
      cc[j++] = i - c;
      tmp = a[i];
      c = i;
    }
    if (i == n - 1) {
      cc[j++] = n - c;
    }
  }
  tmp = 0;
  for (i = 0; i < j; i++) {
    if (cc[i] % 2 == 0) {
      tmp++;
    }
    //  printf("%d\n",cc[i] );
  }
  printf("%d\n", j - tmp % 2);
}


Fixed submission:
#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
int n, i;
vector<int> a;
int cc[100010];
int main() {
  scanf("%d\n", &n);
  for (i = 0; i < n; i++) {
    int tmp;
    scanf("%d\n", &tmp);
    a.push_back(tmp);
  }
  sort(a.begin(), a.end());
  int tmp = a[0], c = 0, j = 0;
  for (i = 1; i < n; i++) {
    if (tmp != a[i]) {
      cc[j++] = i - c;
      tmp = a[i];
      c = i;
    }
    if (i == n - 1) {
      cc[j++] = n - c;
    }
  }
  tmp = 0;
  for (i = 0; i < j; i++) {
    if (cc[i] % 2 == 0) {
      tmp++;
    }
    //  printf("%d\n",cc[i] );
  }
  printf("%d\n", j - tmp % 2);
}
Problem p03816 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>
// #include <unordered_map>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <climits>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <utility>

using namespace std;

#define SCD(t) scanf("%d", &t)
#define SCLD(t) scanf("%ld", &t)
#define SCLLD(t) scanf("%lld", &t)
#define SCC(t) scanf("%c", &t)
#define SCS(t) scanf("%s", t)
#define SCF(t) scanf("%f", &t)
#define SCLF(t) scanf("%lf", &t)
#define FOR(i, j, k) for (int i = j; i < k; i++)
#define RFOR(i, j, k) for (int i = j; i >= k; i--)
#define REP(i, j) FOR(i, 0, j)
#define RREP(i, j) RFOR(i, j, 0)
#define PI 3.1415926535897932384626433832795
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  int N;
  cin >> N;
  vi a(N), b(10001, 0);
  REP(i, N) {
    cin >> a[i];
    b[a[i]]++;
  }

  ll x = 0;
  REP(i, b.size()) {
    if (b[i] > 1)
      x += b[i] - 1;
  }

  ll ans = (x + 1) / 2;

  cout << N - ans * 2 << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
#include <vector>
// #include <unordered_map>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <climits>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <utility>

using namespace std;

#define SCD(t) scanf("%d", &t)
#define SCLD(t) scanf("%ld", &t)
#define SCLLD(t) scanf("%lld", &t)
#define SCC(t) scanf("%c", &t)
#define SCS(t) scanf("%s", t)
#define SCF(t) scanf("%f", &t)
#define SCLF(t) scanf("%lf", &t)
#define FOR(i, j, k) for (int i = j; i < k; i++)
#define RFOR(i, j, k) for (int i = j; i >= k; i--)
#define REP(i, j) FOR(i, 0, j)
#define RREP(i, j) RFOR(i, j, 0)
#define PI 3.1415926535897932384626433832795
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  int N;
  cin >> N;
  vi a(N), b(100001, 0);
  REP(i, N) {
    cin >> a[i];
    b[a[i]]++;
  }

  ll x = 0;
  REP(i, b.size()) {
    if (b[i] > 1)
      x += b[i] - 1;
  }

  ll ans = (x + 1) / 2;

  cout << N - ans * 2 << endl;

  return 0;
}
Problem p03816 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int A[10100];
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  sort(A, A + N);
  int count = 1;
  for (int i = 1; i < N; ++i) {
    if (A[i] != A[i - 1])
      count++;
  }
  printf("%d\n", N - (N - count + 1) / 2 * 2);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int A[101000];
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  sort(A, A + N);
  int count = 1;
  for (int i = 1; i < N; ++i) {
    if (A[i] != A[i - 1])
      count++;
  }
  printf("%d\n", N - (N - count + 1) / 2 * 2);
  return 0;
}
Problem p03816 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << endl;
#define CFYN(n) cout << ((n) ? "YES" : "NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

int main(void) {
  IOS const int N = 1e8 + 1;
  int n;
  cin >> n;
  vector<int> m(N);
  REP(i, n) {
    int x;
    cin >> x;
    m[x]++;
  }
  int cnt = 0;
  REP(i, N) if (m[i] != 0) cnt++;

  cout << (cnt % 2 == 0 ? cnt - 1 : cnt) << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << endl;
#define CFYN(n) cout << ((n) ? "YES" : "NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

int main(void) {
  IOS const int N = 1e7 + 1;
  int n;
  cin >> n;
  vector<int> m(N);
  REP(i, n) {
    int x;
    cin >> x;
    m[x]++;
  }
  int cnt = 0;
  REP(i, N) if (m[i] != 0) cnt++;

  cout << (cnt % 2 == 0 ? cnt - 1 : cnt) << endl;

  return 0;
}
Problem p03816 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x) cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9 + 7;
const ll INF = 1e18;
const int inf = 1e9;

void solve() {
  int n;
  cin >> n;
  vector<int> a(10010, 0);
  int ans = 0;
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (!a[t]) {
      a[t]++;
      ans++;
    } else {
      tmp++;
    }
  }
  cout << ans - (tmp % 2) << endl;
}

int main() {
  solve();
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x) cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9 + 7;
const ll INF = 1e18;
const int inf = 1e9;

void solve() {
  int n;
  cin >> n;
  vector<int> a(100010, 0);
  int ans = 0;
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (!a[t]) {
      a[t]++;
      ans++;
    } else {
      tmp++;
    }
  }
  cout << ans - (tmp % 2) << endl;
}

int main() {
  solve();
  return 0;
}
Problem p03816 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr                                                                    \
  getchar();                                                                   \
  getchar();                                                                   \
  return 0;
int gcd(int x, int y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }

int n, a[100010], ta, mu;

signed main() {
  cin >> n;
  vector<int> rin(n + 5);
  rep(i, n) {
    cin >> a[i];
    rin[a[i]]++;
  }
  rep(i, rin.size()) {
    if (rin[i] % 2 == 1)
      ta += rin[i] - 1;
    else if (rin[i] > 0) {
      ta += rin[i] - 2;
      mu++;
    }
  }
  if (mu % 2 == 1)
    ta += mu + 1;
  else
    ta += mu;
  cout << n - ta << endl;
  ggr
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr                                                                    \
  getchar();                                                                   \
  getchar();                                                                   \
  return 0;
int gcd(int x, int y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }

int n, a[100010], ta, mu;

signed main() {
  cin >> n;
  vector<int> rin(100010);
  rep(i, n) {
    cin >> a[i];
    rin[a[i]]++;
  }
  rep(i, rin.size()) {
    if (rin[i] % 2 == 1)
      ta += rin[i] - 1;
    else if (rin[i] > 0) {
      ta += rin[i] - 2;
      mu++;
    }
  }
  if (mu % 2 == 1)
    ta += mu + 1;
  else
    ta += mu;
  cout << n - ta << endl;
  ggr
}
Problem p03816 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
map<int, int> coun;
int a[1000], elemin = 1000000, elemax = -1;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    elemin = min(a[i], elemin);
    elemax = max(a[i], elemax);
  }
  for (int i = 1; i <= n; i++) {
    coun[a[i]]++;
  }
  for (int i = elemin; i <= elemax; i++) {
    if (coun[i] > 2) {
      if (coun[i] % 2 == 0)
        coun[i] = 2;
      else
        coun[i] = coun[i] % 2;
    }
    // cout<<i<<" "<<coun[i]<<endl;
  }
  int j = elemin;
  for (int i = elemin; i <= elemax; i++) {
    if (coun[i] == 2) {
      j = i + 1;
      while ((j <= elemax) && (coun[j] < 2)) {
        j++;
      }
      if (j > elemax)
        break;
      if (coun[j] == 2) {
        coun[i]--;
        coun[j]--;
        // cout<<i<<" "<<coun[i]<<" "<<j<<coun[j]<<endl;
      }
    }
  }
  int ans = 0;
  int res = 0;
  for (int i = elemin; i <= elemax; i++) {
    if (coun[i] == 1) {
      ans++;
      // cout<<i<<" ";
    }
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
map<int, int> coun;
int a[100002], elemin = 1000000, elemax = -1;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    elemin = min(a[i], elemin);
    elemax = max(a[i], elemax);
  }
  for (int i = 1; i <= n; i++) {
    coun[a[i]]++;
  }
  for (int i = elemin; i <= elemax; i++) {
    if (coun[i] > 2) {
      if (coun[i] % 2 == 0)
        coun[i] = 2;
      else
        coun[i] = coun[i] % 2;
    }
    // cout<<i<<" "<<coun[i]<<endl;
  }
  int j = elemin;
  for (int i = elemin; i <= elemax; i++) {
    if (coun[i] == 2) {
      j = i + 1;
      while ((j <= elemax) && (coun[j] < 2)) {
        j++;
      }
      if (j > elemax)
        break;
      if (coun[j] == 2) {
        coun[i]--;
        coun[j]--;
        // cout<<i<<" "<<coun[i]<<" "<<j<<coun[j]<<endl;
      }
    }
  }
  int ans = 0;
  int res = 0;
  for (int i = elemin; i <= elemax; i++) {
    if (coun[i] == 1) {
      ans++;
      // cout<<i<<" ";
    }
  }
  cout << ans;
}
Problem p03816 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e3 + 6;
const int mod = 1e9 + 7;
const int inf = 1e8;
int cnt[N];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += max(0, cnt[i] - 1);
  }
  if (ans % 2)
    ans++;
  cout << n - ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  //    cin>>t;
  while (t--)
    solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5 + 6;
const int mod = 1e9 + 7;
const int inf = 1e8;
int cnt[N];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += max(0, cnt[i] - 1);
  }
  if (ans % 2)
    ans++;
  cout << n - ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  //    cin>>t;
  while (t--)
    solve();
  return 0;
}
Problem p03816 (C++)

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

int number_count[100005];

int main() {
  int N, number, count = 0;
  cin >> N;
  for (int i = 0; i < 100005; i++)
    number_count[i] = 0;
  for (int i = 0; i < N; i++) {
    cin >> number;
    number_count[number]++;
  }
  int min_p = 0, max_p = 100005;
  while (min_p != max_p) {
    if (number_count[min_p] == 0 || number_count[min_p] == 1)
      min_p++;
    if (number_count[max_p] == 0 || number_count[max_p] == 1)
      max_p--;
    if (number_count[min_p] != 0 && number_count[min_p] != 1 &&
        number_count[max_p] != 0 && number_count[max_p] != 1) {
      int del_num = min(number_count[min_p], number_count[max_p]) - 1;
      number_count[min_p] -= del_num;
      number_count[max_p] -= del_num;
    }
  }
  if (number_count[min_p] != 1 && number_count[min_p] != 0) {
    if (number_count[min_p] % 2 == 0)
      number_count[min_p] = 0;
    else
      number_count[min_p] = 1;
  }
  for (int i = 0; i < 100005; i++) {
    if (number_count[i] != 0)
      count++;
  }
  cout << count << endl;
  return 0;
}

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

int number_count[100005];

int main() {
  int N, number, count = 0;
  cin >> N;
  for (int i = 0; i < 100005; i++)
    number_count[i] = 0;
  for (int i = 0; i < N; i++) {
    cin >> number;
    number_count[number]++;
  }
  int min_p = 0, max_p = 100005;
  while (min_p != max_p) {
    if (number_count[min_p] == 0 || number_count[min_p] == 1)
      min_p++;
    if (min_p == max_p)
      break;
    if (number_count[max_p] == 0 || number_count[max_p] == 1)
      max_p--;
    if (number_count[min_p] != 0 && number_count[min_p] != 1 &&
        number_count[max_p] != 0 && number_count[max_p] != 1) {
      int del_num = min(number_count[min_p], number_count[max_p]) - 1;
      number_count[min_p] -= del_num;
      number_count[max_p] -= del_num;
    }
  }
  if (number_count[min_p] != 1 && number_count[min_p] != 0) {
    if (number_count[min_p] % 2 == 0)
      number_count[min_p] = 0;
    else
      number_count[min_p] = 1;
  }
  for (int i = 0; i < 100005; i++) {
    if (number_count[i] != 0)
      count++;
  }
  cout << count << endl;
  return 0;
}
Problem p03816 (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++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }
  sort(A.begin(), A.end());
  vector<pair<int, int>> B;
  B.push_back(make_pair(A[0], 1));
  rep(i, N - 1) {
    if (B.back().first == A[i + 1])
      B.back().second++;
    else
      B.push_back(make_pair(A[i + 1], 1));
  }

  int ans = N;
  int head = 0;
  int tail = N - 1;
  for (; head < tail;) {
    if (B[head].second < 2) {
      head++;
      continue;
    }

    for (; tail > head; tail--) {
      if (B[tail].second < 2)
        continue;

      B[head].second--;
      B[tail].second--;
      ans -= 2;
      break;
    }

    if (head == tail) {
      ans -= (B[head].second / 2) * 2;
      B[head].second = 1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }
  sort(A.begin(), A.end());
  vector<pair<int, int>> B;
  B.push_back(make_pair(A[0], 1));
  rep(i, N - 1) {
    if (B.back().first == A[i + 1])
      B.back().second++;
    else
      B.push_back(make_pair(A[i + 1], 1));
  }

  int ans = N;
  int head = 0;
  int tail = B.size() - 1;
  for (; head <= tail;) {
    if (B[head].second < 2) {
      head++;
      continue;
    }

    for (; tail > head; tail--) {
      if (B[tail].second < 2)
        continue;

      B[head].second--;
      B[tail].second--;
      ans -= 2;
      break;
    }

    if (head == tail) {
      ans -= (B[head].second / 2) * 2;
      B[head].second = 1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03816 (C++)

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

int main(void) {
  // your code goes here
  int d[10000];
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", &d[i]);
  sort(d, d + N);
  int ln = -1;
  int cout = 0;
  for (int i = 0; i < N; i++) {
    if (ln != d[i]) {
      cout++;
      ln = d[i];
    }
  }
  if (cout % 2 != 0)
    printf("%d", cout);
  if (cout % 2 == 0)
    printf("%d", cout - 1);
  return 0;
}


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

int main(void) {
  // your code goes here
  int d[100000];
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", &d[i]);
  sort(d, d + N);
  int ln = -1;
  int cout = 0;
  for (int i = 0; i < N; i++) {
    if (ln != d[i]) {
      cout++;
      ln = d[i];
    }
  }
  if (cout % 2 != 0)
    printf("%d", cout);
  if (cout % 2 == 0)
    printf("%d", cout - 1);
  return 0;
}
Problem p03816 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int n, p, m = 0, e = 0, l;
  cin >> n;
  l = n;
  int a[10000] = {0};
  while (n--) {
    cin >> p;
    m = max(m, p);
    a[p]++;
  }
  for (int i = 1; i <= m; i++) {
    if (a[i] > 1)
      e += a[i] - 1;
  }
  if (e % 2 == 1)
    cout << l - e - 1 << endl;
  else
    cout << l - e << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int n, p, m = 0, e = 0, l;
  cin >> n;
  l = n;
  int a[1000000] = {0};
  while (n--) {
    cin >> p;
    m = max(m, p);
    a[p]++;
  }
  for (int i = 1; i <= m; i++) {
    if (a[i] > 1)
      e += a[i] - 1;
  }
  if (e % 2 == 1)
    cout << l - e - 1 << endl;
  else
    cout << l - e << endl;
}
Problem p03816 (C++)

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

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> n_num(*max_element(a.begin(), a.end()), 0);
  int n_even = 0, n_odd = 0;
  for (int i = 0; i < n_num.size(); i++) {
    n_num[a[i] - 1]++;
  }
  for (int i = 0; i < n_num.size(); i++) {
    if (n_num[i] % 2 == 0) {
      if (n_num[i] != 0)
        n_even++;
    } else
      n_odd++;
  }
  cout << n_odd + n_even - (n_even % 2) << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> n_num(*max_element(a.begin(), a.end()), 0);
  int n_even = 0, n_odd = 0;
  for (int i = 0; i < n; i++) {
    n_num[a[i] - 1]++;
  }
  for (int i = 0; i < n_num.size(); i++) {
    if (n_num[i] % 2 == 0) {
      if (n_num[i] != 0)
        n_even++;
    } else
      n_odd++;
  }
  cout << n_odd + n_even - (n_even % 2) << endl;
  return 0;
}
Problem p03816 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
const static int MAX_A = 10000;
unsigned Bucket[MAX_A];

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    unsigned tmp;
    scanf("%u", &tmp);
    Bucket[tmp - 1]++;
  }
  unsigned answer = 0;
  bool even = false;
  for (int i = 0; i < MAX_A; ++i) {
    if (Bucket[i]) {
      answer++;
      if (!(Bucket[i] & 1))
        even ^= true;
    }
  }
  if (even)
    answer--;
  printf("%u\n", answer);
  return 0;
}

Fixed submission:
#include <cstdio>
const static int MAX_A = 100000;
unsigned Bucket[MAX_A];

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    unsigned tmp;
    scanf("%u", &tmp);
    Bucket[tmp - 1]++;
  }
  unsigned answer = 0;
  bool even = false;
  for (int i = 0; i < MAX_A; ++i) {
    if (Bucket[i]) {
      answer++;
      if (!(Bucket[i] & 1))
        even ^= true;
    }
  }
  if (even)
    answer--;
  printf("%u\n", answer);
  return 0;
}
Problem p03816 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, a[10005], sum = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1]) {
      sum++;
    }
  }
  if (sum % 2 != 0) {
    sum++;
  }
  cout << n - sum;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, a[100005], sum = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1]) {
      sum++;
    }
  }
  if (sum % 2 != 0) {
    sum++;
  }
  cout << n - sum;
  return 0;
}