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

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

int MOD = 998244353;

int main(void) {

  int N;
  cin >> N;

  int a[N];
  int sum = 0;
  long long all = 1;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
    all = (3 * all) % MOD;
  }

  long long dp1[N + 1][sum + 1], dp2[N + 1][sum + 1];
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));
  dp1[0][0] = dp2[0][0] = 1;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= sum; j++) {
      if (a[i] <= j) {
        dp1[i + 1][j] = (dp1[i][j - a[i]] + 2 * dp1[i][j]) % MOD;
        dp2[i + 1][j] = (dp2[i][j - a[i]] + dp2[i][j]) % MOD;
      } else {
        dp1[i + 1][j] = 2 * dp1[i][j] % MOD;
        dp2[i + 1][j] = dp2[i][j] % MOD;
      }
    }
  }

  long long p1 = 0;
  for (int i = (sum + 1) / 2; i <= sum; i++) {
    p1 = (p1 + dp1[N][i]) % MOD;
  }

  long long p2 = 0;
  if (sum % 2 == 0) {
    p2 = dp2[N][sum / 2] % MOD;
  }

  long long ans = (all - 3 * p1 + 3 * p2) % MOD;

  while (ans < 0) {
    ans += MOD;
  }

  cout << ans << endl;
}

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

int MOD = 998244353;

int main(void) {

  int N;
  cin >> N;

  int a[N];
  int sum = 0;
  long long all = 1;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
    all = (3 * all) % MOD;
  }

  vector<vector<long long>> dp1(N + 1, vector<long long>(sum + 1, 0)),
      dp2(N + 1, vector<long long>(sum + 1, 0));
  dp1[0][0] = dp2[0][0] = 1;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= sum; j++) {
      if (a[i] <= j) {
        dp1[i + 1][j] = (dp1[i][j - a[i]] + 2 * dp1[i][j]) % MOD;
        dp2[i + 1][j] = (dp2[i][j - a[i]] + dp2[i][j]) % MOD;
      } else {
        dp1[i + 1][j] = 2 * dp1[i][j] % MOD;
        dp2[i + 1][j] = dp2[i][j] % MOD;
      }
    }
  }

  long long p1 = 0;
  for (int i = (sum + 1) / 2; i <= sum; i++) {
    p1 = (p1 + dp1[N][i]) % MOD;
  }

  long long p2 = 0;
  if (sum % 2 == 0) {
    p2 = dp2[N][sum / 2] % MOD;
  }

  long long ans = (all - 3 * p1 + 3 * p2) % MOD;

  while (ans < 0) {
    ans += MOD;
  }

  cout << ans << endl;
}
Problem p03071 (C++)

Buggy submission (status: Runtime Error):
/*author: hyperion_1724
  date:
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("INPUT.txt", "r", stdin);
  // freopen ("OUTPUT.txt" , "w" , stdout);
#endif

  int A, B;
  cin >> A >> B;
  int ans = 0;
  if (A > B) {
    ans = ans + A;
    A--;
  } else {
    ans = ans + B;
    B--;
  }
  if (A > B) {
    ans = ans + A;
    A--;
  } else {
    ans = ans + B;
    B--;
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
/*author: hyperion_1724
  date:
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int A, B;
  cin >> A >> B;
  int ans = 0;
  if (A > B) {
    ans = ans + A;
    A--;
  } else {
    ans = ans + B;
    B--;
  }
  if (A > B) {
    ans = ans + A;
    A--;
  } else {
    ans = ans + B;
    B--;
  }
  cout << ans << endl;

  return 0;
}
Problem p03071 (C++)

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

#define int long long
#define ll long long
#define f1(i, a, b) for (i = a; i < b; i++)
#define f2(i, a, b) for (i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod = 1000000007;
int i, j;
ll temp;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int a, b;
  cin >> a >> b;
  int ans = a + b;
  if (2 * a - 1 > ans)
    ans = 2 * a - 1;
  if (2 * b - 1 > ans)
    ans = 2 * b - 1;
  cout << ans;
  return 0;
}

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

#define int long long
#define ll long long
#define f1(i, a, b) for (i = a; i < b; i++)
#define f2(i, a, b) for (i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod = 1000000007;
int i, j;
ll temp;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // #ifndef ONLINE_JUDGE
  // 	freopen("in.txt","r",stdin);
  // 	freopen("out.txt","w",stdout);
  // #endif
  int a, b;
  cin >> a >> b;
  int ans = a + b;
  if (2 * a - 1 > ans)
    ans = 2 * a - 1;
  if (2 * b - 1 > ans)
    ans = 2 * b - 1;
  cout << ans;
  return 0;
}
Problem p03071 (C++)

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

int main() {
  int a;
  cin >> a;
  int b;
  cin >> b;
  if (a == b)
    return cout << a + b, 0;
  return (max(a, b) * 2) - 1;
}

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

int main() {
  int a;
  cin >> a;
  int b;
  cin >> b;
  if (a == b)
    return cout << a + b, 0;
  cout << (max(a, b) * 2) - 1;
}
Problem p03071 (C++)

Buggy submission (status: Runtime Error):
/****************************************************
 *   Template for coding contests                    *
 *   Author    :    Sanjeev Sharma                   *
 *   Email     :    thedevelopersanjeev@gmail.com    *
 *****************************************************/
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int a, b;
  cin >> a >> b;
  cout << max({(2 * a) - 1, (2 * b) - 1, a + b});
  return 0;
}


Fixed submission:
/****************************************************
 *   Template for coding contests                    *
 *   Author    :    Sanjeev Sharma                   *
 *   Email     :    thedevelopersanjeev@gmail.com    *
 *****************************************************/
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a, b;
  cin >> a >> b;
  cout << max({(2 * a) - 1, (2 * b) - 1, a + b});
  return 0;
}
Problem p03071 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input().split())

if a >= b:
    tmp1 = a
    a -= 1
else:
    tmp2 = b
    b -= 1

if a >= b:
    tmp2 = a
else:
    tmp2 = b

print(tmp1 + tmp2)


Fixed submission:
a, b = map(int, input().split())

if a >= b:
    tmp1 = a
    a -= 1
else:
    tmp1 = b
    b -= 1

if a >= b:
    tmp2 = a
else:
    tmp2 = b

print(tmp1 + tmp2)
Problem p03071 (Python)

Buggy submission (status: Runtime Error):
A = input()
B = input()

A = int(A)
B = int(B)

if A > B:
    X = A
    A = A - 1

else:
    X = B
    B = B - 1

if A > B:
    X = X + A
else:
    X = X + B

print(X)


Fixed submission:
A, B = input().split(" ")

A = int(A)
B = int(B)

if A > B:
    X = A
    A = A - 1

else:
    X = B
    B = B - 1

if A > B:
    X = X + A
else:
    X = X + B

print(X)
Problem p03071 (C++)

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

#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
#define speed                                                                  \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);

int const N = 2 * 1e5 + 2;
int a[N], cnt[101], ans;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  speed int a, b;
  cin >> a >> b;
  if (a == b)
    return cout << a + b, 0;
  int mx = max(a, b);
  cout << mx * 2 - 1 << endl;
}

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

#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
#define speed                                                                  \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);

int const N = 2 * 1e5 + 2;
int a[N], cnt[101], ans;

int main() {
  speed int a, b;
  cin >> a >> b;
  if (a == b)
    return cout << a + b, 0;
  int mx = max(a, b);
  cout << mx * 2 - 1 << endl;
}
Problem p03072 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("inputf.txt", "r", stdin);
  // for writing output to output.txt
  freopen("outputf.txt", "w", stdout);
#endif
  std::ios::sync_with_stdio(false);
  // cin.ignore(); must be there when using getline(cin, s)
  int n, m = 0, d, ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> d;
    m = max(d, m);
    if (m == d)
      ans++;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  // cin.ignore(); must be there when using getline(cin, s)
  int n, m = 0, d, ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> d;
    m = max(d, m);
    if (m == d)
      ans++;
  }
  cout << ans;
}
Problem p03072 (C++)

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

int main() {
  int N;
  vector<int> H(N);

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

  int M = H[0];
  int count = 0;

  for (int i = 0; i < N; i++) {
    if (H[i] >= M) {
      count++;
    }
    M = max(M, H[i]);
  }

  cout << count << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);

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

  int M = H[0];
  int count = 0;

  for (int i = 0; i < N; i++) {
    if (H[i] >= M) {
      count++;
    }
    M = max(M, H[i]);
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
// const ll INF = 1LL<<60;
const long long INF = 1LL << 60; // 仮想的な無限大の値

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

  vector<ll> H(N);
  rep(i, N) cin >> H[i];

  vector<ll> S(N, 0);
  rep(i, N) S[i + 1] = max(S[i], H[i]);

  ll ans = 0;
  rep(i, N) if (H[i] >= S[i + 1]) ans++;

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

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
// const ll INF = 1LL<<60;
const long long INF = 1LL << 60; // 仮想的な無限大の値

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

  vector<ll> H(N);
  rep(i, N) cin >> H[i];

  vector<ll> S(N + 1, 0);
  rep(i, N) S[i + 1] = max(S[i], H[i]);

  ll ans = 0;
  rep(i, N) if (H[i] >= S[i + 1]) ans++;

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

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
#define MOD 1e9 + 7

int main() {
  int N;
  int M = -1;
  int ans = 0;
  cin >> N;
  int i = 0;
  while (i < N) {
    int H;
    cin >> H;
    if (H >= M)
      ans++;
    M = max(M, H);
  }
  cout << ans << endl;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
#define MOD 1e9 + 7

int main() {
  int N;
  int M = -1;
  int ans = 0;
  cin >> N;
  int i = 0;
  while (i < N) {
    int H;
    cin >> H;
    if (H >= M)
      ans++;
    M = max(M, H);
    i++;
  }
  cout << ans << endl;
}
Problem p03072 (C++)

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

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

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

  int count = 0;

  for (int i = 1; i < N; i++) {
    bool flg = true;

    for (int j = 0; j < i; j++) {
      if (H.at(i) < H.at(j)) {
        flg = false;
      }
    }

    if (flg)
      count++;
  }
  cout << count + 1 << endl;
}

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

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

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

  int count = 0;

  for (int i = 1; i < N; i++) {
    bool flg = true;

    for (int j = 0; j < i; j++) {
      if (H.at(i) < H.at(j)) {
        flg = false;
      }
    }

    if (flg)
      count++;
  }
  cout << count + 1 << endl;
}
Problem p03072 (C++)

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

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

  int count = 1;
  int maxH = H.at(1);
  for (int i = 1; i < N; i++) {
    if (maxH <= H.at(i)) {
      count++;
      maxH = H.at(i);
    }
  }

  cout << count << endl;
}

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

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

  int count = 1;
  int maxH = H.at(0);
  for (int i = 1; i < N; i++) {
    if (maxH <= H.at(i)) {
      count++;
      maxH = H.at(i);
    }
  }

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

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

int main() {

  int n, i, h[i];
  cin >> n;

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

  int count = 0, max = h[0];

  for (i = 1; i < n; i++) {
    if (h[i] >= max) {
      count++;
      max = h[i];
    }
  }

  cout << count + 1 << endl;
}


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

int main() {

  int n, i, h[25];
  cin >> n;

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

  int count = 0, max = h[0];

  for (i = 1; i < n; i++) {
    if (h[i] >= max) {
      count++;
      max = h[i];
    }
  }

  cout << count + 1 << endl;
}
Problem p03072 (C++)

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

using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int m = 0;
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    int H;
    scanf("%d", &H);
    if (i == 0) {
      ++cnt;
      m = H;
      continue;
    }
    if (H >= m) {
      ++cnt;
      m = H;
    }
  }
  printf("%d", cnt);
  fflush(stdout);
  return cnt;
}


Fixed submission:
#include <cstdio>

using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int m = 0;
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    int H;
    scanf("%d", &H);
    if (i == 0) {
      ++cnt;
      m = H;
      continue;
    }
    if (H >= m) {
      ++cnt;
      m = H;
    }
  }
  printf("%d", cnt);
  fflush(stdout);
  return 0;
}
Problem p03072 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int MAX = A[0];
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (MAX < A[i])
      MAX = A[i];
    if (MAX <= A[i])
      cnt++;
  }
  cout << cnt << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int MAX = A[0];
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (MAX < A[i])
      MAX = A[i];
    if (MAX <= A[i])
      cnt++;
  }
  cout << cnt << endl;
}
Problem p03072 (C++)

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  vector<int> J;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  if (N == 1) {
    cout << 1 << endl;
  } else {
    int max_height = 0;

    for (int i = 0; i < N; i++) {
      max_height = max(H[i], max_height);
      J[i] = max_height;
    }
    int cnt = 1;
    for (int j = 1; j < N; j++) {
      if (J[j - 1] <= H[j]) {
        cnt++;
      }
    }

    cout << cnt << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> H(N, 0);
  vector<int> J(N - 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  if (N == 1) {
    cout << 1 << endl;
  } else {
    int max_height = 0;

    for (int i = 0; i < N; i++) {
      max_height = max(H[i], max_height);
      J[i] = max_height;
    }
    int cnt = 1;
    for (int j = 1; j < N; j++) {
      if (J[j - 1] <= H[j]) {
        cnt++;
      }
    }

    cout << cnt << endl;
  }
  return 0;
}
Problem p03072 (Python)

Buggy submission (status: Runtime Error):
def solve(string):
    n, *h = map(int, string.split())
    count = 1
    for i in range(1, n):
        if max(h[:i]) <= h[i]:
            count += 1
    return str(count)


if __name__ == "__main__":
    print(solve(input()))


Fixed submission:
def solve(string):
    n, *h = map(int, string.split())
    count = 1
    for i in range(1, n):
        if max(h[:i]) <= h[i]:
            count += 1
    return str(count)


if __name__ == "__main__":
    print(solve("\n".join([input(), input()])))
Problem p03072 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
h = [int(x) for x in input().split()]
c = 0
for i in range(n):
    if h[i] >= max(h[:i]):
        c += 1
print(c)


Fixed submission:
n = int(input())
h = [int(x) for x in input().split()]
c = 1

for i in range(1, n):
    if h[i] >= max(h[:i]):
        c += 1
print(c)
Problem p03072 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
h = map(int, input().split())
total = 1
max_value = h[0]
for i in range(1, n):
    if max_value <= h[i]:
        total += 1
    max_value = max(max_value, h[i])
print(total)


Fixed submission:
n = int(input())
h = list(map(int, input().split()))
total = 1
max_value = h[0]
for i in range(1, n):
    if max_value <= h[i]:
        total += 1
    max_value = max(max_value, h[i])
print(total)
Problem p03072 (C++)

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

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

using namespace std;

int main() {
  int n;
  vector<int> h(n);
  cin >> n;
  rep(i, n) { cin >> h[i]; }
  int max = 0, cnt = 0;
  rep(i, n) {
    if (h[i] >= max) {
      cnt++;
      max = h[i];
    }
  }
  cout << cnt << endl;
}


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

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

using namespace std;

int main() {
  int n;
  int h[20];
  cin >> n;
  rep(i, n) { cin >> h[i]; }
  int max = 0, cnt = 0;
  rep(i, n) {
    if (h[i] >= max) {
      cnt++;
      max = h[i];
    }
  }
  cout << cnt << endl;
}
Problem p03072 (C++)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define per(i, n) for (int i = n - 1; i >= 0; --i)
#define sc1(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d %d", &a, &b)
#define sc3(a, b, c) scanf("%d %d %d", &a, &b, &c)

int main() {
  int n, m = 0, ans = 0;
  int h[n];
  sc1(n);
  rep(i, n) sc1(h[i]);
  rep(i, n) {
    if (h[i] >= m) {
      m = h[i];
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define per(i, n) for (int i = n - 1; i >= 0; --i)
#define sc1(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d %d", &a, &b)
#define sc3(a, b, c) scanf("%d %d %d", &a, &b, &c)

int main() {
  int n, m = 0, ans = 0;
  int h[25];
  sc1(n);
  rep(i, n) sc1(h[i]);
  rep(i, n) {
    if (h[i] >= m) {
      m = h[i];
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03072 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define All(x) (x).begin(), (x).end()
using namespace std;
using pii = pair<int, int>;
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
  int a, b[100000009], ma, c;
  ma = c = 0;
  cin >> a;
  rep(i, a) {
    cin >> b[i];
    if (b[i] >= ma) {
      ma = b[i];
      c++;
    }
  }
  cout << c << endl;
}


Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define All(x) (x).begin(), (x).end()
using namespace std;
using pii = pair<int, int>;
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
  int a, b[1009], ma, c;
  ma = c = 0;
  cin >> a;
  rep(i, a) {
    cin >> b[i];
    if (b[i] >= ma) {
      ma = b[i];
      c++;
    }
  }
  cout << c << endl;
}
Problem p03073 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int i = stoi(s, 0, 2);
  cerr << hex << i;
  int sum1 = (i & 0x55555555) + ((i >> 1) & 0x55555555);
  sum1 = (sum1 & 0x33333333) + ((sum1 >> 2) & 0x33333333);
  sum1 = (sum1 & 0x0f0f0f0f) + ((sum1 >> 4) & 0x0f0f0f0f);
  sum1 = (sum1 & 0x00ff00ff) + ((sum1 >> 8) & 0x00ff00ff);
  sum1 = (sum1 & 0x0000ffff) + (sum1 >> 16);

  cout << min(sum1, int(s.length()) - sum1);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length(), cnt = 0;
  for (int i = 0; i < n; i++)
    if (s[i] - '0' == i % 2)
      cnt++;
  cout << min(cnt, n - cnt);
  return 0;
}
Problem p03073 (C++)

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int N = S.length();
  int ans01 = 0;
  int ans10 = 0;
  int ans;
  string S01, S10;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      S01[i] = '0';
      S10[i] = '1';
    } else {
      S01[i] = '1';
      S10[i] = '0';
    }
  }
  for (int i = 0; i < N; i++) {
    if (S[i] != S01[i]) {
      ans01++;
    }
    if (S[i] != S10[i]) {
      ans10++;
    }
  }
  ans = min(ans01, ans10);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int N = S.length();
  int ans01 = 0;
  int ans10 = 0;
  int ans;
  char S01[N], S10[N];
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      S01[i] = '0';
      S10[i] = '1';
    } else {
      S01[i] = '1';
      S10[i] = '0';
    }
  }
  for (int i = 0; i < N; i++) {
    if (S[i] != S01[i]) {
      ans01++;
    }
    if (S[i] != S10[i]) {
      ans10++;
    }
  }
  ans = min(ans01, ans10);
  cout << ans << endl;
  return 0;
}
Problem p03073 (C++)

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

int main() {
  int n, cnt = 0, cnt1 = 0;
  string s, s1;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0 && s[i] == '0')
      cnt++;
    else if (i % 2 && s[i] == '1')
      cnt++;
    if (i % 2 == 0 && s[i] == '1')
      cnt1++;
    else if (i % 2 && s[i] == '0')
      cnt1++;
  }

  cout << min(cnt, cnt1) << endl;

  return 0;
}


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

int main() {
  int cnt = 0, cnt1 = 0;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0 && s[i] == '0')
      cnt++;
    else if (i % 2 && s[i] == '1')
      cnt++;
    if (i % 2 == 0 && s[i] == '1')
      cnt1++;
    else if (i % 2 && s[i] == '0')
      cnt1++;
  }

  cout << min(cnt, cnt1) << endl;

  return 0;
}
Problem p03073 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define register rg
#define file(a)                                                                \
  freopen(a ".in", "r", stdin);                                                \
  freopen(a ".out", "w", stdout)
using namespace std;
typedef long long ll;
char a[10];
int main() {
  cin >> a;
  int c = 0, ans = 0, ans1 = 0;
  for (int i = 0; i < strlen(a); i++) {
    if (a[i] - '0' != c)
      ans++;
    c ^= 1;
  }
  c = 1;
  for (int i = 0; i < strlen(a); i++) {
    if (a[i] - '0' != c)
      ans1++;
    c ^= 1;
  }
  printf("%lld\n", min(ans1, ans));
  // file("a");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define register rg
#define file(a)                                                                \
  freopen(a ".in", "r", stdin);                                                \
  freopen(a ".out", "w", stdout)
using namespace std;
typedef long long ll;
char a[1000001];
int main() {
  cin >> a;
  int c = 0, ans = 0, ans1 = 0;
  for (int i = 0; i < strlen(a); i++) {
    if (a[i] - '0' != c)
      ans++;
    c ^= 1;
  }
  c = 1;
  for (int i = 0; i < strlen(a); i++) {
    if (a[i] - '0' != c)
      ans1++;
    c ^= 1;
  }
  printf("%lld\n", min(ans1, ans));
  // file("a");
  return 0;
}
Problem p03073 (C++)

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

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

  int n = s.size();

  int c1 = 0;
  for (int i = 0; i < n - 1; i++) {
    if (s.at(i) == s.at(i + 1)) {
      c1++;
      if (s.at(i) == '0') {
        s.at(i + 1) = '1';
      } else {
        s.at(i + 1) = '0';
      }
    }
  }

  int c2 = 0;
  for (int i = 0; i < n - 1; i++) {
    if (t.at(n - 1 - i) == t.at(n - 1 - i - 1)) {
      c2++;
      if (t.at(n - 1 - i) == '0') {
        t.at(n - 1 - i - 1) = '1';
      } else {
        t.at(n - 1 - i - 1) = '0';
      }
    }
  }
  cout << min(c1, c2) << endl;
}


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

int main() {
  string s, t;
  cin >> s;
  t = s;

  int n = s.size();

  int c1 = 0;
  for (int i = 0; i < n - 1; i++) {
    if (s.at(i) == s.at(i + 1)) {
      c1++;
      if (s.at(i) == '0') {
        s.at(i + 1) = '1';
      } else {
        s.at(i + 1) = '0';
      }
    }
  }

  int c2 = 0;
  for (int i = 0; i < n - 1; i++) {
    if (t.at(n - 1 - i) == t.at(n - 1 - i - 1)) {
      c2++;
      if (t.at(n - 1 - i) == '0') {
        t.at(n - 1 - i - 1) = '1';
      } else {
        t.at(n - 1 - i - 1) = '0';
      }
    }
  }
  cout << min(c1, c2) << endl;
}
Problem p03073 (C++)

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int num = stoi(S);
  bitset<100000> A(S), P1(0), P2(0);
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0) {
      P1.set(i);
    }
  }
  P2 = ~P1;
  for (int i = S.size(); i < 100000; i++) {
    P2.reset(i);
  }
  P1 ^= A;
  P2 ^= A;
  // cout << A << endl;
  // cout << P2 << endl;
  cout << min(P1.count(), P2.count()) << endl;

  return 0;
}


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

using namespace std;

int main() {
  string S;
  cin >> S;
  // int num = stoi(S);
  bitset<100000> A(S), P1(0), P2(0);
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0) {
      P1.set(i);
    }
  }
  P2 = ~P1;
  for (int i = S.size(); i < 100000; i++) {
    P2.reset(i);
  }
  P1 ^= A;
  P2 ^= A;
  // cout << A << endl;
  // cout << P2 << endl;
  cout << min(P1.count(), P2.count()) << endl;

  return 0;
}
Problem p03073 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>
int main() {
  char a[10005];
  int k = 0;
  scanf("%s", a);
  if (strlen(a) == 1) {
    printf("0");
    return 0;
  }
  for (int i = 0; i < strlen(a); i++) {
    if (a[i] == '0' && a[i + 1] == '0') {
      a[i + 1] = '1';
      k++;
    }
    if (a[i] == '1' && a[i + 1] == '1') {
      a[i + 1] = '0';
      k++;
    }
  }
  printf("%d", k);
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>
int main() {
  char a[100005];
  int k = 0;
  scanf("%s", a);
  if (strlen(a) == 1) {
    printf("0");
    return 0;
  }
  for (int i = 0; i < strlen(a); i++) {
    if (a[i] == '0' && a[i + 1] == '0') {
      a[i + 1] = '1';
      k++;
    }
    if (a[i] == '1' && a[i + 1] == '1') {
      a[i + 1] = '0';
      k++;
    }
  }
  printf("%d", k);
  return 0;
}
Problem p03073 (C++)

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

using namespace std;

int main() {
  const int MAX_N = 100000;
  char s[MAX_N];
  for (int i = 0; i < MAX_N; i++)
    s[i] = '2';
  cin >> s;
  int n = 0;
  for (int i = 0; i >= 0; i++) {
    if (s[i] != '2')
      n++;
    else
      break;
  }
  n = n - 1; // 文字数 配列は文字数-1がMAX

  int ans = 0;

  for (int i = 1; i < n; i++) {
    if (s[i - 1] == s[i]) {
      if (s[i] == '0')
        s[i] = '1';
      else if (s[i] == '1')
        s[i] = '0';
      ans++;
    }
  }

  cout << ans;
}

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

using namespace std;

int main() {
  const int MAX_N = 1000000;
  char s[MAX_N];
  for (int i = 0; i < MAX_N; i++)
    s[i] = '2';
  cin >> s;
  int n = 0;
  for (int i = 0; i >= 0; i++) {
    if (s[i] != '2')
      n++;
    else
      break;
  }
  n = n - 1; // 文字数 配列は文字数-1がMAX

  int ans = 0;

  for (int i = 1; i < n; i++) {
    if (s[i - 1] == s[i]) {
      if (s[i] == '0')
        s[i] = '1';
      else if (s[i] == '1')
        s[i] = '0';
      ans++;
    }
  }

  cout << ans;
}
Problem p03073 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int n, i, j, count1 = 0, count2 = 0;
  char a[10000];
  cin >> a;
  for (j = 0; j < strlen(a); j++) {
    if (j % 2 == 1) {
      if (a[j] == '1')
        count1++;
    } else {
      if (a[j] == '0')
        count1++;
    }
  }
  for (j = 0; j < strlen(a); j++) {
    if (j % 2 == 1) {
      if (a[j] == '0')
        count2++;
    } else {
      if (a[j] == '1')
        count2++;
    }
  }
  if (count1 > count2)
    cout << count2;
  else
    cout << count1;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int n, i, j, count1 = 0, count2 = 0;
  char a[100020];
  cin >> a;
  for (j = 0; j < strlen(a); j++) {
    if (j % 2 == 1) {
      if (a[j] == '1')
        count1++;
    } else {
      if (a[j] == '0')
        count1++;
    }
  }
  for (j = 0; j < strlen(a); j++) {
    if (j % 2 == 1) {
      if (a[j] == '0')
        count2++;
    } else {
      if (a[j] == '1')
        count2++;
    }
  }
  if (count1 > count2)
    cout << count2;
  else
    cout << count1;
  return 0;
}
Problem p03073 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>
int main() {
  int i = 0, d = 0, n = 0, n2;
  char s[10001];
  scanf("%s", s);
  n2 = strlen(s);
  for (i = 0; i < n2; i++) {
    if (s[i] == '0')
      if (s[i + 1] == '0') {
        s[i + 1] = '1';
        n++;
      }
    if (s[i] == '1')
      if (s[i + 1] == '1') {
        n++;
        s[i + 1] = '0';
      }
  }
  printf("%d", n);
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>
int main() {
  int i = 0, n = 0, n2;
  char s[100001];
  scanf("%s", s);
  n2 = strlen(s);
  for (i = 0; i < n2; i++) {
    if (s[i] == '0')
      if (s[i + 1] == '0') {
        s[i + 1] = '1';
        n++;
      }
    if (s[i] == '1')
      if (s[i + 1] == '1') {
        n++;
        s[i + 1] = '0';
      }
  }
  printf("%d", n);
  return 0;
}
Problem p03073 (C++)

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

int main() {

  int numN = 0, numT = 0, ans;
  string S, N, T;
  cin >> S;

  for (int i = 0; i < S.size(); i++) {
    if (i % 2) {
      N[i] = '0';
    } else {
      N[i] = '1';
    }
  }
  for (int i = 0; i < S.size(); i++) {
    if (!(i % 2)) {
      T[i] = '0';
    } else {
      T[i] = '1';
    }
  }

  for (int i = 0; i < S.size(); i++) {
    if (S[i] != N[i])
      numN++;
    if (S[i] != T[i])
      numT++;
  }

  ans = min(numN, numT);

  cout << ans << endl;

  return 0;
}


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

int main() {

  int numN = 0, numT = 0, ans;
  string S, N, T;
  cin >> S;
  N = S;
  T = S;

  for (int i = 0; i < S.size(); i++) {
    if (i % 2) {
      N[i] = '0';
    } else {
      N[i] = '1';
    }
  }
  for (int i = 0; i < S.size(); i++) {
    if (!(i % 2)) {
      T[i] = '0';
    } else {
      T[i] = '1';
    }
  }

  for (int i = 0; i < S.size(); i++) {
    if (S[i] != N[i])
      numN++;
    if (S[i] != T[i])
      numT++;
  }

  ans = min(numN, numT);

  cout << ans << endl;

  return 0;
}
Problem p03073 (Python)

Buggy submission (status: Runtime Error):
t1 = ["0", "1"] * 25000
t2 = ["1", "0"] * 25000

s = input()
sl = list(s)

a1 = 0
a2 = 0

for i in range(len(sl)):
    if sl[i] != t1[i]:
        a1 += 1
    if sl[i] != t2[i]:
        a2 += 1

print(min(a1, a2))


Fixed submission:
t1 = ["0", "1"] * 50000
t2 = ["1", "0"] * 50000

s = input()
sl = list(s)

a1 = 0
a2 = 0

for i in range(len(sl)):
    if sl[i] != t1[i]:
        a1 += 1
    if sl[i] != t2[i]:
        a2 += 1

print(min(a1, a2))
Problem p03073 (C++)

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

int main() {
  char s[10005];
  cin >> s;

  int ans1 = 0, ans2 = 0;
  int n;
  for (int i = 0; i < strlen(s); ++i) {
    if (s[i] == '1')
      n = 1;
    else
      n = 0;

    if (n == i % 2)
      ans1++;
    else
      ans2++;
  }

  cout << min(ans1, ans2) << endl;

  return 0;
}

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

int main() {
  char s[100005];
  cin >> s;

  int ans1 = 0, ans2 = 0;
  int n;
  for (int i = 0; i < strlen(s); ++i) {
    if (s[i] == '1')
      n = 1;
    else
      n = 0;

    if (n == i % 2)
      ans1++;
    else
      ans2++;
  }

  cout << min(ans1, ans2) << endl;

  return 0;
}
Problem p03073 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int i, ans1, ans2;
  string t1, t2;
  for (i = 0; i < s.size(); ++i) {
    if (i % 2 == 0) {
      t1.at(i) = '0';
      t2.at(i) = '1';
    }
    if (i % 2 == 1) {
      t1.at(i) = '1';
      t2.at(i) = '0';
    }
  }

  for (i = 0; i < s.size(); ++i) {
    if (t1.at(i) == s.at(i))
      ans1++;
    if (t2.at(i) == s.at(i))
      ans2++;
  }
  if (ans1 > ans2)
    cout << s.size() - ans1;
  else
    cout << s.size() - ans2;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int i, ans1, ans2;
  ans1 = 0;
  ans2 = 0;
  vector<char> t1(s.size()), t2(s.size());
  for (i = 0; i < s.size(); ++i) {
    if (i % 2 == 0) {
      t1.at(i) = '0';
      t2.at(i) = '1';
    }
    if (i % 2 == 1) {
      t1.at(i) = '1';
      t2.at(i) = '0';
    }
  }

  for (i = 0; i < s.size(); ++i) {
    if (t1.at(i) == s.at(i))
      ans1++;
    if (t2.at(i) == s.at(i))
      ans2++;
  }
  if (ans1 > ans2)
    cout << s.size() - ans1;
  else
    cout << s.size() - ans2;
  return 0;
}
Problem p03073 (C++)

Buggy submission (status: Time Limit Exceeded):
// キョウプロ.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#pragma once

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

long long A, B, C, D, M, N, X, Y, Z;
long long a[10000];
char ch;
string S;

int main() {

  cin >> S;
  M = 0;
  C = 0;
  D = 0;
  for (int i = 0; i < S.size(); i++) {

    if (M != S[i] - '0') {
      C++;
    }

    A /= 10;
    M++;
    M %= 2;
  }

  M = 1;

  for (int i = 0; i < S.size(); i++) {
    A = atoi(S.c_str());
    if (M != S[i] - '0') {
      D++;
    }
    M++;
    M %= 2;
  }

  cout << min(C, D) << endl;

  return 0;
}


Fixed submission:
// キョウプロ.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#pragma once

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

long long A, B, C, D, M, N, X, Y, Z;
long long a[10000];
char ch;
string S;

int main() {

  cin >> S;
  M = 0;
  C = 0;
  D = 0;
  for (int i = 0; i < S.size(); i++) {

    if (M != S[i] - '0') {
      C++;
    }

    A /= 10;
    M++;
    M %= 2;
  }

  M = 1;

  for (int i = 0; i < S.size(); i++) {
    if (M != S[i] - '0') {
      D++;
    }
    M++;
    M %= 2;
  }

  cout << min(C, D) << endl;

  return 0;
}
Problem p03073 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define INF 0X3f3f3f3f
const ll MAXN = 5000 + 7;
const ll MOD = 1e9 + 7;
//-------------------------------------------//
char s[MAXN];
int ans = 0;
int main() {
  scanf("%s", s);
  for (int i = 1; s[i] != '\0'; i++) {
    if (s[i] == s[i - 1]) {
      s[i] = !(s[i - 1] - '0') + '0';
      ans++;
    }
  }
  printf("%d\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define INF 0X3f3f3f3f
const ll MAXN = 300000 + 7;
const ll MOD = 1e9 + 7;
//-------------------------------------------//
char s[MAXN];
int ans = 0;
int main() {
  scanf("%s", s);
  for (int i = 1; s[i] != '\0'; i++) {
    if (s[i] == s[i - 1]) {
      s[i] = !(s[i - 1] - '0') + '0';
      ans++;
    }
  }
  printf("%d\n", ans);
}
Problem p03073 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
int main(void) {
  string color;
  char colortype[100000];
  int res1 = 0;
  int res2 = 0;
  cin >> color;
  strcpy(colortype, color.c_str());
  if (color.length() == 1) {
    cout << res1;
    exit(0);
  }
  for (int i = 1; i < color.length(); ++i) {
    if (colortype[i] == colortype[i - 1]) {
      res1++;
      if (colortype[i] == '0') {
        colortype[i] = '1';
      } else {
        colortype[i] = '0';
      }
    }
  }
  strcpy(colortype, color.c_str());
  for (int i = 1; i < color.length(); ++i) {
    if (colortype[i] == colortype[i - 1]) {
      res2++;
      if (colortype[i] == '0') {
        colortype[i] = '1';
      } else {
        colortype[i] = '0';
      }
    }
  }
  if (res1 < res2) {
    cout << res1;
  } else {
    cout << res2;
  }
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
int main(void) {
  string color;
  char colortype[1000000];
  int res1 = 0;
  int res2 = 0;
  cin >> color;
  strcpy(colortype, color.c_str());
  if (color.length() == 1) {
    cout << res1;
    exit(0);
  }
  for (int i = 1; i < color.length(); ++i) {
    if (colortype[i] == colortype[i - 1]) {
      res1++;
      if (colortype[i] == '0') {
        colortype[i] = '1';
      } else {
        colortype[i] = '0';
      }
    }
  }
  strcpy(colortype, color.c_str());
  for (int i = 1; i < color.length(); ++i) {
    if (colortype[i] == colortype[i - 1]) {
      res2++;
      if (colortype[i] == '0') {
        colortype[i] = '1';
      } else {
        colortype[i] = '0';
      }
    }
  }
  if (res1 < res2) {
    cout << res1;
  } else {
    cout << res2;
  }
}
Problem p03073 (C++)

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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;
  int len = s.size();

  string result1;
  string result2;
  for (int i = 0; i < len; i++) {
    if (i % 2 == 0) {
      result1[i] = '0';
      result2[i] = '1';
    } else {
      result1[i] = '1';
      result2[i] = '0';
    }
  }

  int count1 = 0;
  int count2 = 0;
  for (int i = 0; i < len; i++) {
    if (s[i] != result1[i]) {
      count1++;
    }
    if (s[i] != result2[i]) {
      count2++;
    }
  }

  int ans = min(count1, count2);

  cout << ans;

  return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;
  int len = s.size();

  string result1;
  string result2;
  result1.resize(len, '0');
  result2.resize(len, '0');
  for (int i = 0; i < len; i++) {
    if (i % 2 == 0) {
      result1[i] = '0';
      result2[i] = '1';
    } else {
      result1[i] = '1';
      result2[i] = '0';
    }
  }

  int count1 = 0;
  int count2 = 0;
  for (int i = 0; i < len; i++) {
    if (s[i] != result1[i]) {
      count1++;
    }
    if (s[i] != result2[i]) {
      count2++;
    }
  }

  int ans = min(count1, count2);

  cout << ans;

  return 0;
}
Problem p03073 (C++)

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

// #define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

const int MAXN = 1e5 + 1;
char s1[MAXN], s2[MAXN];

void solve() {
  string s;
  cin >> s;
  int n = (int)s.length();
  char c = 0;
  for (int i = 0; i < n; ++i) {
    s1[i] = (char)('0' + c);
    s2[i] = (char)('0' + (1 - c));
    c = 1 - c;
  }

  int n1 = 0, n2 = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != s1[i]) {
      ++n1;
    }
    if (s[i] != s2[i]) {
      ++n2;
    }
  }

  cout << min(n1, n2) << '\n';
}

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

#ifndef ONLINE_JUDGE
  FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
  clock_t time_start = clock();
#endif

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  solve();

#ifndef ONLINE_JUDGE
  fclose(FIN);
  cerr << "\x1b[031m\n-----------------\nTime="
       << (ll)((double)(clock() - time_start) / CLOCKS_PER_SEC * 1000)
       << "ms\n\x1b[0m";
#endif

  return 0;
}

//////// End Initialization ///////////////////////////////////////

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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

const int MAXN = 1e5 + 1;
char s1[MAXN], s2[MAXN];

void solve() {
  string s;
  cin >> s;
  int n = (int)s.length();
  char c = 0;
  for (int i = 0; i < n; ++i) {
    s1[i] = (char)('0' + c);
    s2[i] = (char)('0' + (1 - c));
    c = 1 - c;
  }

  int n1 = 0, n2 = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != s1[i]) {
      ++n1;
    }
    if (s[i] != s2[i]) {
      ++n2;
    }
  }

  cout << min(n1, n2) << '\n';
}

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

#ifndef ONLINE_JUDGE
  FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
  clock_t time_start = clock();
#endif

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  solve();

#ifndef ONLINE_JUDGE
  fclose(FIN);
  cerr << "\x1b[031m\n-----------------\nTime="
       << (ll)((double)(clock() - time_start) / CLOCKS_PER_SEC * 1000)
       << "ms\n\x1b[0m";
#endif

  return 0;
}

//////// End Initialization ///////////////////////////////////////
Problem p03073 (C++)

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

int comp(const void *a, const void *b) { return *(int *)a - *(int *)b; }

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

  // 初期値は大きい値
  int ans = s.size();

  // iは最初に使う色（０か１）
  for (int i = 0; i < 2; i++) {
    int cnt = 0;
    for (int j = 0; i < s.size(); j++) {
      if (j % 2 == 0 && s[i] != (char)(i + '0'))
        cnt++;
      if (j % 2 == 1 && s[j] == (char)(i + '0'))
        cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

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

int comp(const void *a, const void *b) { return *(int *)a - *(int *)b; }

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

  // 初期値は大きい値
  int ans = s.size();

  // iは最初に使う色（０か１）
  for (int i = 0; i < 2; i++) {
    int cnt = 0;
    for (int j = 0; j < s.size(); j++) {
      if ((j % 2 == 0) ^ (s[j] != (char)(i + '0')))
        cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}
Problem p03073 (C++)

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

int main(void) {
  vector<char> s(10000);
  int i, one_count, zero_count;

  i = 0;
  while ((s[i] = getchar()) != '\n') {
    i++;
  }
  s[i] = -1;

  i = 0;
  one_count = 0;
  zero_count = 0;
  while (s[i] != -1) {
    if (s[i] != (i % 2 ? '0' : '1')) {
      one_count++;
    }
    if (s[i] != (i % 2 ? '1' : '0')) {
      zero_count++;
    }
    i++;
  }

  if (one_count > zero_count)
    cout << zero_count << endl;
  else
    cout << one_count << endl;

  return 0;
}

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

int main(void) {
  vector<char> s(100000);
  int i, one_count, zero_count;

  i = 0;
  while ((s[i] = getchar()) != '\n') {
    i++;
  }
  s[i] = -1;

  i = 0;
  one_count = 0;
  zero_count = 0;
  while (s[i] != -1) {
    if (s[i] != (i % 2 ? '0' : '1')) {
      one_count++;
    }
    if (s[i] != (i % 2 ? '1' : '0')) {
      zero_count++;
    }
    i++;
  }

  if (one_count > zero_count)
    cout << zero_count << endl;
  else
    cout << one_count << endl;

  return 0;
}
Problem p03073 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> P;
constexpr ll mod = 1000000007;
int main() {
  char s[10001];
  cin >> s;
  ll i, ch = 0;
  for (i = 0; i < strlen(s); i++) {
    if ((s[i] == '1' && i % 2 == 1) || (s[i] == '0' && i % 2 == 0)) {
    } else
      ch++;
  }
  if (ch * 2 >= i)
    cout << i - ch;
  else
    cout << ch;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> P;
constexpr ll mod = 1000000007;
int main() {
  char s[100000];
  cin >> s;
  ll i, ch = 0;
  for (i = 0; i < strlen(s); i++) {
    if ((s[i] == '1' && i % 2 == 1) || (s[i] == '0' && i % 2 == 0)) {
    } else
      ch++;
  }
  if (ch * 2 >= i)
    cout << i - ch;
  else
    cout << ch;
}