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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll int64_t
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = 1; i <= n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007

using namespace std;

bool compare_by_b(pair<string, ll> a, pair<string, ll> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}

bool my_compare(pair<string, ll> a, pair<string, ll> b) {

  if (a.first != b.first)
    return a.first < b.first;
  if (a.second != b.second)
    return a.second > b.second;
  else
    return true;
}

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

  rep(i, s.size()) {
    if (s.at(i) == '0')
      m.append("0");
    if (s.at(i) == '1')
      m.append("1");
    if (s.at(i) == 'B')
      m.pop_back();
  }
  cout << m << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll int64_t
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = 1; i <= n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007

using namespace std;

bool compare_by_b(pair<string, ll> a, pair<string, ll> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}

bool my_compare(pair<string, ll> a, pair<string, ll> b) {

  if (a.first != b.first)
    return a.first < b.first;
  if (a.second != b.second)
    return a.second > b.second;
  else
    return true;
}

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

  rep(i, s.size()) {
    if (s.at(i) == '0')
      m.append("0");
    if (s.at(i) == '1')
      m.append("1");
    if (s.at(i) == 'B')
      if (m.size() >= 1)
        m.pop_back();
  }
  cout << m << endl;
  return 0;
}
Problem p04030 (C++)

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

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() {
  string s;
  string res;

  cin >> s;
  for (char x : s) {
    if (x == '0')
      res += '0';
    else if (x == '1')
      res += '1';
    else
      res.pop_back();
  }
  cout << res << endl;

  return 0;
}


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

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() {
  string s;
  string res;

  cin >> s;
  for (char x : s) {
    if (x == '0')
      res += '0';
    else if (x == '1')
      res += '1';
    else if (x == 'B' && res != "")
      res.pop_back();
  }
  cout << res << endl;

  return 0;
}
Problem p04030 (C++)

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

int main() {
  string S;
  cin >> S;
  string answer;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '0') {
      answer = answer + '0';
    }
    if (S.at(i) == '1') {
      answer = answer + '1';
    }
    if (S.at(i) == 'B') {
      if (S.size() != 0) {
        answer.pop_back();
      }
    }
  }
  cout << answer << endl;
}

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

int main() {
  string S;
  cin >> S;
  string answer;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '0') {
      answer = answer + '0';
    }
    if (S.at(i) == '1') {
      answer = answer + '1';
    }
    if (S.at(i) == 'B') {
      if (answer.size() > 0) {
        answer.pop_back();
      }
    }
  }
  cout << answer << endl;
}
Problem p04030 (C++)

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

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

  int c = 0;
  vector<int> s;
  for (int i = 0; i < keys.length(); i++) {
    if (keys[i] == '0') {
      s.push_back(0);
      c++;
    } else if (keys[i] == '1') {
      s.push_back(1);
      c++;
    } else {
      s.pop_back();
      c--;
    }
  }

  for (int i = 0; i < c; i++) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}

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

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

  int c = 0;
  vector<int> s;
  for (int i = 0; i < keys.length(); i++) {
    if (keys[i] == '0') {
      s.push_back(0);
      c++;
    } else if (keys[i] == '1') {
      s.push_back(1);
      c++;
    } else if (s.size() > 0) {
      s.pop_back();
      c--;
    }
  }

  for (int i = 0; i < c; i++) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}
Problem p04030 (C++)

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

int main() {
  string a, b = {};
  cin >> a;
  for (int i = 0; i < a.length(); i++) {
    if (a[i] == '0') {
      b += '0';
    } else if (a[i] == '1') {
      b += '1';
    } else if (a[i] == 'B') {
      if (a.length() > 0) {
        b.pop_back();
      }
    }
  }
  cout << b;
}


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

int main() {
  string a, b = {};
  cin >> a;
  for (int i = 0; i < a.length(); i++) {
    if (a[i] == '0') {
      b += '0';
    } else if (a[i] == '1') {
      b += '1';
    } else if (a[i] == 'B') {
      if (b.length() > 0) {
        b.pop_back();
      }
    }
  }
  cout << b;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define INF

typedef long long ll;

int main() {
  std::string str;
  std::vector<int> ans;
  std::cin >> str;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '0') {
      ans.push_back(0);
    } else if (str[i] == '1') {
      ans.push_back(1);
    } else if (str[i] == 'B') {
      ans.pop_back();
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    std::cout << ans[i];
  }
  std::cout << std::endl;
  return 0;
}

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

typedef long long ll;

int main() {
  std::string str;
  std::vector<int> ans;
  std::cin >> str;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '0') {
      ans.push_back(0);
    } else if (str[i] == '1') {
      ans.push_back(1);
    } else if (str[i] == 'B' && ans.size() > 0) {
      ans.pop_back();
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    std::cout << ans[i];
  }
  std::cout << std::endl;
  return 0;
}
Problem p04030 (C++)

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

int main() {
  string s, ans;
  int i;
  cin >> s;
  for (i = 0; i < s.size(); i++) {
    switch (s[i]) {
    case '1':
      ans.push_back(s[i]);
      break;
    case '0':
      ans.push_back(s[i]);
      break;
    case 'B':
      if (i == 0) {
        continue;
      } else {
        ans.pop_back();
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  string s, ans;
  int i;
  cin >> s;
  for (i = 0; i < s.size(); i++) {
    switch (s[i]) {
    case '1':
      ans.push_back(s[i]);
      break;
    case '0':
      ans.push_back(s[i]);
      break;
    case 'B':
      if (ans.size() == 0) {
        continue;
      } else {
        ans.pop_back();
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p04030 (C++)

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18) + 7;
const llong mod = 1e9 + 7;

int main() {
  string s;

  cin >> s;
  string a;
  for (auto x : s)
    if (x == 'B')
      a.pop_back();
    else
      a += x;

  cout << a << endl;

  return 0;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18) + 7;
const llong mod = 1e9 + 7;

int main() {
  string s;

  cin >> s;
  string a;
  for (auto x : s)

    if (x == 'B') {
      if ((int)a.size() > 0)
        a.pop_back();
    } else
      a += x;

  cout << a << endl;

  return 0;
}
Problem p04030 (C++)

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

using namespace std;

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

  string ans;

  for (int i = 0; i < S.length(); i++) {
    if (S[i] == '0') {
      ans += '0';
    }
    if (S[i] == '1') {
      ans += '1';
    }
    if (S[i] == 'B') {
      ans.erase(ans.length() - 1);
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

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

  string ans;

  for (int i = 0; i < S.length(); i++) {
    if (S[i] == '0') {
      ans += '0';
    }
    if (S[i] == '1') {
      ans += '1';
    }
    if (S[i] == 'B' && ans.length() != 0) {
      ans.erase(ans.length() - 1);
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
// cout << std::fixed << std::setprecision(15) << y << endl;

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

  deque<ll> q;
  rep(i, s.size()) {
    switch (s[i]) {
    case '0':
      q.push_back(0);
      break;
    case '1':
      q.push_back(1);
      break;
    case 'B':
      q.pop_back();
      break;
    }
  }

  while (!q.empty()) {
    cout << q.front();
    q.pop_front();
  }
  cout << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
// cout << std::fixed << std::setprecision(15) << y << endl;

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

  deque<ll> q;
  rep(i, s.size()) {
    switch (s[i]) {
    case '0':
      q.push_back(0);
      break;
    case '1':
      q.push_back(1);
      break;
    case 'B':
      if (!q.empty()) {
        q.pop_back();
      }
      break;
    }
  }

  while (!q.empty()) {
    cout << q.front();
    q.pop_front();
  }
  cout << endl;

  return 0;
}
Problem p04030 (C++)

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

int main() {

  string input, output;
  cin >> input;
  for (int i = 0; i < input.size(); i++) {
    if (input[i] == '0' || input[i] == '1') {
      output += input[i];
    } else if (input[i] == 'B') {
      output.pop_back();
    }
  }

  cout << output << endl;
  return 0;
}

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

int main() {

  string input, output;
  cin >> input;
  for (int i = 0; i < input.size(); i++) {
    if (input[i] == '0' || input[i] == '1') {
      output += input[i];
    } else if (input[i] == 'B') {
      if (output == "") {

      } else {
        output.pop_back();
      }
    }
  }

  cout << output << endl;
  return 0;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail> void _cin(Head &&head, Tail &&...tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...)                                                            \
  T __VA_ARGS__;                                                               \
  _cin(__VA_ARGS__)

int main() {
  Cin(string, s);
  string out;

  for (auto e : s) {
    if (e == '0' || e == '1')
      out.push_back(e);
    if (e == 'B')
      out.pop_back();
  }

  puts(out.c_str());

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail> void _cin(Head &&head, Tail &&...tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...)                                                            \
  T __VA_ARGS__;                                                               \
  _cin(__VA_ARGS__)

int main() {
  Cin(string, s);
  string out;

  for (auto e : s) {
    if (e == '0' || e == '1')
      out.push_back(e);
    if (e == 'B')
      if (sz(out))
        out.pop_back();
  }

  puts(out.c_str());

  return 0;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); }
ll lcg(ll x, ll y) { return x * y / gcd(x, y); }
ll digits(ll x) {
  ll length = 0;
  while (x > 0) {
    x /= 10;
    length++;
  }
  return length;
  if (x == 0)
    return 0;
}
map<ll, ll> factor(ll n) {
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a) {
    if (n % a == 0) {
      ans[a]++;
      n /= a;
    } else
      a++;
  }
  ans[n]++;
  return ans;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  cout << fixed << setprecision(15);
  // int ans = 0;
  // string ans = "No";

  string ans = "";
  string s;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] == '0')
      ans += "0";
    if (s[i] == '1')
      ans += "1";
    if (s[i] == 'B')
      ans.pop_back();
  }

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

Fixed submission:
#include <bits/stdc++.h>
// #pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); }
ll lcg(ll x, ll y) { return x * y / gcd(x, y); }
ll digits(ll x) {
  ll length = 0;
  while (x > 0) {
    x /= 10;
    length++;
  }
  return length;
  if (x == 0)
    return 0;
}
map<ll, ll> factor(ll n) {
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a) {
    if (n % a == 0) {
      ans[a]++;
      n /= a;
    } else
      a++;
  }
  ans[n]++;
  return ans;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  cout << fixed << setprecision(15);
  // int ans = 0;
  // string ans = "No";

  string ans = "";
  string s;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] == '0')
      ans += "0";
    if (s[i] == '1')
      ans += "1";
    if (s[i] == 'B')
      if (ans != "")
        ans.pop_back();
  }

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

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

using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  string ans = "";
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      ans += "0";
    } else if (s[i] == '1') {
      ans += "1";
    } else {
      ans.pop_back();
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  string ans = "";
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      ans += "0";
    } else if (s[i] == '1') {
      ans += "1";
    } else {
      if (ans != "") {
        ans.pop_back();
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
lines = list(input())
answers = []
out = ""
for line in lines:
    if line == "0" or line == "1":
        answers.append(line)
    else:
        answers.pop()
for answer in answers:
    out += answer
print(out)


Fixed submission:
lines = list(input())
answers = []
out = ""
for line in lines:
    if line == "0" or line == "1":
        answers.append(line)
    elif answers:
        answers.pop()
for answer in answers:
    out += answer
print(out)
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
s = list(input())
n = len(s)

ans = []
for i in range(n):
    if s[i] == "0":
        ans.append("0")
    if s[i] == "1":
        ans.append("1")
    if s[i] == "B":
        ans[-1] = ""

print("".join(ans))


Fixed submission:
s = list(input())
n = len(s)

ans = []
for i in range(n):
    if s[i] == "0":
        ans.append("0")
    if s[i] == "1":
        ans.append("1")
    if s[i] == "B":
        if ans:
            ans.pop()

print("".join(ans))
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
keys = input()
outputs = []

for key in keys:
    if key == "B":
        if outputs is None:
            pass
        else:
            outputs.pop()
    else:
        outputs.append(key)

for output in outputs:
    print(output, end="")


Fixed submission:
keys = input()
outputs = []

for key in keys:
    if key == "B":
        if not outputs:
            pass
        else:
            outputs.pop()
    else:
        outputs.append(key)

for output in outputs:
    print(output, end="")
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
s = input()
ans = []
for c in s:
    if c == "0":
        ans.append("0")
    if c == "1":
        ans.append("1")
    if c == "B":
        ans.pop(-1)
print("".join(ans))


Fixed submission:
s = input()
ans = []
for c in s:
    if c == "0":
        ans.append("0")
    if c == "1":
        ans.append("1")
    if c == "B":
        if ans:
            ans.pop(-1)
        else:
            pass
print("".join(ans))
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
s = input()
ans = []

for i in range(len(s)):
    if s[i] == "0":
        ans.append("0")
    if s[i] == "1":
        ans.append("1")
    if s[i] == "B":
        ans.pop(-1)

print("".join(ans))


Fixed submission:
s = input()
ans = []

for i in range(len(s)):
    if s[i] == "0":
        ans.append("0")
    if s[i] == "1":
        ans.append("1")
    if s[i] == "B":
        if len(ans) != 0:
            ans.pop(-1)

print("".join(ans))
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
arr = input()
arr = "".join(reversed(arr))
print(arr[: arr.index("B")])


Fixed submission:
arr = input()
new = ""
for x in arr:
    if x == "B":
        if new:
            new = new[:-1]
    else:
        new += x
print(new)
Problem p04030 (C++)

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

int main() {
  string s, t;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (i > 0 && s[i] == 'B')
      t.pop_back();
    if (s[i] == '0')
      t += '0';
    if (s[i] == '1')
      t += '1';
  }

  cout << t << endl;

  return 0;
}

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

int main() {
  string s, t;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (t.length() != 0 && s[i] == 'B')
      t.pop_back();
    if (s[i] == '0')
      t += '0';
    if (s[i] == '1')
      t += '1';
  }

  cout << t << endl;

  return 0;
}
Problem p04030 (Python)

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


def list_n():
    return [int(e) for e in input().split()]


def list_s():
    return [s for e in input().split()]


def main(s):
    ret = []
    for c in s:
        if c in ["0", "1"]:
            ret.append(c)
        else:
            if c:
                ret.pop()
    return "".join(ret)


if __name__ == "__main__":
    s = input()
    print(main(s))


Fixed submission:
# -*- coding: utf-8 -*-


def list_n():
    return [int(e) for e in input().split()]


def list_s():
    return [s for e in input().split()]


def main(s):
    ret = []
    for c in s:
        if c in ["0", "1"]:
            ret.append(c)
        else:
            if ret:
                ret.pop()
    return "".join(ret)


if __name__ == "__main__":
    s = input()
    print(main(s))
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
s = input()
ans = []
for x in s:
    if x == "0" or x == "1":
        ans.append(x)
    else:
        ans.pop()
print("".join(ans))


Fixed submission:
s = input()
ans = []
for x in s:
    if x == "0" or x == "1":
        ans.append(x)
    else:
        if len(ans) > 0:
            ans.pop()
print("".join(ans))
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
A = []
for a in input():
    if a == "0" or a == "1":
        A.append(a)
    else:
        del A[-1]
print("".join(A))


Fixed submission:
A = []
for a in input():
    if a == "0" or a == "1":
        A.append(a)
    elif len(A) > 0:
        del A[-1]
print("".join(A))
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
set = input()
words = []
for i in range(len(set)):
    if set[i] == "0":
        words.append("0")
    if set[i] == "1":
        words.append("1")
    if set[i] == "B":
        words.pop(-1)
word = ""
for i in words:
    word += i
print(word)


Fixed submission:
set = input()
words = []
for i in range(len(set)):
    if set[i] == "0":
        words.append("0")
    if set[i] == "1":
        words.append("1")
    if set[i] == "B":
        try:
            words.pop(-1)
        except:
            pass
word = ""
for i in words:
    word += i
print(word)
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
s = input()
s_list = list(s)
out_list = []

for i in range(len(s_list)):
    if s_list[i] == "0":
        out_list.append("0")
    elif s_list[i] == "1":
        out_list.append("1")
    elif s_list[i] == "B":
        del out_list[-1]

for ol in out_list:
    print(ol, end="")


Fixed submission:
s = input()
s_list = list(s)
out_list = []

for i in range(len(s_list)):
    if s_list[i] == "0":
        out_list.append("0")
    elif s_list[i] == "1":
        out_list.append("1")
    elif s_list[i] == "B":
        if out_list:
            del out_list[-1]

for ol in out_list:
    print(ol, end="")
Problem p04030 (Python)

Buggy submission (status: Runtime Error):
s = input()
ans = ""
for char in s:
    if char != "B":
        ans += char
    else:
        if ans == "":
            pass
        else:
            len = len(ans)
            ans = ans[0 : len - 1]
print(ans)


Fixed submission:
s = input()
ans = ""
for char in s:
    if char != "B":
        ans += char
    else:
        if ans == "":
            pass
        else:
            le = len(ans)
            ans = ans[0 : le - 1]
print(ans)
Problem p04030 (C++)

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

typedef pair<int, int> P;

int main() {
  string s;
  cin >> s;
  string ans;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '0') {
      ans += '0';
    } else if (s[i] == '1') {
      ans += '1';
    } else if (s[i] == 'B' && s.size()) {
      ans.pop_back();
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

typedef pair<int, int> P;

int main() {
  string s;
  cin >> s;
  string ans;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '0') {
      ans += '0';
    } else if (s[i] == '1') {
      ans += '1';
    } else if (s[i] == 'B' && ans.size()) {
      ans.pop_back();
    }
  }
  cout << ans << endl;
}
Problem p04031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define optimize_cin()                                                         \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  optimize_cin();
  lint N;
  cin >> N;
  vector<lint> a;
  a.resize(N);
  rep(i, N) { cin >> a[i]; }

  sort(ALL(a));

  vector<lint> l;

  lint mi = a[0];
  lint ma = a[a.size() - 1];
  for (lint i = mi; i < ma; ++i) {
    lint cost = 0;
    for (lint k = 0; k < N; ++k) {
      cost += (a[k] - i) * (a[k] - i);
    }
    l.pb(cost);
  }

  sort(ALL(l));
  cout << l[0] << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define optimize_cin()                                                         \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  optimize_cin();
  lint N;
  cin >> N;
  vector<lint> a;
  a.resize(N);
  rep(i, N) { cin >> a[i]; }

  sort(ALL(a));

  vector<lint> l;

  lint mi = a[0];
  lint ma = a[a.size() - 1];
  for (lint i = -100; i <= 100; ++i) {
    lint cost = 0;
    for (lint k = 0; k < N; ++k) {
      cost += (a[k] - i) * (a[k] - i);
    }
    l.pb(cost);
  }

  sort(ALL(l));
  cout << l[0] << endl;

  return 0;
}
Problem p04031 (C++)

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

int main(int argc, char const *argv[]) {
  std::vector<int> v(100), costs(201);
  int n, i, k;

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

  for (i = -100; i <= 100; i++) {
    for (k = 0; k < n; i++) {
      costs[i + 100] += ((i - v[k]) * (i - v[k]));
    }
  }

  cout << *min_element(costs.begin(), costs.end());
  return 0;
}

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

int main(int argc, char const *argv[]) {
  std::vector<int> v(100), costs(201);
  int n, i, k;

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

  for (i = -100; i <= 100; i++) {
    for (k = 0; k < n; k++) {
      costs[i + 100] += ((i - v[k]) * (i - v[k]));
    }
  }

  cout << *min_element(costs.begin(), costs.end());
  return 0;
}
Problem p04031 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]

li_ans = []
ans = 0

for j in range(min(a), max(a)):
    for k in a:
        ans += abs(k - j) ** 2
    else:
        li_ans.appned(ans)
        ans = 0

if len(li_ans) == 0:
    print(0)
else:
    print(min(li_ans))


Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]

li_ans = []
ans = 0

for j in range(min(a), max(a)):
    for k in a:
        ans += abs(k - j) ** 2
    else:
        li_ans.append(ans)
        ans = 0

if len(li_ans) == 0:
    print(0)
else:
    print(min(li_ans))
Problem p04031 (C++)

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

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

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

  int C = v.at(N - 1) - v.at(0);
  vector<int> u(C);

  for (int j = 0; j < C; j++) {
    for (int i = 0; i < N; i++) {
      u.at(j) += (v.at(i) - (j + v.at(0))) * (v.at(i) - (j + v.at(0)));
    }
  }

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

  cout << u.at(0) << endl;
}

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

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

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

  int C = v.at(N - 1) - v.at(0) + 1;
  vector<int> u(C);

  for (int j = 0; j < C; j++) {
    for (int i = 0; i < N; i++) {
      u.at(j) += (v.at(i) - (j + v.at(0))) * (v.at(i) - (j + v.at(0)));
    }
  }

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

  cout << u.at(0) << endl;
}
Problem p04031 (C++)

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

using namespace std;
int main() {
#ifdef LDT
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#else
  freopen("movie.inp", "r", stdin);
  freopen("movie.out", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long res = 0;
  long long suma = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    res += 1ll * x * x;
    suma += x;
  }
  suma *= 2;
  // find y such that n * y * y - suma * y is min
  // n * 2 * y - suma = 0
  long long best = suma / 2 / n;
#define cost(x) ((x) * (x)*n - suma * (x))
  res = res + min({cost(best), cost(best - 1), cost(best + 1)});
  cout << res;
  return 0;
}

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

using namespace std;
int main() {
  // #ifdef LDT
  //     freopen("input.txt", "r", stdin);
  //     //freopen("output.txt", "w", stdout);
  // #else
  //     freopen("movie.inp", "r", stdin);
  //     freopen("movie.out", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long res = 0;
  long long suma = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    res += 1ll * x * x;
    suma += x;
  }
  suma *= 2;
  // find y such that n * y * y - suma * y is min
  // n * 2 * y - suma = 0
  long long best = suma / 2 / n;
#define cost(x) ((x) * (x)*n - suma * (x))
  res = res + min({cost(best), cost(best - 1), cost(best + 1)});
  cout << res;
  return 0;
}
Problem p04031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans;
  ans = 10000000;
  cin >> n;
  vector<int> a;
  vector<int> b(201);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = -100; i < 101; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++)
      sum += (a.at(j) - i) * (a.at(j) - i);
    ans = min(ans, sum);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans;
  ans = 10000000;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = -100; i < 101; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++)
      sum += (a.at(j) - i) * (a.at(j) - i);
    ans = min(ans, sum);
  }
  cout << ans << endl;
}
Problem p04031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

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

int main() {
  IOS io_set();
  ll n, i, j, m = INT_MAX;
  cin >> n;
  ll a[n], s = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = -100; i <= 100; i++) {
    ll ans = 0;
    for (j = 0; j < n; j++) {
      ans += ((abs(i - a[j])) * (abs(i - a[j])));
    }
    m = min(m, ans);
  }
  cout << m << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

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

int main() {
  IOS
      // io_set();
      ll n,
      i, j, m = INT_MAX;
  cin >> n;
  ll a[n], s = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = -100; i <= 100; i++) {
    ll ans = 0;
    for (j = 0; j < n; j++) {
      ans += ((abs(i - a[j])) * (abs(i - a[j])));
    }
    m = min(m, ans);
  }
  cout << m << endl;
  return 0;
}
Problem p04032 (Python)

Buggy submission (status: Time Limit Exceeded):
s = input()
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        print(i + 1, i + 2)
        exit(0)
for sz in range(3, 102, 2):
    if sz > len(s):
        break
    for i in range(len(s) - sz + 1):
        curr = s[i : i + sz]
        for it in curr:
            if curr.count(it) > sz // 2:
                print(i + 1, i + sz)
                exit(0)
print("-1 -1")


Fixed submission:
s = input()
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        print(i + 1, i + 2)
        exit(0)
for sz in range(3, 4, 2):
    if sz > len(s):
        break
    for i in range(len(s) - sz + 1):
        curr = s[i : i + sz]
        for it in curr:
            if curr.count(it) > sz // 2:
                print(i + 1, i + sz)
                exit(0)
print("-1 -1")
Problem p04032 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <string.h>

int main(void) {
  char s[100000];
  int l;
  int i, j;
  int n[26] = {};
  int th;
  int num;

  scanf("%s", s);

  l = strlen(s);

  for (i = 2; i <= 2; i++) {
    th = i / 2 + 1;

    for (j = 0; j < 26; j++) {
      n[j] = 0;
    }

    for (j = 0; j < i; j++) {
      num = s[j] - 'a';
      n[num]++;
      if (n[num] >= th) {
        printf("%d %d\n", 1, i);
        return 0;
      }
    }

    for (j = i; j < l; j++) {
      num = s[j - i] - 'a';
      n[num]--;
      num = s[j] - 'a';
      n[num]++;
      if (n[num] >= th) {
        printf("%d %d\n", j - i + 2, j + 1);
        return 0;
      }
    }
  }
  if (l > 2) {
    for (i = 3; i <= l; i += 2) {
      th = i / 2 + 1;

      for (j = 0; j < 26; j++) {
        n[j] = 0;
      }

      for (j = 0; j < i; j++) {
        num = s[j] - 'a';
        n[num]++;
        if (n[num] >= th) {
          printf("%d %d\n", 1, i);
          return 0;
        }
      }

      for (j = i; j < l; j++) {
        num = s[j - i] - 'a';
        n[num]--;
        num = s[j] - 'a';
        n[num]++;
        if (n[num] >= th) {
          printf("%d %d\n", j - i + 2, j + 1);
          return 0;
        }
      }
    }
  }

  printf("-1 -1\n");

  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>

int main(void) {
  char s[100000];
  int l;
  int i, j;
  int n[26] = {};
  int th;
  int num;

  scanf("%s", s);

  l = strlen(s);

  for (i = 2; i <= 2; i++) {
    th = i / 2 + 1;

    for (j = 0; j < 26; j++) {
      n[j] = 0;
    }

    for (j = 0; j < i; j++) {
      num = s[j] - 'a';
      n[num]++;
      if (n[num] >= th) {
        printf("%d %d\n", 1, i);
        return 0;
      }
    }

    for (j = i; j < l; j++) {
      num = s[j - i] - 'a';
      n[num]--;
      num = s[j] - 'a';
      n[num]++;
      if (n[num] >= th) {
        printf("%d %d\n", j - i + 2, j + 1);
        return 0;
      }
    }
  }
  if (l > 2) {
    for (i = 3; i <= 3; i += 2) {
      th = i / 2 + 1;

      for (j = 0; j < 26; j++) {
        n[j] = 0;
      }

      for (j = 0; j < i; j++) {
        num = s[j] - 'a';
        n[num]++;
        if (n[num] >= th) {
          printf("%d %d\n", 1, i);
          return 0;
        }
      }

      for (j = i; j < l; j++) {
        num = s[j - i] - 'a';
        n[num]--;
        num = s[j] - 'a';
        n[num]++;
        if (n[num] >= th) {
          printf("%d %d\n", j - i + 2, j + 1);
          return 0;
        }
      }
    }
  }

  printf("-1 -1\n");

  return 0;
}
Problem p04032 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
char a[101];
using namespace std;
int main() {
  cin >> a + 1;
  int flag = 0;
  int len = strlen(a + 1);
  for (int i = 1; i < len; i++) {
    if (i + 1 <= len && a[i + 1] == a[i]) {
      cout << i << " " << i + 1 << endl;
      flag = 1;
      break;
    }
    if (i + 2 <= len && a[i + 2] == a[i]) {
      cout << i << " " << i + 2 << endl;
      flag = 1;
      break;
    }
  }
  if (flag == 0)
    cout << "-1 -1" << endl;
}

Fixed submission:
#include <cstring>
#include <iostream>
char a[1000000];
using namespace std;
int main() {
  cin >> a + 1;
  int flag = 0;
  int len = strlen(a + 1);
  for (int i = 1; i < len; i++) {
    if (i + 1 <= len && a[i + 1] == a[i]) {
      cout << i << " " << i + 1 << endl;
      flag = 1;
      break;
    }
    if (i + 2 <= len && a[i + 2] == a[i]) {
      cout << i << " " << i + 2 << endl;
      flag = 1;
      break;
    }
  }
  if (flag == 0)
    cout << "-1 -1" << endl;
}
Problem p04032 (C++)

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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = i + 1; j < s.size(); ++j) {
      int n[26] = {};
      for (int k = i; k <= j; ++k) {
        n[s[k] - 'a']++;
      }
      auto mx = *max_element(begin(n), end(n));
      if (mx * 2 > j - i + 1) {
        cout << i + 1 << " " << j + 1 << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    if (i < s.size() - 1 && s[i] == s[i + 1]) {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
    if (i < s.size() - 2 && s[i] == s[i + 2]) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}
Problem p04032 (C++)

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

int cnt[50];
int pos[50][100002];
char str[100002];

int main() {

  // Init
  for (int i = 0; i < 50; i++) {
    cnt[i] = 0;
  }

  // Input
  cin >> str;
  for (int i = 0; i < strlen(str); i++) {
    pos[str[i] - 'a'][cnt[str[i] - 'a']++] = i;
  }

  // Solve
  for (int i = 'a'; i <= 'z'; i++) {
    int lk = i - 'a';
    for (int j = 0; j < cnt[lk]; j++) {
      for (int k = j + 1; k < cnt[lk]; k++) {
        int len = pos[lk][k] - pos[lk][j] + 1;
        if (len / 2 < k - j + 1) {
          cout << pos[lk][j] + 1 << " " << pos[lk][k] + 1 << endl;
          return (0);
        }
      }
    }
  }

  cout << "-1 -1" << endl;
  return (0);
}

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

int cnt[50];
int pos[50][100002];
char str[100002];

int main() {

  // Init
  for (int i = 0; i < 50; i++) {
    cnt[i] = 0;
  }

  // Input
  cin >> str;
  for (int i = 0; i < strlen(str); i++) {
    pos[str[i] - 'a'][cnt[str[i] - 'a']++] = i;
  }

  // Solve
  for (int i = 'a'; i <= 'z'; i++) {
    int lk = i - 'a';
    for (int j = 0; j < cnt[lk]; j++) {
      for (int k = j + 1; k < cnt[lk]; k++) {
        int len = pos[lk][k] - pos[lk][j] + 1;
        if (len / 2 < k - j + 1) {
          cout << pos[lk][j] + 1 << " " << pos[lk][k] + 1 << endl;
          return (0);
        } else
          break;
      }
    }
  }

  cout << "-1 -1" << endl;
  return (0);
}
Problem p04032 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FIO                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define pii pair<ll, ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define calc_fact(n) tgamma(n + 1)
#define INF LONG_LONG_MAX

pii solve(string s, char ch) {
  vi v;
  pii p;
  for (ll i = 0; i < s.length(); i++) {
    if (s[i] == ch)
      v.pb(i);
  }
  if (v.size() <= 1) {
    p.F = -1;
    p.S = -1;
    return p;
  }
  ll j = 0;
  for (ll i = 1; i < v.size(); i++) {
    while (v[i] - v[j] + 1 >= 2 * (i - j + 1) and i - 1 > j)
      j++;

    if (i > j and v[i] - v[j] + 1 < (i - j + 1) * 2) {
      p.F = v[j] + 1;
      p.S = v[i] + 1;
      return p;
    }
  }
}

signed main() {
  FIO;
  string s;
  cin >> s;
  set<char> st;
  for (ll i = 0; i < s.length(); i++)
    st.insert(s[i]);

  for (auto it : st) {
    pii p = solve(s, it);
    if (p.F != -1 and p.S != -1) {
      cout << p.F << " " << p.S;
      goto h;
    }
  }
  cout << "-1 -1";
h:;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FIO                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define pii pair<ll, ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define calc_fact(n) tgamma(n + 1)
#define INF LONG_LONG_MAX

pii solve(string s, char ch) {
  vi v;
  pii p;
  for (ll i = 0; i < s.length(); i++) {
    if (s[i] == ch)
      v.pb(i);
  }
  if (v.size() <= 1) {
    p.F = -1;
    p.S = -1;
    return p;
  }
  ll j = 0;
  for (ll i = 1; i < v.size(); i++) {
    while (v[i] - v[j] + 1 >= 2 * (i - j + 1) and i - 1 > j)
      j++;

    if (i > j and v[i] - v[j] + 1 < (i - j + 1) * 2) {
      p.F = v[j] + 1;
      p.S = v[i] + 1;
      return p;
    }
  }

  p.F = -1;
  p.S = -1;
  return p;
}

signed main() {
  FIO;
  string s;
  cin >> s;
  set<char> st;
  for (ll i = 0; i < s.length(); i++)
    st.insert(s[i]);

  for (auto it : st) {
    pii p = solve(s, it);
    if (p.F != -1 and p.S != -1) {
      cout << p.F << " " << p.S;
      goto h;
    }
  }
  cout << "-1 -1";
h:;
}
Problem p04032 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define reg(i, a, b) for (int i = ((int)(a)); i <= ((int)(b)); i++)
#define irep(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define ireg(i, a, b) for (int i = ((int)(b)); i >= ((int)(a)); i--)
typedef long long int lli;
typedef pair<int, int> mp;

char s[500];
int main() {
  scanf("%s", s);
  int len = strlen(s);
  int flg = 1;
  reg(i, 0, len - 2) {
    if (s[i] == s[i + 1]) {
      flg = 0;
      printf("%d %d\n", i + 1, i + 2);
      break;
    }
  }
  if (flg) {
    reg(i, 0, len - 3) {
      if (s[i] == s[i + 2]) {
        flg = 2;
        printf("%d %d\n", i + 1, i + 3);
        break;
      }
    }
  }
  if (flg == 1)
    printf("-1 -1\n");

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define reg(i, a, b) for (int i = ((int)(a)); i <= ((int)(b)); i++)
#define irep(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define ireg(i, a, b) for (int i = ((int)(b)); i >= ((int)(a)); i--)
typedef long long int lli;
typedef pair<int, int> mp;

char s[500000];
int main() {
  scanf("%s", s);
  int len = strlen(s);
  int flg = 1;
  reg(i, 0, len - 2) {
    if (s[i] == s[i + 1]) {
      flg = 0;
      printf("%d %d\n", i + 1, i + 2);
      break;
    }
  }
  if (flg) {
    reg(i, 0, len - 3) {
      if (s[i] == s[i + 2]) {
        flg = 2;
        printf("%d %d\n", i + 1, i + 3);
        break;
      }
    }
  }
  if (flg == 1)
    printf("-1 -1\n");

  return 0;
}
Problem p04032 (C++)

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

int main() {
  string s;
  cin >> s;
  if (s.size() == 2) {
    if (s.at(0) == s.at(1)) {
      cout << 1 << " " << 2 << endl;
    } else {
      cout << -1 << " " << -1 << endl;
    }
    return 0;
  }
  for (int i = 0; i <= s.size() - 2; i++) {
    if (s.at(i) == s.at(i + 1) || s.at(i + 1) == s.at(i + 2) ||
        s.at(i + 2) == s.at(i)) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s.size() == 2) {
    if (s.at(0) == s.at(1)) {
      cout << 1 << " " << 2 << endl;
    } else {
      cout << -1 << " " << -1 << endl;
    }
    return 0;
  }
  for (int i = 0; i < s.size() - 2; i++) {
    if (s.at(i) == s.at(i + 1) || s.at(i + 1) == s.at(i + 2) ||
        s.at(i + 2) == s.at(i)) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}