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

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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

// #define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)                                                             \
  sort(v.begin(), v.end());                                                    \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  string s;
  cin >> s;

  ll n = s.size();

  while (1) {
    ll prev = s.size();
    regex e("(01)|(10)");
    s = regex_replace(s, e, "");
    if (s.size() == prev) {
      break;
    }
  }

  cout << n - s.size() << endl;

  return 0;
}


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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

// #define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)                                                             \
  sort(v.begin(), v.end());                                                    \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  string s;
  cin >> s;

  ll n = s.size();

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

  REP(i, n) {
    if (s[i - 1] == s[i]) {
      s.erase(s.begin() + i - 1, s.begin() + i + 1);
      i -= 2;
      if (i < 0) {
        i = 0;
      }
    }
  }

  cout << n - s.size() << endl;

  return 0;
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
/*
Task:
Author: John_05
State: Unknown
Lang: C++
Solution:
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 2e9 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair

int read() {
  int xx = 0, ww = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      ww = -ww;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    xx = 10 * xx + ch - 48;
    ch = getchar();
  }
  return xx * ww;
}

string str;
char s[10010];
int l, ans;

int main() {
  scanf("%s", s);
  l = strlen(s);
  str = string(s);
  for (int i = 0; i < l; i++)
    if (s[i] == '0')
      ans++;
  printf("%d\n", 2 * min(ans, l - ans));
  return 0;
}

Fixed submission:
/*
Task:
Author: John_05
State: Unknown
Lang: C++
Solution:
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 2e9 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair

int read() {
  int xx = 0, ww = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      ww = -ww;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    xx = 10 * xx + ch - 48;
    ch = getchar();
  }
  return xx * ww;
}

string str;
char s[100020];
int l, ans;

int main() {
  scanf("%s", s);
  l = strlen(s);
  str = string(s);
  for (int i = 0; i < l; i++)
    if (s[i] == '0')
      ans++;
  printf("%d\n", 2 * min(ans, l - ans));
  return 0;
}
Problem p03107 (C++)

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

int ctoi(const char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return -1;
  }
}

int main() {
  string a;
  int sum = 0;
  int flag = 0;
  vector<int> v;
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    v.push_back(ctoi(a[i]));
  }
  int length;
  length = v.size();
  while (1) {
    int tmp;
    tmp = v.at(0);
    for (int i = 0; i < v.size(); i++) {
      if (tmp != v.at(i)) {
        if (v.size() != 2) {
          v.erase(v.begin() + i - 1);
          v.erase(v.begin() + i);
          sum += 2;
          flag = 1;
          break;
        } else {
          sum += 2;
          flag = 0;
          break;
        }
      } else {
        flag = 0;
        tmp = v.at(i);
      }
    }
    if (flag == 0) {
      break;
    }
  }
  cout << sum << endl;
  return 0;
}

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

int ctoi(const char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return -1;
  }
}

int main() {
  string a;
  int sum = 0;
  int flag = 0;
  vector<int> v;
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    v.push_back(ctoi(a[i]));
  }
  int length;
  length = v.size();
  while (1) {
    int tmp;
    tmp = v.at(0);
    for (int i = 0; i < v.size(); i++) {
      if (tmp != v.at(i)) {
        if (v.size() != 2) {
          v.erase(v.begin() + i - 1);
          v.erase(v.begin() + i - 1);
          sum += 2;
          flag = 1;
          break;
        } else {
          sum += 2;
          flag = 0;
          break;
        }
      } else {
        flag = 0;
        tmp = v.at(i);
      }
    }
    if (flag == 0) {
      break;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p03107 (C++)

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

int main() {
  int a = 0, b = 0;
  scanf("%s", str);
  for (int i = 0; i < strlen(str); i++) {
    if (str[i] == '1')
      a++;
    else
      b++;
  }
  printf("%d\n", a > b ? 2 * b : 2 * a);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
char str[100005];

int main() {
  int a = 0, b = 0;
  scanf("%s", str);
  for (int i = 0; i < strlen(str); i++) {
    if (str[i] == '1')
      a++;
    else
      b++;
  }
  printf("%d\n", a > b ? 2 * b : 2 * a);
  return 0;
}
Problem p03107 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define check(v)                                                               \
  rep(i, v.size()) cout << v[i] << " ";                                        \
  cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
// オーバーフローに気をつけろよおおおおおお
// 確認忘れるなよおおおおおお

int main() {
  string s;
  cin >> s;
  int count = 0;
  bool flag = true;
  while (flag) {
    int count2 = 0;
    REP(i, 1, s.size()) {
      if (s[i] != s[i - 1]) {
        s.erase(i - 1, 2);
        count2++;
        count += 2;
      }
    }
    if (count2 == 0)
      flag = false;
  }
  cout << count << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define check(v)                                                               \
  rep(i, v.size()) cout << v[i] << " ";                                        \
  cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
// オーバーフローに気をつけろよおおおおおお
// 確認忘れるなよおおおおおお

int main() {
  string s;
  cin >> s;
  vector<int> v(2, 0);
  rep(i, s.size()) { v[s[i] - '0']++; }
  cout << min(v[0], v[1]) * 2 << endl;

  return 0;
}
Problem p03107 (C++)

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  while (!s.empty()) {
    int n = s.size();
    vector<int> v;
    for (int i = 0; i < n - 1; i++) {
      if (s[i] != s[i + 1]) {
        v.emplace_back(i++);
      }
    }
    reverse(v.begin(), v.end());
    for (auto &i : v) {
      s.erase(s.begin() + i + 1);
      s.erase(s.begin() + i);
    }
    ans += 2 * v.size();
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  int a = count(s.begin(), s.end(), '0'), b = count(s.begin(), s.end(), '1');
  cout << 2 * min(a, b) << endl;
  return 0;
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
#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 RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS string s;
  cin >> s;
  stack<char> st;
  REP(i, s.size()) {
    if (st.top() != s[i])
      st.pop();
    else
      st.push(s[i]);
  }

  OUT(s.size() - st.size())

  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 RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS string s;
  cin >> s;
  stack<char> st;
  REP(i, s.size()) {
    if (!st.empty() && st.top() != s[i])
      st.pop();
    else
      st.push(s[i]);
  }

  OUT(s.size() - st.size())

  return 0;
}
Problem p03107 (C++)

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

using namespace std;

typedef long long ll;

int main() {
  string s;
  cin >> s;
  vector<int> a;
  for (int i = 0; i < s.size(); i++) {
    a.push_back(s[i] - '0');
    while (a.size() > 1 && abs(a[a.size() - 1] - a[a.size() - 2]) > 0)
      a.erase(a.begin() + a.size() - 1), a.erase(a.begin() - 1);
  }
  cout << (int)s.size() - (int)a.size() << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
  string s;
  cin >> s;
  vector<int> a;
  for (int i = 0; i < s.size(); i++) {
    a.push_back(s[i] - '0');
    while (a.size() > 1 && abs(a[a.size() - 1] - a[a.size() - 2]) > 0)
      a.erase(a.begin() + a.size() - 1), a.erase(a.begin() + a.size() - 1);
  }
  cout << (int)s.size() - (int)a.size() << endl;
  return 0;
}
Problem p03107 (C++)

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

typedef long long ll;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif
  string str;

  cin >> str;

  int len = str.size(), ans = 0;
  set<int> s;

  int i = 0, j = 1;
  while (true) {
    if (i >= len || j >= len)
      break;
    if (str[i] == str[j] || i < 0) {
      if (i >= 0)
        s.insert(i);
      i = j;
      j = j + 1;
    } else {
      i = *s.rbegin();
      j++;
      ans += 2;
    }
  }

  cout << ans << endl;

  return 0;
}

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

typedef long long ll;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif
  string str;

  cin >> str;

  int len = str.size(), ans = 0;
  set<int> s;

  int i = 0, j = 1;
  while (true) {
    if (i >= len || j >= len)
      break;
    if (str[i] == str[j] || i < 0) {
      if (i >= 0)
        s.insert(i);
      i = j;
      j = j + 1;
    } else {
      if (s.count(i)) {
        s.erase(i);
      }
      if (!s.empty()) {
        i = *s.rbegin();
      } else
        i = -1;
      j++;
      ans += 2;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03107 (C++)

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

using namespace std;

vector<long long> func(vector<long long> &vv) {
  long long temp;
  temp = vv[0];
  bool flag = false;
  int fl = 0;
  for (long long j = 1; j < vv.size(); j++) {
    if (temp != vv[j]) {
      vv.erase(vv.begin() + j - 1);
      vv.erase(vv.begin() + j - 1);
      fl = 1;
    }
    temp = vv[j];
  }
  if (fl == 0) {
    return vv;
  }
  return func(vv);
}

int main() {
  std::string s;
  cin >> s;
  long long size = s.length();

  char cary[size];
  s.copy(cary, size);

  vector<long long> v(size);
  for (long long i = 0; i < size; i++) {
    v[i] = cary[i];
  }

  vector<long long> v2;
  v2 = func(v);

  cout << size - v2.size() << endl;

  return 0;
}

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

using namespace std;

vector<long long> func(vector<long long> &vv) {
  long long temp;
  temp = vv[0];
  bool flag = false;
  int fl = 0;
  for (long long j = 1; j < vv.size(); j++) {
    if (temp != vv[j]) {
      vv.erase(vv.begin() + j - 1);
      vv.erase(vv.begin() + j - 1);
      fl = 1;
      break;
    }
    temp = vv[j];
  }
  if (fl == 0) {
    return vv;
  }
  return func(vv);
}

int main() {
  std::string s;
  cin >> s;
  long long size = s.length();

  char cary[size];
  s.copy(cary, size);

  vector<long long> v(size);
  for (long long i = 0; i < size; i++) {
    v[i] = cary[i];
  }

  vector<long long> v2;
  v2 = func(v);

  cout << size - v2.size() << endl;

  return 0;
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

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

  vector<char> vec;
  vec.push_back(S[0]);
  ll count = 0;
  for (int i = 1; i < S.length(); ++i) {
    if (vec.front() != S[i]) {
      count += 2;
      vec.pop_back();
    } else {
      vec.push_back(S[i]);
    }
  }
  cout << count << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

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

  vector<char> vec;
  vec.push_back(S[0]);
  ll count = 0;
  for (int i = 1; i < S.length(); ++i) {
    if (vec.size() == 0) {
      vec.push_back(S[i]);
    } else if (vec.front() != S[i]) {
      count += 2;
      vec.pop_back();
    } else {
      vec.push_back(S[i]);
    }
  }
  cout << count << endl;
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  map<char, int> c;
  for (int i = 0; i < s.size(); i++)
    c[s.at(i)]++;
  cout << min(c.at('0'), c.at('1')) * 2 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  map<char, int> c;
  for (int i = 0; i < s.size(); i++)
    c[s.at(i)]++;
  cout << min(c['0'], c['1']) * 2 << endl;
}
Problem p03107 (C++)

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s.substr(i, 2) == "01" || s.substr(i, 2) == "10") {
      s.erase(s.begin() + i, s.begin() + i + 2);
      ans += 2;

      i -= 3;
      i = max(-1, i);
    }
  }
  cout << ans;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s.substr(i, 2) == "01" || s.substr(i, 2) == "10") {
      s.erase(s.begin() + i, s.begin() + i + 2);
      ans += 2;

      i -= 3;
      i = max(-1, i);
      if (s.size() == 0) {
        break;
      }
    }
  }
  cout << ans;
}
Problem p03107 (C++)

Buggy submission (status: Time Limit Exceeded):
// AtCoder ABC120 C - Unification
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
std::string replaceStringAll(std::string str, const std::string &replace,
                             const std::string &with) {
  if (!replace.empty()) {
    std::size_t pos = 0;
    while ((pos = str.find(replace, 0)) != std::string::npos) {
      str.replace(pos, replace.length(), with);
      // pos += with.length();
    }
  }
  return str;
}
int main() {
#if LOCAL & 0
  std::ifstream in("./test/sample-1.in"); // input.txt
  std::cin.rdbuf(in.rdbuf());
#endif
  string S = "0011";
  cin >> S;
  auto ret = replaceStringAll(S, "01", "");
  ret = replaceStringAll(ret, "10", "");
  cout << S.size() - ret.size() << endl;
  return 0;
}

Fixed submission:
// AtCoder ABC120 C - Unification
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
std::string replaceStringAll(std::string str, const std::string &replace,
                             const std::string &with) {
  if (!replace.empty()) {
    std::size_t pos = 0;
    while ((pos = str.find(replace, 0)) != std::string::npos) {
      str.replace(pos, replace.length(), with);
      // pos += with.length();
    }
  }
  return str;
}
int main() {
#if LOCAL & 0
  std::ifstream in("./test/sample-1.in"); // input.txt
  std::cin.rdbuf(in.rdbuf());
#endif
  string S = "0011";
  cin >> S;
  ll cnt0 = 0;
  for (const auto &c : S) {
    if (c == '0') {
      ++cnt0;
    }
  }
  ll cnt1 = S.size() - cnt0;
  cout << min(cnt0, cnt1) * 2 << endl;
  return 0;
}
Problem p03107 (C++)

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

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(a) cout << #a << ": " << a << endl;

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

  int cnt = 0;
  while ((int)S.size() != 0) {
    int find01 = S.find("01");
    int find10 = S.find("10");
    if (find01 == -1 && find10 == -1) {
      break;
    } else {
      if (find01 == -1) {
        S.erase(find10, 2);
      } else if (find10 == -1) {
        S.erase(find01, 2);
      } else {
        S.erase(min(find01, find10), 2);
      }
      cnt += 1;
    }
  }
  cout << cnt * 2 << endl;
}


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

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(a) cout << #a << ": " << a << endl;

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

  int cnt0 = count(S.begin(), S.end(), '0');
  int cnt1 = count(S.begin(), S.end(), '1');
  cout << min(cnt0, cnt1) * 2 << endl;
}
Problem p03107 (C++)

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

int main() {
  string s;

  while (cin >> s) {
    int sz = s.size();

    while (s.size() > 1) {
      int flag = 0;
      for (int i = 0; i < s.size() - 1; i++) {
        if ((s[i] == '0' && s[i + 1] == '1') ||
            (s[i] == '1' && s[i + 1] == '0')) {
          s.erase(i, 2);
          i--;
          flag = 1;
        }
        if (s.size() < 2)
          break;
      }
      if (flag == 0)
        break;
    }

    cout << sz - s.size() << endl;
  }

  return 0;
}


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

int main() {
  string s;

  while (cin >> s) {
    int sz = s.size();

    while (s.size() > 1) {
      int flag = 0;
      for (int i = 0; i < s.size() - 1; i++) {
        if ((s[i] == '0' && s[i + 1] == '1') ||
            (s[i] == '1' && s[i + 1] == '0')) {
          s.erase(i, 2);
          i -= 2;

          if (i == -2)
            i = -1;

          flag = 1;
        }
        if (s.size() < 2)
          break;
      }
      if (flag == 0)
        break;
    }

    cout << sz - s.size() << endl;
  }

  return 0;
}
Problem p03107 (C++)

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

using namespace std;

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

  int ans = 0;
  while (s.size() > 0 && count(s.begin(), s.end(), s[0]) < s.size()) {
    for (int i = 0; i < s.size() - 1; ++i) {
      if ((s[i] == '0' && s[i + 1] == '1') ||
          (s[i] == '1' && s[i + 1] == '0')) {
        s.erase(i, 2);
        ans += 2;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

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

  int zero = count(s.begin(), s.end(), '0');
  int one = count(s.begin(), s.end(), '1');
  int ans = 2 * min(zero, one);

  cout << ans << endl;

  return 0;
}
Problem p03107 (C++)

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a = 0;
  int b = 0;
  for (int i = 0; i < n; i++) {
    if (s.at(i) == '0')
      a++;
    else
      b++;
  }

  int m = n;
  int r = 0;

  while (a > 0 && b > 0) {
    string t = s;
    int m = t.size();
    for (int i = 0; i < m - 1; i++) {
      if (t.at(i) != t.at(i + 1)) {
        r += 2;
        s.erase(s.begin() + i, s.begin() + i + 1);
        a--;
        b--;
        break;
      }
    }
  }

  cout << r << endl;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a = 0;
  int b = 0;
  for (int i = 0; i < n; i++) {
    if (s.at(i) == '0')
      a++;
    else
      b++;
  }

  cout << min(a, b) * 2 << endl;
}
Problem p03107 (C++)

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

using namespace std;

int main(void) {
  string S;
  cin >> S;
  int N = S.size();
  int first = 0, second = 1;
  int ans = 0;
  while (second < N) {
    if (S[first] != S[second]) {
      ans += 2;
      S[first] = S[second] = 'x';
      while (first >= 0 && S[first] == 'x')
        first--;
      if (first < 0) {
        first = second + 1;
        second = first + 1;
      } else
        second++;
    } else {
      first = second;
      second++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(void) {
  string S;
  cin >> S;
  int sum[2] = {0, 0};
  for (auto i : S)
    sum[i - '0']++;
  cout << (S.size() - (max(sum[0], sum[1]) - min(sum[0], sum[1]))) << endl;
  return 0;
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100000

int main(void) {
  char input[N];
  char stack[N];
  scanf("%s", input);

  int eraseCnt = 0;
  stack[0] = input[0];
  int sCnt, iCnt;
  for (sCnt = 0, iCnt = 1; input[iCnt] != '\0';) {
    // printf("%c %c\n",stack[sCnt],input [iCnt]);
    if (stack[sCnt] != input[iCnt]) { // erase
      eraseCnt++;
      if (sCnt == 0) { // stack becomes empty
        stack[sCnt] = input[iCnt + 1];
        sCnt = 0;
        iCnt = iCnt + 2;
      } else { // stack still not empty
        sCnt = sCnt - 1;
        iCnt = iCnt + 1;
      }
    } else { // dont erase
      stack[sCnt + 1] = input[iCnt];
      sCnt++;
      iCnt++;
    }
  }
  printf("%d", eraseCnt * 2);
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 200000

int main(void) {
  char input[N];
  char stack[N];
  scanf("%s", input);

  int eraseCnt = 0;
  stack[0] = input[0];
  int sCnt, iCnt;
  for (sCnt = 0, iCnt = 1; input[iCnt] != '\0';) {
    // printf("%c %c\n",stack[sCnt],input [iCnt]);
    if (stack[sCnt] != input[iCnt]) { // erase
      eraseCnt++;
      if (sCnt == 0) { // stack becomes empty
        stack[sCnt] = input[iCnt + 1];
        sCnt = 0;
        iCnt = iCnt + 2;
      } else { // stack still not empty
        sCnt = sCnt - 1;
        iCnt = iCnt + 1;
      }
    } else { // dont erase
      stack[sCnt + 1] = input[iCnt];
      sCnt++;
      iCnt++;
    }
  }
  printf("%d", eraseCnt * 2);
  return 0;
}
Problem p03107 (C++)

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int num0, num1;
  num0 = count(s.begin(), s.end(), '0');
  num1 = count(s.begin(), s.end(), '1');
  cout << min(num0, num1) * 2;
  while (1)
    ;
  return 0;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int num0, num1;
  num0 = count(s.begin(), s.end(), '0');
  num1 = count(s.begin(), s.end(), '1');
  cout << min(num0, num1) * 2;
  return 0;
}
Problem p03107 (C++)

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

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

  int b, w;
  b = 0;
  w = 0;

  for (int i = 0;; i++) {
    if (s.at(i) == '1') {
      b++;
    } else {
      w++;
    }
  }

  int Ans = min(b, w) * 2;

  cout << Ans << endl;
}


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

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

  int b, w;
  b = 0;
  w = 0;

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '1') {
      b++;
    } else {
      w++;
    }
  }

  int Ans = min(b, w) * 2;

  cout << Ans << endl;
}
Problem p03107 (C++)

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

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  int i = 0;
  while (s.size() != 0 && s.size() != 1) {
    if ((s.at(i) - '0') + (s.at(i + 1) - '0') == 1) {
      s.erase(i, 2);
      i = -1;
      cnt += 2;
    }
    i++;
    if (i == s.size() - 1)
      break;
  }
  cout << cnt << endl;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  vector<int> cnt(2, 0);
  rep(i, s.size()) { cnt[s.at(i) - '0']++; }
  cout << 2 * min(cnt[0], cnt[1]) << endl;
  return 0;
}
Problem p03107 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  string S;
  cin >> S;
  int e = 0, ne = 0;
  do {
    ne = 0;
    int i = 0;
    while (i < int(S.size()) - 1) {
      if (S.at(i) != S.at(i + 1)) {
        S.erase(i, 2);
        e += 2;
        ne += 1;
      }
      i++;
    }

  } while (ne != 0);
  cout << e;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  string S;
  cin >> S;
  int z = 0, o = 0;
  for (size_t i = 0; i < S.size(); i++) {
    if (S.at(i) == '0') {
      z++;
    } else
      o++;
  }
  cout << min(o, z) * 2;
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
typedef long long ll;
const int xmax = 1e5 + 7;
const int INF = 1e9 + 7;
using namespace std;
int main() {
  char s[1000];
  scanf("%s", s);
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == '0')
      ans1++;
    else
      ans2++;
  }
  if (ans1 == 0 || ans2 == 0)
    printf("0");
  else
    printf("%d", min(ans1, ans2) * 2);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
typedef long long ll;
const int xmax = 1e5 + 7;
const int INF = 1e9 + 7;
using namespace std;
int main() {
  char s[100007];
  scanf("%s", s);
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == '0')
      ans1++;
    else
      ans2++;
  }
  if (ans1 == 0 || ans2 == 0)
    printf("0");
  else
    printf("%d", min(ans1, ans2) * 2);
  return 0;
}
Problem p03107 (C++)

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

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;

// 120
int main() {
  static char S[10010];

  scanf("%s", S);

  ll len = strlen(S);

  ll countOne = 0;
  for (ll i = 0; i < len; i++) {
    if (S[i] == '1') {
      countOne++;
    }
  }

  printf("%lld", std::min(countOne, len - countOne) * 2);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;

// 120
int main() {
  static char S[100010];

  scanf("%s", S);

  ll len = strlen(S);

  ll countOne = 0;
  for (ll i = 0; i < len; i++) {
    if (S[i] == '1') {
      countOne++;
    }
  }

  printf("%lld", std::min(countOne, len - countOne) * 2);

  return 0;
}
Problem p03107 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

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

  ll total = 0;
  while (1) {
    ll count = 0;
    REP(i, max((signed)0, (signed)s.size() - 1)) {
      if (s.substr(i, 2) == "01" || s.substr(i, 2) == "10") {
        s.erase(i, 2);
        i--;
        count += 2;
      }
    }
    if (count == 0)
      break;
    else
      total += count;
  }
  cout << total << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
  string s;
  cin >> s;
  cout << 2 * min(count(ALL(s), '0'), count(ALL(s), '1')) << endl;
  return 0;
}
Problem p03107 (C++)

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

typedef long long ll;

char s[10020];
int ans, tot1, tot2;
int main() {
  cin >> s;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == '0')
      tot1++;
    else
      tot2++;
  }
  ans = min(tot1, tot2) * 2;
  cout << ans << endl;
}


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

typedef long long ll;

char s[100200];
int ans, tot1, tot2;
int main() {
  cin >> s;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == '0')
      tot1++;
    else
      tot2++;
  }
  ans = min(tot1, tot2) * 2;
  cout << ans << endl;
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int zero, one;
int main() {
  char ch[1000];
  scanf("%s", &ch);
  int len = strlen(ch);
  for (int i = 0; i < len; i++) {
    if (ch[i] == '0')
      ++zero;
    else if (ch[i] == '1')
      ++one;
  }
  printf("%d\n", min(zero, one) * 2);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int zero, one;
int main() {
  char ch[100009];
  scanf("%s", &ch);
  int len = strlen(ch);
  for (int i = 0; i < len; i++) {
    if (ch[i] == '0')
      ++zero;
    else if (ch[i] == '1')
      ++one;
  }
  printf("%d\n", min(zero, one) * 2);
}
Problem p03107 (C++)

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

int main() {
  string homu;
  cin >> homu;
  int n = homu.size();
  while (1) {
    bool ok = false;
    string ns = "";
    for (int i = 0; i < (int)homu.size(); ++i) {
      if (i + 1 < homu.size() && homu[i] != homu[i + 1]) {
        ++i;
        ok = true;
      } else
        ns += homu[i];
    }
    if (!ok)
      break;
    // cout<<ns<<endl;
    homu.swap(ns);
  }
  cout << n - homu.size() << endl;

  return 0;
}


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

int main() {
  string homu;
  cin >> homu;
  int n = homu.size();
  random_shuffle(homu.begin(), homu.end());
  while (1) {
    bool ok = false;
    string ns = "";
    for (int i = 0; i < (int)homu.size(); ++i) {
      if (i + 1 < homu.size() && homu[i] != homu[i + 1]) {
        ++i;
        ok = true;
      } else
        ns += homu[i];
    }
    if (!ok)
      break;
    // cout<<ns<<endl;
    homu.swap(ns);
  }
  cout << n - homu.size() << endl;

  return 0;
}
Problem p03107 (C++)

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  bool f = true;
  while (f) {
    f = false;
    for (int i = 1; i < s.size(); i++) {
      if (s[i] != s[i - 1]) {
        s.erase(i - 1, 2);
        ans += 2;
        i -= 2;
        f = true;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  bool f = true;
  while (f) {
    f = false;
    for (int i = 1; i < s.size(); i++) {
      if (s[i] != s[i - 1]) {
        s.erase(i - 1, 2);
        ans += 2;
        i--;
        f = true;
      }
    }
  }
  cout << ans << endl;
}
Problem p03107 (C++)

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

using namespace std;

int main() {
  string s;
  int n = 0;

  cin >> s;

  for (int i = 0; i < s.size();) {
    if (s.substr(i, 2) == "01" || s.substr(i, 2) == "10") {
      n += 2;
      s.erase(i, 2);
      i = 0;
    } else {
      i++;
    }
  }
  cout << n << endl;

  return 0;
}

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

using namespace std;

int main() {
  string s;
  int n = 0;

  cin >> s;

  for (int i = 0; i < s.size();) {
    if (s.substr(i, 2) == "01" || s.substr(i, 2) == "10") {
      n += 2;
      s.erase(i, 2);
      if (i != 0)
        i--;
    } else {
      i++;
    }
  }
  cout << n << endl;

  return 0;
}
Problem p03107 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  int ssize = S.size();
  int counter = 0;
  vector<bool> flag(ssize, true);
  for (int i = 0; i < ssize - 1; i++) {
    if (!flag.at(i))
      continue;
    int next = -1;
    for (int j = i + 1; j < ssize; j++) {
      if (flag.at(j)) {
        next = j;
        break;
      }
    }
    if (next == -1)
      break;

    if (S.at(i) != S.at(next)) {
      flag.at(i) = false;
      flag.at(next) = false;
      counter += 2;
      i = -1;
    }
  }
  cout << counter << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  cout << 2 * min(count(ALL(S), '0'), count(ALL(S), '1')) << endl;
}
Problem p03107 (C++)

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

int main() {
  string S;
  cin >> S;
  int start = 0;
  int compare = start + 1;
  int count = 0;
  priority_queue<int> bs;
  while (compare < S.size()) {
    if (S[start] != S[compare]) {
      count += 2;
      while (true) {
        if (start > bs.top()) {
          start = bs.top();
          compare++;
          break;
        }
        if (bs.top() == 0) {
          start = compare + 1;
          compare = start + 1;
          break;
        }
        bs.pop();
      }
    } else {
      bs.push(start);
      start = compare;
      compare = start + 1;
    }
  }

  cout << count << endl;
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  int start = 0;
  int compare = start + 1;
  int count = 0;
  priority_queue<int> bs;
  while (compare < S.size()) {
    if (S[start] != S[compare]) {
      count += 2;
      while (true) {
        if (bs.size() == 0) {
          start = compare + 1;
          compare = start + 1;
          break;
        }
        if (start > bs.top()) {
          start = bs.top();
          compare++;
          break;
        }
        if (bs.top() == 0) {
          start = compare + 1;
          compare = start + 1;
          break;
        }
        bs.pop();
      }
    } else {
      bs.push(start);
      start = compare;
      compare = start + 1;
    }
  }

  cout << count << endl;
  return 0;
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, red = 0, blue = 0;
  string s;
  cin >> n >> s;
  REP(i, n) {
    if (s[i] == '0') {
      red++;
    } else {
      blue++;
    }
  }
  cout << min(red, blue) * 2;
  return (0);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, red = 0, blue = 0;
  string s;
  cin >> s;
  n = s.size();
  REP(i, n) {
    if (s[i] == '0') {
      red++;
    } else {
      blue++;
    }
  }
  cout << min(red, blue) * 2;
  return (0);
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
const int M = 1e6 + 10;
int n, cnt, ans;
bool a[M], st[M];
int main() {
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    a[i] = s[i] - '0';
  for (int i = 0; i < n; i++) {
    if (cnt && (st[cnt - 1] ^ a[i]) == 1)
      cnt--, ans += 2;
    else
      st[cnt++] = a[i];
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
const int M = 1e6 + 10;
int n, cnt, ans;
bool a[M], st[M];
int main() {
  string s;
  cin >> s;
  n = s.length();
  for (int i = 0; i < n; i++)
    a[i] = s[i] - '0';
  for (int i = 0; i < n; i++) {
    if (cnt && (st[cnt - 1] ^ a[i]) == 1)
      cnt--, ans += 2;
    else
      st[cnt++] = a[i];
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03107 (C++)

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

int A[] = {0, 0};

int main(void) {
  while (true) {
    char c = getchar();
    if (c == EOF)
      break;
    A[c - '0']++;
  }
  printf("%d\n", (A[0] > A[1] ? A[1] : A[0]) << 1);
  return 0;
}

Fixed submission:
#include <iostream>

int A[] = {0, 0};

int main(void) {
  while (true) {
    char c = getchar();
    if (c == '\n')
      break;
    A[c - '0']++;
  }
  printf("%d\n", (A[0] > A[1] ? A[1] : A[0]) << 1);
  return 0;
}
Problem p03107 (C++)

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

int main() {
  string s;
  cin >> s;
  bool flag = true;
  bool done = false;
  int count = 0;
  int len = s.size();
  while (flag) {
    done = false;
    for (int i = 0; i < s.size(); ++i) {
      if ((s[i] == '0' && s[i + 1] == '1') or
          (s[i] == '1' && s[i + 1] == '0')) {
        s.erase(s.begin() + i, s.begin() + i + 2);
        count += 2;
        done = true;
      }
    }
    if (!done)
      flag = false;
  }
  cout << count << endl;
}


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

int main() {
  string s;
  cin >> s;
  bool flag = true;
  bool done = false;
  int count = 0;
  int len = s.size();
  while (flag) {
    done = false;
    for (int i = 0; i < s.size(); ++i) {
      if ((s[i] == '0' && s[i + 1] == '1') or
          (s[i] == '1' && s[i + 1] == '0')) {
        s.erase(s.begin() + i, s.begin() + i + 2);
        count += 2;
        done = true;
        if (i >= 1)
          i -= 2;
      }
    }
    if (!done)
      flag = false;
  }
  cout << count << endl;
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF = 1e18;
const int MOD = 1e9 + 7;
const double pi = acos(-1);
int main() {
  string s;
  cin >> s;
  ll n = s.size();
  vector<int> vec;
  rep(i, n) vec.push_back(s[i] - '0');
  ll now = 0;
  ll have = n;
  while (now <= have - 1 && 0 <= now) {
    if (vec[now] != vec[now + 1]) {
      vec.erase(vec.begin() + now);
      vec.erase(vec.begin() + now);
      have -= 2;
      if (now != 0)
        now--;
    } else {
      now++;
    }
  }
  cout << n - have << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF = 1e18;
const int MOD = 1e9 + 7;
const double pi = acos(-1);
int main() {
  string s;
  cin >> s;
  ll n = s.size();
  vector<int> vec;
  rep(i, n) vec.push_back(s[i] - '0');
  ll now = 0;
  ll have = n;
  while (now <= have - 2 && 0 <= now) {
    if (vec[now] != vec[now + 1]) {
      vec.erase(vec.begin() + now);
      vec.erase(vec.begin() + now);
      have -= 2;
      if (now != 0)
        now--;
    } else {
      now++;
    }
  }
  cout << n - have << endl;
}
Problem p03107 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,tune=native")

#include <bits/stdc++.h>
#include <x86intrin.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  string backup = s;
  auto i = s.find("01", 0);
  while (i != -1) {
    s = s.substr(0, i) + s.substr(i + 2, -1);
    i = s.find("01", 0);
  }
  i = s.find("10", 0);
  while (i != -1) {
    s = s.substr(0, i) + s.substr(i + 2, -1);
    i = s.find("10", 0);
  }
  cout << backup.length() - s.length();
  return 0;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,tune=native")

#include <bits/stdc++.h>
#include <x86intrin.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int cnt0 = 0, cnt1 = 0;
  for (int i = 0; i < s.length(); i++)
    (s[i] == '1') ? cnt1++ : cnt0++;
  cout << 2 * min(cnt0, cnt1);
  return 0;
}
Problem p03107 (C++)

Buggy submission (status: Runtime Error):
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int max(int a, int b) { return a >= b ? a : b; }
int lmax(long int a, long int b) { return a >= b ? a : b; }
int min(int a, int b) { return b >= a ? a : b; }
int lmin(long int a, long int b) { return b >= a ? a : b; }
int sei(int a) { return a > 0 ? a : 0; }
long int power(int a, int b) {
  long int count = 1;
  for (int i = 0; i < b; i++) {
    count *= 2;
  }
  return count;
}
int factorial(int n) {
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}
int compare_up_int(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}
int compare_down_int(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}
int euclid(int a, int b) {
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }
  int r = a % b;
  if (r < 0)
    r += b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
    if (r < 0)
      r += b;
  }
  return b;
}

int main() {
  char s[10001];
  int count0 = 0, count1 = 0;
  scanf("%s", s);
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == '0')
      count0++;
    else
      count1++;
  }
  if (count1 >= 1 && count0 >= 1) {
    printf("%d", 2 * min(count0, count1));
    return 0;
  } else
    printf("%d", 0);
  return 0;
}


Fixed submission:
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int max(int a, int b) { return a >= b ? a : b; }
int lmax(long int a, long int b) { return a >= b ? a : b; }
int min(int a, int b) { return b >= a ? a : b; }
int lmin(long int a, long int b) { return b >= a ? a : b; }
int sei(int a) { return a > 0 ? a : 0; }
long int power(int a, int b) {
  long int count = 1;
  for (int i = 0; i < b; i++) {
    count *= 2;
  }
  return count;
}
int factorial(int n) {
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}
int compare_up_int(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}
int compare_down_int(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}
int euclid(int a, int b) {
  if (a < b) {
    int tmp = a;
    a = b;
    b = tmp;
  }
  int r = a % b;
  if (r < 0)
    r += b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
    if (r < 0)
      r += b;
  }
  return b;
}

int main() {
  char s[100001];
  int count0 = 0, count1 = 0;
  scanf("%s", s);
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == '0')
      count0++;
    else
      count1++;
  }
  if (count1 >= 1 && count0 >= 1) {
    printf("%d", 2 * min(count0, count1));
    return 0;
  } else
    printf("%d", 0);
  return 0;
}