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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int, int>
#define vp vector<P>
#define PP pair<P, int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1 << 30)
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
int main() {
  vs st(3);
  REP(i, 3) { cin >> st[i]; }
  queue<int> q[3];
  REP(i, 3) {
    REP(j, st[i].size()) { q[i].push(st[i][j] - 'a'); }
  }
  int now = 0;
  while (1) {
    if (q[now].size() == 0) {
      cout << (char)('A' + now) << endl;
    }
    int t = q[now].front();
    q[now].pop();
    now = t;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int, int>
#define vp vector<P>
#define PP pair<P, int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1 << 30)
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
int main() {
  vs st(3);
  REP(i, 3) { cin >> st[i]; }
  queue<int> q[3];
  REP(i, 3) {
    REP(j, st[i].size()) { q[i].push(st[i][j] - 'a'); }
  }
  int now = 0;
  while (1) {
    if (q[now].size() == 0) {
      cout << (char)('A' + now) << endl;
      return 0;
    }
    int t = q[now].front();
    q[now].pop();
    now = t;
  }
  return 0;
}
Problem p03998 (C++)

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

int main() {
  string v[3];
  for (ll i = 0; i < 3; ++i) {
    cin >> v[i];
  }
  char ans;
  ll flag = 0;

  bool bol = true;
  while (bol) {
    if (v[flag].size() == 0) {
      if (flag == 0) {
        ans = 'A';
      } else if (flag == 1) {
        ans = 'B';
      } else if (flag = 2) {
        ans = 'C';
      }
    } else if (v[flag][0] == 'a') {
      v[flag] = v[flag].substr(1, v[flag].size());
      flag = 0;
    } else if (v[flag][0] == 'b') {
      v[flag] = v[flag].substr(1, v[flag].size());
      flag = 1;
    } else if (v[flag][0] == 'c') {
      v[flag] = v[flag].substr(1, v[flag].size());
      flag = 2;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  string v[3];
  for (ll i = 0; i < 3; ++i) {
    cin >> v[i];
  }
  char ans;
  ll flag = 0;

  bool bol = true;
  while (bol) {
    if (v[flag].size() == 0) {
      if (flag == 0) {
        ans = 'A';
      } else if (flag == 1) {
        ans = 'B';
      } else if (flag = 2) {
        ans = 'C';
      }
      bol = false;
    } else if (v[flag][0] == 'a') {
      v[flag] = v[flag].substr(1, v[flag].size());
      flag = 0;
    } else if (v[flag][0] == 'b') {
      v[flag] = v[flag].substr(1, v[flag].size());
      flag = 1;
    } else if (v[flag][0] == 'c') {
      v[flag] = v[flag].substr(1, v[flag].size());
      flag = 2;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03998 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  sa.push_back('A');
  sa.push_back('B');
  sa.push_back('C');

  char nt = 'a';
  while (1) {
    if (nt == 'A') {
      cout << 'A' << endl;
      return 0;
    } else if (nt == 'B') {
      cout << 'B' << endl;
      return 0;
    } else if (nt == 'C') {
      cout << 'C' << endl;
      return 0;
    } else if (nt == 'a') {
      nt = sa[0];
      sa = sa.substr(1);
    } else if (nt == 'b') {
      nt = sb[0];
      sb = sb.substr(1);
    } else if (nt == 'c') {
      nt = sc[0];
      sc = sc.substr(1);
    }
  }

  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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  sa.push_back('A');
  sb.push_back('B');
  sc.push_back('C');

  char nt = 'a';
  while (1) {
    if (nt == 'A') {
      cout << 'A' << endl;
      return 0;
    } else if (nt == 'B') {
      cout << 'B' << endl;
      return 0;
    } else if (nt == 'C') {
      cout << 'C' << endl;
      return 0;
    } else if (nt == 'a') {
      nt = sa[0];
      sa = sa.substr(1);
    } else if (nt == 'b') {
      nt = sb[0];
      sb = sb.substr(1);
    } else if (nt == 'c') {
      nt = sc[0];
      sc = sc.substr(1);
    }
  }

  return 0;
}
Problem p03998 (C++)

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

using namespace std;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  lli len1, len2, len3, x = 0, y = 0, z = 0;
  len1 = a.length();
  len2 = b.length();
  len3 = c.length();
  lli flag = 1;
  while (1) {
    if (flag == 1 && x == len1) {
      cout << "A\n";
      break;
    } else if (flag == 2 && y == len2) {
      cout << "B\n";
      break;
    } else if (flag == 3 && z == len3) {
      cout << "C\n";
    } else if (flag == 1) {
      if (a[x] == 'a') {
        flag = 1;
      } else if (a[x] == 'b') {
        flag = 2;
      } else {
        flag = 3;
      }
      x++;
    } else if (flag == 2) {
      if (b[y] == 'a') {
        flag = 1;
      } else if (b[y] == 'b') {
        flag = 2;
      } else {
        flag = 3;
      }
      y++;
    } else {
      if (c[z] == 'a') {
        flag = 1;
      } else if (c[z] == 'b') {
        flag = 2;
      } else {
        flag = 3;
      }
      z++;
    }
  }

  // cout << "Hello world!" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  lli len1, len2, len3, x = 0, y = 0, z = 0;
  len1 = a.length();
  len2 = b.length();
  len3 = c.length();
  lli flag = 1;
  while (1) {
    if (flag == 1 && x == len1) {
      cout << "A\n";
      break;
    } else if (flag == 2 && y == len2) {
      cout << "B\n";
      break;
    } else if (flag == 3 && z == len3) {
      cout << "C\n";
      break;
    } else if (flag == 1) {
      if (a[x] == 'a') {
        flag = 1;
      } else if (a[x] == 'b') {
        flag = 2;
      } else {
        flag = 3;
      }
      x++;
    } else if (flag == 2) {
      if (b[y] == 'a') {
        flag = 1;
      } else if (b[y] == 'b') {
        flag = 2;
      } else {
        flag = 3;
      }
      y++;
    } else {
      if (c[z] == 'a') {
        flag = 1;
      } else if (c[z] == 'b') {
        flag = 2;
      } else {
        flag = 3;
      }
      z++;
    }
  }

  // cout << "Hello world!" << endl;
  return 0;
}
Problem p03998 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long int;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int flag = 0;
  int i, j, k = 0;
  while (1) {
    if (flag == 0) {
      if (a.size() == i) {
        cout << 'A' << endl;
        return 0;
      }
      if (a[i] == 'a') {
        flag = 0;
      } else if (a[i] == 'b') {
        flag = 1;
      } else {
        flag = 2;
      }
      i++;
    } else if (flag == 1) {
      if (b.size() == j) {
        cout << 'B' << endl;
        return 0;
      }
      if (b[j] == 'a') {
        flag = 0;
      } else if (b[j] == 'b') {
        flag = 1;
      } else {
        flag = 2;
      }
      j++;
    } else {
      if (c.size() == k) {
        cout << 'C' << endl;
        return 0;
      }
      if (c[k] == 'a') {
        flag = 0;
      } else if (c[k] == 'b') {
        flag = 1;
      } else {
        flag = 2;
      }
      k++;
    }
  }
}


Fixed submission:
#include <algorithm>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long int;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int flag = 0;
  int i = 0;
  int j = 0;
  int k = 0;
  while (1) {
    if (flag == 0) {
      if (a.size() == i) {
        cout << 'A' << endl;
        return 0;
      }
      if (a[i] == 'a') {
        flag = 0;
      } else if (a[i] == 'b') {
        flag = 1;
      } else {
        flag = 2;
      }
      i++;
    } else if (flag == 1) {
      if (b.size() == j) {
        cout << 'B' << endl;
        return 0;
      }
      if (b[j] == 'a') {
        flag = 0;
      } else if (b[j] == 'b') {
        flag = 1;
      } else {
        flag = 2;
      }
      j++;
    } else {
      if (c.size() == k) {
        cout << 'C' << endl;
        return 0;
      }
      if (c[k] == 'a') {
        flag = 0;
      } else if (c[k] == 'b') {
        flag = 1;
      } else {
        flag = 2;
      }
      k++;
    }
  }
}
Problem p03998 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  vector<int> cnt(3, 0), upper(3);
  vector<string> s(3);
  for (int i = 0; i < 3; i++) {
    cin >> s[i];
    upper[i] = s[i].size();
  }

  int cur = 0;
  while (true) {
    if (cnt[cur] == upper[cur]) {
      printf("%c\n", 'A' + cur);
      return 0;
    }
    int cur = s[cur][cnt[cur]++] - 'a';
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  vector<int> cnt(3, 0), upper(3);
  vector<string> s(3);
  for (int i = 0; i < 3; i++) {
    cin >> s[i];
    upper[i] = s[i].size();
  }

  int cur = 0;
  while (true) {
    if (cnt[cur] == upper[cur]) {
      printf("%c\n", 'A' + cur);
      return 0;
    }
    int ne = s[cur][cnt[cur]] - 'a';
    cnt[cur]++;
    cur = ne;
  }
}
Problem p03998 (Python)

Buggy submission (status: Runtime Error):
a = list(input())
b = list(input())
c = list(input())

n = a[0]
del a[0]
if len(a) == 0:
    print("A")
while True:
    if n == "a":
        n = a[0]
        del a[0]
        if len(a) == 0:
            print("A")
            break
    elif n == "b":
        n = b[0]
        del b[0]
        if len(b) == 0:
            print("B")
            break
    elif n == "c":
        n = c[0]
        del c[0]
        if len(c) == 0:
            print("C")
            break


Fixed submission:
a = list(input())
b = list(input())
c = list(input())

n = a[0]
if len(a) < 1:
    del a[0]

while True:
    if n == "a":
        n = a[0]
        del a[0]
        if len(a) == 0:
            print("A")
            break
    elif n == "b":
        n = b[0]
        del b[0]
        if len(b) == 0:
            print("B")
            break
    elif n == "c":
        n = c[0]
        del c[0]
        if len(c) == 0:
            print("C")
            break
Problem p03998 (C++)

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

int main() {
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  int i = 0;
  while (true) {
    if (s[i].size() == 0) {
      cout << char('A' + i) << endl;
      return 0;
    }
    char c = s[i][0];
    s[i].erase(0, 0);
    i = c - 'a';
  }
}


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

int main() {
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  int i = 0;
  while (true) {
    if (s[i].size() == 0) {
      cout << char('A' + i) << endl;
      return 0;
    }
    char c = s[i][0];
    s[i].erase(0, 1);
    i = c - 'a';
  }
}
Problem p03998 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int, int>;
using pq = priority_queue<int>;
typedef long long ll;
typedef long double ld;
#define pi 3.14159265358979

int main() {
  string s[3];
  rep(i, 3) cin >> s[i];
  map<char, int> mp;
  mp['a'] = 0;
  mp['b'] = 1;
  mp['c'] = 2;
  vector<queue<char>> q(3);
  rep(i, 3) {
    rep(j, s[i].size()) { q[i].push(s[i][j]); }
  }
  char f = s[0].front();
  q[0].pop();
  char tmp;
  while (1) {
    tmp = q[mp[f]].front();
    q[mp[f]].pop();
    f = tmp;
    if (q[mp[f]].empty()) {
      char ans = 'A' + mp[f];
      cout << ans << endl;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int, int>;
using pq = priority_queue<int>;
typedef long long ll;
typedef long double ld;
#define pi 3.14159265358979

int main() {
  string s[3];
  rep(i, 3) cin >> s[i];
  map<char, int> mp;
  mp['a'] = 0;
  mp['b'] = 1;
  mp['c'] = 2;
  vector<queue<char>> q(3);
  rep(i, 3) {
    rep(j, s[i].size()) { q[i].push(s[i][j]); }
  }
  char f = s[0].front();
  q[0].pop();
  char tmp;
  while (1) {
    if (!q[mp[f]].empty()) {
      tmp = q[mp[f]].front();
      q[mp[f]].pop();
    }
    f = tmp;
    if (q[mp[f]].empty()) {
      char ans = 'A' + mp[f];
      cout << ans << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03998 (C++)

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i < 100; i++) {
    a += " ";
    b += " ";
    c += " ";
  }
  deque<char> A, B, C;
  for (int i = 0; i < 108; i++) {
    A.push_back(a.at(i));
    B.push_back(b.at(i));
    C.push_back(c.at(i));
  }
  char symbol = 'a';
  while (true) {
    if (symbol == 'a') {
      if (A.front() == ' ') {
        cout << "A" << endl;
        break;
      } else {
        symbol = A.front();
        A.pop_front();
      }
    } else if (symbol == 'b') {
      if (B.front() == ' ') {
        cout << "B" << endl;
        break;
      } else {
        symbol = B.front();
        B.pop_front();
      }
    } else {
      if (C.front() == ' ') {
        cout << "C" << endl;
        break;
      } else {
        symbol = C.front();
        C.pop_front();
      }
    }
  }
}

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i < 110; i++) {
    a += " ";
    b += " ";
    c += " ";
  }
  deque<char> A, B, C;
  for (int i = 0; i < 108; i++) {
    A.push_back(a.at(i));
    B.push_back(b.at(i));
    C.push_back(c.at(i));
  }
  char symbol = 'a';
  while (true) {
    if (symbol == 'a') {
      if (A.front() == ' ') {
        cout << "A" << endl;
        break;
      } else {
        symbol = A.front();
        A.pop_front();
      }
    } else if (symbol == 'b') {
      if (B.front() == ' ') {
        cout << "B" << endl;
        break;
      } else {
        symbol = B.front();
        B.pop_front();
      }
    } else {
      if (C.front() == ' ') {
        cout << "C" << endl;
        break;
      } else {
        symbol = C.front();
        C.pop_front();
      }
    }
  }
}
Problem p03998 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, p, n) for (int i = (int)p; i < (int)n; i++)
#define rrep(i, p, n) for (int i = (int)p; i >= (int)n; i--)
#define lli long long int
#define vi vector<int>

using namespace std;

void p(int x) { cout << x << endl; }

void pp(string s) { cout << s << endl; }

int main() {
  char mode = 'a';
  string sa, sb, sc;
  cin >> sa >> sb >> sc;

  while (1) {
    if (mode == 'a') {
      if (sa.empty()) {
        cout << "A" << endl;
        break;
      } else {
        mode = *(sa.begin());
        sa.erase(sa.begin());
      }
    }

    else if (mode == 'b') {
      if (sb.empty()) {
        cout << "B" << endl;
        break;
      } else {
        mode = *(sb.begin());
        sb.erase(sb.begin());
      }
    }

    else if (mode == 'c') {
      if (sa.empty()) {
        cout << "C" << endl;
        break;
      } else {
        mode = *(sc.begin());
        sc.erase(sc.begin());
      }
    }
  }

  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, p, n) for (int i = (int)p; i < (int)n; i++)
#define rrep(i, p, n) for (int i = (int)p; i >= (int)n; i--)
#define lli long long int
#define vi vector<int>

using namespace std;

void p(int x) { cout << x << endl; }

void pp(string s) { cout << s << endl; }

int main() {
  char mode = 'a';
  string sa, sb, sc;
  cin >> sa >> sb >> sc;

  while (1) {
    if (mode == 'a') {
      if (sa.empty()) {
        cout << "A" << endl;
        break;
      } else {
        mode = *(sa.begin());
        sa.erase(sa.begin());
      }
    }

    else if (mode == 'b') {
      if (sb.empty()) {
        cout << "B" << endl;
        break;
      } else {
        mode = *(sb.begin());
        sb.erase(sb.begin());
      }
    }

    else if (mode == 'c') {
      if (sc.empty()) {
        cout << "C" << endl;
        break;
      } else {
        mode = *(sc.begin());
        sc.erase(sc.begin());
      }
    }
  }

  return 0;
}
Problem p03998 (Python)

Buggy submission (status: Runtime Error):
d = dict(a=input(), b=input(), c=input())
op = "a"
while True:
    if not d[op]:
        print(op.upper())
        break
    op = d[op].pop(0)


Fixed submission:
d = dict(a=list(input()), b=list(input()), c=list(input()))
op = "a"
while True:
    if not d[op]:
        print(op.upper())
        break
    op = d[op].pop(0)
Problem p03998 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  ll la = sa.size(), lb = sb.size(), lc = sc.size();
  char ch = 'a';
  ll a = 0, b = 0, c = 0;
  while (1) {
    if (ch == 'a' && a >= la) {
      cout << 'A';
      break;
      return 0;
    }
    if (ch == 'b' && b >= lb) {
      cout << 'B';
      break;
      return 0;
    }
    if (ch == 'c' && c >= lc) {
      cout << 'C';
      break;
      return 0;
    }
    if (ch == 'a') {
      ch = sa.at(a);
      a++;
    } else if (c == 'b') {
      ch = sb.at(b);
      b++;
    } else {
      ch = sc.at(c);
      c++;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  ll la = sa.size(), lb = sb.size(), lc = sc.size();
  char ch = 'a';
  ll a = 0, b = 0, c = 0;
  while (1) {
    if (ch == 'a' && a >= la) {
      cout << 'A';
      break;
      return 0;
    }
    if (ch == 'b' && b >= lb) {
      cout << 'B';
      break;
      return 0;
    }
    if (ch == 'c' && c >= lc) {
      cout << 'C';
      break;
      return 0;
    }
    if (ch == 'a') {
      ch = sa.at(a);
      a++;
    } else if (ch == 'b') {
      ch = sb.at(b);
      b++;
    } else {
      ch = sc.at(c);
      c++;
    }
  }
}
Problem p03998 (C++)

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

using namespace std;

int main(void) {
  vector<string> v(3);
  cin >> v[0] >> v[1] >> v[2];

  int now = 0;
  while (1) {
    if (v[now].size() == 0) {
      if (now == 0)
        cout << "A" << endl;
      else if (now == 1)
        cout << "B" << endl;
      else
        cout << "C" << endl;
    }

    int tmp = now;
    if (v[now][0] == 'a') {
      now = 0;
    } else if (v[now][0] == 'b') {
      now = 1;
    } else {
      now = 2;
    }
    v[tmp].erase(v[tmp].begin());
  }
}

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

using namespace std;

int main(void) {
  vector<string> v(3);
  cin >> v[0] >> v[1] >> v[2];

  int now = 0;
  while (1) {
    if (v[now].size() == 0) {
      if (now == 0)
        cout << "A" << endl;
      else if (now == 1)
        cout << "B" << endl;
      else
        cout << "C" << endl;
      return 0;
    }

    int tmp = now;
    if (v[now][0] == 'a') {
      now = 0;
    } else if (v[now][0] == 'b') {
      now = 1;
    } else {
      now = 2;
    }
    v[tmp].erase(v[tmp].begin());
  }
}
Problem p03998 (C++)

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

int main() {
  int p = 1, ac = 1, bc = 0, cc = 0;
  string a, b, c;
  cin >> a >> b >> c;
  char x = a.at(0);
  while (p = 1) {
    if (x == 'a') {
      x = a.at(ac);
      ac++;
    } else if (x == 'b') {
      x = b.at(bc);
      bc++;
    } else if (x == 'c') {
      x = c.at(cc);
      cc++;
    }
    if (ac == a.size() && x == 'a') {
      cout << "A" << endl;
      return 0;
    } else if (bc == b.size() && x == 'b') {
      cout << "B" << endl;
      return 0;
    } else if (cc == c.size() && x == 'c') {
      cout << "C" << endl;
      return 0;
    }
  }
}


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

int main() {
  int p = 1, ac = 1, bc = 0, cc = 0;
  string a, b, c;
  cin >> a >> b >> c;
  char x = a.at(0);
  if (a == "a") {
    cout << "A" << endl;
    return 0;
  }
  while (p = 1) {
    if (x == 'a') {
      x = a.at(ac);
      ac++;
    } else if (x == 'b') {
      x = b.at(bc);
      bc++;
    } else if (x == 'c') {
      x = c.at(cc);
      cc++;
    }
    if (ac == a.size() && x == 'a') {
      cout << "A" << endl;
      return 0;
    } else if (bc == b.size() && x == 'b') {
      cout << "B" << endl;
      return 0;
    } else if (cc == c.size() && x == 'c') {
      cout << "C" << endl;
      return 0;
    }
  }
}
Problem p03998 (C++)

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

using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star; // 処理早くするためのおまじない
int main() {

  string Sa, Sb, Sc;
  cin >> Sa >> Sb >> Sc;

  string next;
  next.push_back(Sa[0]);

  while (true) {
    if (next == "a") {
      if (Sa.empty()) {
        cout << "A" << endl;
        break;
      }
      next = *Sa.begin();
      Sa.erase(Sa.begin());
    }
    if (next == "b") {
      if (Sb.empty()) {
        cout << "B" << endl;
        break;
      }
      next = *Sb.begin();
      Sb.erase(Sb.begin());
    }
    if (next == "c") {
      if (Sa.empty()) {
        cout << "C" << endl;
        break;
      }
      next = *Sc.begin();
      Sc.erase(Sc.begin());
    }
  }
  return 0;
}


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

using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star; // 処理早くするためのおまじない
int main() {

  string Sa, Sb, Sc;
  cin >> Sa >> Sb >> Sc;

  string next;
  next.push_back(Sa[0]);

  while (true) {
    if (next == "a") {
      if (Sa.empty()) {
        cout << "A" << endl;
        break;
      }
      next = *Sa.begin();
      Sa.erase(Sa.begin());
    }
    if (next == "b") {
      if (Sb.empty()) {
        cout << "B" << endl;
        break;
      }
      next = *Sb.begin();
      Sb.erase(Sb.begin());
    }
    if (next == "c") {
      if (Sc.empty()) {
        cout << "C" << endl;
        break;
      }
      next = *Sc.begin();
      Sc.erase(Sc.begin());
    }
  }
  return 0;
}
Problem p03998 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  string s, t, u;
  cin >> s >> t >> u;
  int turn = 0;
  int si = 0, ti = 0, ui = 0;
  while (1) {
    if (turn == 'a' - 'a') {
      if (si == s.length()) {
        cout << 'A' << endl;
        break;
      }
      turn = s[si] - 'a';
      si++;
    }
    if (turn == 'b' - 'a') {
      if (ti == t.length()) {
        cout << 'B' << endl;
        break;
      }
      turn = t[ti] - 'a';
      ti++;
    }
    if (turn == 'c' - 'a') {
      if (si == s.length()) {
        cout << 'C' << endl;
        break;
      }
      turn = u[ui] - 'a';
      ui++;
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  string s, t, u;
  cin >> s >> t >> u;
  int turn = 0;
  int si = 0, ti = 0, ui = 0;
  while (1) {
    if (turn == 'a' - 'a') {
      if (si == s.length()) {
        cout << 'A' << endl;
        break;
      }
      turn = s[si] - 'a';
      si++;
    }
    if (turn == 'b' - 'a') {
      if (ti == t.length()) {
        cout << 'B' << endl;
        break;
      }
      turn = t[ti] - 'a';
      ti++;
    }
    if (turn == 'c' - 'a') {
      if (ui == u.length()) {
        cout << 'C' << endl;
        break;
      }
      turn = u[ui] - 'a';
      ui++;
    }
  }
  return 0;
}
Problem p03998 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
using namespace std;
void card(char, int);
int p = 0;
int main() {
  char a[101], b[101], c[101];
  int i = 0, j = 0, k = 0;
  scanf("%s%s%s", a, b, c);
  while (1) {
    if (p == 0) {
      card(a[i], 0);
      i++;
    } else if (p == 1) {
      card(b[j], 1);
      j++;
    } else if (p == 2) {
      card(c[j], 2);
      k++;
    } else
      break;
  }
  return 0;
}
void card(char a, int b) {
  if (a == 'a') {
    p = 0;
    return;
  } else if (a == 'b') {
    p = 1;
    return;
  } else if (a == 'c') {
    p = 2;
    return;
  } else {
    if (b == 0) {
      cout << "A" << endl;
    }
    if (b == 1) {
      cout << "B" << endl;
    }
    if (b == 2) {
      cout << "C" << endl;
    }
    p = 4;
    return;
  }
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
void card(char, int);
int p = 0;
int main() {
  char a[101], b[101], c[101];
  int i = 0, j = 0, k = 0;
  scanf("%s%s%s", a, b, c);
  while (1) {
    if (p == 0) {
      card(a[i], 0);
      i++;
    } else if (p == 1) {
      card(b[j], 1);
      j++;
    } else if (p == 2) {
      card(c[k], 2);
      k++;
    } else
      break;
  }
  return 0;
}
void card(char a, int b) {
  if (a == 'a') {
    p = 0;
    return;
  } else if (a == 'b') {
    p = 1;
    return;
  } else if (a == 'c') {
    p = 2;
    return;
  } else {
    if (b == 0) {
      cout << "A" << endl;
    }
    if (b == 1) {
      cout << "B" << endl;
    }
    if (b == 2) {
      cout << "C" << endl;
    }
    p = 4;
    return;
  }
}
Problem p03998 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>
using namespace std;

#define INF 1000000
#define REP(i, n) for (int i = 0; i < (int)n; ++i)

#ifdef _MSC_VER
#define FOR(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#else
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#endif

#define ALL(c) (c).begin(), (c).end()

int main() {
  // char a[100], b[100], c[100];

  string abc[3];
  cin >> abc[0] >> abc[1] >> abc[2];
  int id[3];
  int len[3];
  int num = 0;
  for (int i = 0; i < 3; i++) {
    id[i] = 0;
    len[i] = abc[i].size();
  }

  while (1) {
    if (len[num] == id[num]) {
      if (num == 0) {
        cout << "A" << endl;
      } else if (num == 1) {
        cout << "B" << endl;
      } else {
        cout << "C" << endl;
      }
      break;
    }
    id[num]++;
    num = abc[num].at(id[num]) - 'a';
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>
using namespace std;

#define INF 1000000
#define REP(i, n) for (int i = 0; i < (int)n; ++i)

#ifdef _MSC_VER
#define FOR(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#else
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#endif

#define ALL(c) (c).begin(), (c).end()

int main() {
  // char a[100], b[100], c[100];

  string abc[3];
  cin >> abc[0] >> abc[1] >> abc[2];
  int id[3];
  int len[3];
  int num = 0;
  for (int i = 0; i < 3; i++) {
    id[i] = 0;
    len[i] = abc[i].size();
  }

  while (1) {
    if (len[num] == id[num]) {
      if (num == 0) {
        cout << "A" << endl;
      } else if (num == 1) {
        cout << "B" << endl;
      } else {
        cout << "C" << endl;
      }
      break;
    }
    id[num]++;
    num = abc[num].at(id[num] - 1) - 'a';
  }

  return 0;
}
Problem p03998 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T> T sq(T x) { return x * x; }

signed main() {
  string S1, S2, S3;
  cin >> S1;
  cin >> S2;
  cin >> S3;

  char next = S1.at(0);
  S1.erase(0, 1);
  cout << next << S1.at(0) << endl;
  for (int i = 0; i < 300; i++) {

    // cout  << "next :" << next << endl;
    if (next == 'a') {
      if (S1.empty()) {
        cout << "A" << endl;
        return 0;
      }
      next = S1.at(0);
      S1.erase(0, 1);
    } else if (next == 'b') {
      if (S2.empty()) {
        cout << "B" << endl;
        return 0;
      }
      next = S2.at(0);
      S2.erase(0, 1);
    } else if (next == 'c') {
      if (S3.empty()) {
        cout << "C" << endl;
        return 0;
      }
      next = S3.at(0);
      S3.erase(0, 1);
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T> T sq(T x) { return x * x; }

signed main() {
  string S1, S2, S3;
  cin >> S1;
  cin >> S2;
  cin >> S3;

  char next = S1.at(0);
  S1.erase(0, 1);
  // cout << next << S1.at(0) <<endl;
  for (int i = 0; i < 300; i++) {

    // cout  << "next :" << next << endl;
    if (next == 'a') {
      if (S1.empty()) {
        cout << "A" << endl;
        return 0;
      }
      next = S1.at(0);
      S1.erase(0, 1);
    } else if (next == 'b') {
      if (S2.empty()) {
        cout << "B" << endl;
        return 0;
      }
      next = S2.at(0);
      S2.erase(0, 1);
    } else if (next == 'c') {
      if (S3.empty()) {
        cout << "C" << endl;
        return 0;
      }
      next = S3.at(0);
      S3.erase(0, 1);
    }
  }

  return 0;
}
Problem p03998 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))    // Reversi rep
#define nfor(i, a, b) for (int(i) = (a); (i) < (b); ++(i))  // Natural for
#define rfor(i, a, b) for (int(i) = (b); (i) >= (a); --(i)) // Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

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

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

int main() {
  string s1, s2, s3, t = "a";
  int c1 = 0, c2 = 0, c3 = 0;
  cin >> s1 >> s2 >> s3;
  while (1) {
    if (t[0] == 'a') {
      if (s1.size() > c1) {
        t[0] = s1[c1];
        ++c1;
      } else {
        cout << "A" << endl;
        return 0;
      }
    } else if (t[0] == 'b') {
      if (s2.size() > c3) {
        t[0] = s2[c2];
        ++c2;
      } else {
        cout << "B" << endl;
        return 0;
      }
    } else if (t[0] == 'c') {
      if (s3.size() > c3) {
        t[0] = s3[c3];
        ++c3;
      } else {
        cout << "C" << endl;
        return 0;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))    // Reversi rep
#define nfor(i, a, b) for (int(i) = (a); (i) < (b); ++(i))  // Natural for
#define rfor(i, a, b) for (int(i) = (b); (i) >= (a); --(i)) // Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

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

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

int main() {
  string s1, s2, s3, t = "a";
  int c1 = 0, c2 = 0, c3 = 0;
  cin >> s1 >> s2 >> s3;
  while (1) {
    if (t[0] == 'a') {
      if (s1.size() > c1) {
        t[0] = s1[c1];
        ++c1;
      } else {
        cout << "A" << endl;
        return 0;
      }
    } else if (t[0] == 'b') {
      if (s2.size() > c2) {
        t[0] = s2[c2];
        ++c2;
      } else {
        cout << "B" << endl;
        return 0;
      }
    } else if (t[0] == 'c') {
      if (s3.size() > c3) {
        t[0] = s3[c3];
        ++c3;
      } else {
        cout << "C" << endl;
        return 0;
      }
    }
  }
}
Problem p03998 (C++)

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

int main() {
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  int turn = 0;
  char c;
  while (true) {
    if (s[turn] == "") {
      cout << (char)('A' + turn) << endl;
    }
    c = s[turn].at(0);
    s[turn] = s[turn].substr(1, s[turn].length() - 1);
    turn = c - 'a';
  }
  return 0;
}

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

int main() {
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  int turn = 0;
  char c;
  while (true) {
    if (s[turn] == "") {
      cout << (char)('A' + turn) << endl;
      return 0;
    }
    c = s[turn].at(0);
    s[turn] = s[turn].substr(1, s[turn].length() - 1);
    turn = c - 'a';
  }
  return 0;
}
Problem p03998 (Python)

Buggy submission (status: Runtime Error):
a_hands = [*input()]
b_hands = [*input()]
c_hands = [*input()]
turn = "a"

while True:
    if turn == "a":
        if len(a_hands) == 0:
            print("A")
            break
        turn = a_hands.pop(0)
    elif turn == "b":
        if len(b_hands) == 0:
            print("B")
            break
        turn = b_hands.pop(0)
    elif turn == "c":
        if len(c_hands) == 0:
            print("C")
            break
        turn = c_hands.pop(0)


Fixed submission:
a_hands = list(input())
b_hands = list(input())
c_hands = list(input())
turn = "a"

while True:
    if turn == "a":
        if len(a_hands) == 0:
            print("A")
            break
        turn = a_hands.pop(0)
    elif turn == "b":
        if len(b_hands) == 0:
            print("B")
            break
        turn = b_hands.pop(0)
    elif turn == "c":
        if len(c_hands) == 0:
            print("C")
            break
        turn = c_hands.pop(0)
Problem p03999 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LOOP(i, x, n) for (int i = x; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000009;

signed main() {
  string s;
  cin >> s;
  int len = s.size();
  int ans = 0;
  int shift = s.size() - 2;
  for (int i = 0; i < (1 << (len - 1)); i++) {
    int index = 0;
    for (int j = shift; j >= -1; j--) {
      string t = "";
      t += s[index++];
      while (1) {
        if (j == -1)
          break;
        if (!(i & (1 << j))) {
          t += s[index++];
          j--;
        } else {
          break;
        }
      }
      int tmp = stoi(t);
      // cout<<tmp<<' ';
      ans += tmp;
    } // cout<<endl;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LOOP(i, x, n) for (int i = x; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000009;

signed main() {
  string s;
  cin >> s;
  int len = s.size();
  int ans = 0;
  int shift = s.size() - 2;
  for (int i = 0; i < (1 << (len - 1)); i++) {
    int index = 0;
    for (int j = shift; j >= -1; j--) {
      string t = "";
      t += s[index++];
      while (1) {
        if (j == -1)
          break;
        if (!(i & (1 << j))) {
          t += s[index++];
          j--;
        } else {
          break;
        }
      }
      int tmp = stoll(t);
      // cout<<tmp<<' ';
      ans += tmp;
    } // cout<<endl;
  }
  cout << ans << endl;
  return 0;
}
Problem p03999 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

// あたまわるわる～

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

  char S[10];
  int N = fread_unlocked(S, 1, 11, stdin);
  N--;

  ll dp[2] = {};
  dp[0] = S[0] - '0';
  rep1(i, N - 1) {
    dp[1] += dp[1];
    dp[1] += dp[0];
    dp[0] = dp[0] * 10 + (S[i] - '0') * (1 << i);
  }
  printf("%lld", dp[0] + dp[1]);

  Would you please return 0;
}

Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

// あたまわるわる～

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

  char S[11];
  int N = fread_unlocked(S, 1, 11, stdin);
  N--;

  ll dp[2] = {};
  dp[0] = S[0] - '0';
  rep1(i, N - 1) {
    dp[1] += dp[1];
    dp[1] += dp[0];
    dp[0] = dp[0] * 10 + (S[i] - '0') * (1 << i);
  }
  printf("%lld", dp[0] + dp[1]);

  Would you please return 0;
}
Problem p03999 (C++)

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

int main() {
  string s;
  cin >> s;
  int l = s.length();
  LL ans = 0;
  LL dig = 1;
  for (int i = 0; i < l - 1; i++)
    dig *= 10;
  ans += (LL)(stoi(s.substr(0, 1))) * dig + stoi(s.substr(1, l - 1));
  for (int i = 1; i < 1 << (l - 1); i++) {
    int id = 0;
    for (int j = 0; j < l - 1; j++) {
      if (i >> j & 1) {
        ans += stoi(s.substr(id, j + 1 - id));
        id = j + 1;
      }
    }
    ans += stoi(s.substr(id, l - id));
  }
  cout << ans << endl;
}

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

int main() {
  string s;
  cin >> s;
  int l = s.length();
  LL ans = 0;
  LL dig = 1;
  for (int i = 0; i < l - 1; i++)
    dig *= 10;
  ans += (LL)(stoi(s.substr(0, 1))) * dig;
  if (l > 1)
    ans += stoi(s.substr(1, l - 1));
  for (int i = 1; i < 1 << (l - 1); i++) {
    int id = 0;
    for (int j = 0; j < l - 1; j++) {
      if (i >> j & 1) {
        ans += stoi(s.substr(id, j + 1 - id));
        id = j + 1;
      }
    }
    ans += stoi(s.substr(id, l - id));
  }
  cout << ans << endl;
}
Problem p03999 (C++)

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

typedef long long ll;

ll ans = 0;

void solve(int n, string s, string S) {
  if (n < S.size()) {
    solve(n + 1, s + S[n], S);
    solve(n + 1, s + "+" + S[n], S);
  } else {
    cerr << s << endl;

    // eval部分
    vector<ll> v;
    string num = "";
    s = s + "+";
    for (int i = 0; i < s.size(); i++) {
      if (s[i] != '+') {
        num = num + s[i];
      } else {
        v.push_back(stoi(num));
        num = "";
      }
    }
    for (auto x : v) {
      ans += x;
    }
  }
}

int main() {
  string S;
  cin >> S;
  string s = "";
  s += S[0];
  solve(1, s, S);
  cout << ans << endl;
}

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

typedef long long ll;

ll ans = 0;

void solve(int n, string s, string S) {
  if (n < S.size()) {
    solve(n + 1, s + S[n], S);
    solve(n + 1, s + "+" + S[n], S);
  } else {
    cerr << s << endl;

    // eval部分
    vector<ll> v;
    string num = "";
    s = s + "+";
    for (int i = 0; i < s.size(); i++) {
      if (s[i] != '+') {
        num = num + s[i];
      } else {
        v.push_back(stoll(num));
        num = "";
      }
    }
    for (auto x : v) {
      ans += x;
    }
  }
}

int main() {
  string S;
  cin >> S;
  string s = "";
  s += S[0];
  solve(1, s, S);
  cout << ans << endl;
}
Problem p03999 (C++)

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

string to_binString(int value, int length) {
  string h;
  if (value == 0) {
    h = "0";
  }
  while (value != 0) {
    if ((value & 1) == 0) {
      h.insert(h.begin(), '0');
    } else {
      h.insert(h.begin(), '1');
    }
    value >>= 1;
  }
  // hを0詰めする
  while (length != h.size()) {
    h.insert(h.begin(), '0');
  }
  return h;
}

int main() {
  string h;
  cin >> h;
  long long forloop = 1;
  for (int i = 0; i < h.size() - 1; i++) {
    forloop *= 2;
  }
  long long ans = 0;
  for (long long i = 0; i < forloop; i++) {
    string s = to_binString(i, h.size() - 1);
    long long before = 0;
    long long sub = 0;
    for (long long j = 0; j < s.size(); j++) {
      if (s[j] == '1') {
        sub += stol(h.substr(before, j - before + 1));
        before = j + 1;
      }
    }
    sub += stol(h.substr(before, h.size() - before));
    ans = ans + sub;
  }
  cout << ans << endl;
}

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

string to_binString(int value, int length) {
  string h;
  if (value == 0) {
    h = "0";
  }
  while (value != 0) {
    if ((value & 1) == 0) {
      h.insert(h.begin(), '0');
    } else {
      h.insert(h.begin(), '1');
    }
    value >>= 1;
  }
  // hを0詰めする
  while (length != h.size()) {
    h.insert(h.begin(), '0');
  }
  return h;
}

int main() {
  string h;
  cin >> h;
  if (h.size() == 1) {
    cout << stoi(h) << endl;
    return 0;
  }
  long long forloop = 1;
  for (int i = 0; i < h.size() - 1; i++) {
    forloop *= 2;
  }
  long long ans = 0;
  for (long long i = 0; i < forloop; i++) {
    string s = to_binString(i, h.size() - 1);
    long long before = 0;
    long long sub = 0;
    for (long long j = 0; j < s.size(); j++) {
      if (s[j] == '1') {
        sub += stol(h.substr(before, j - before + 1));
        before = j + 1;
      }
    }
    sub += stol(h.substr(before, h.size() - before));
    ans = ans + sub;
  }
  cout << ans << endl;
}
Problem p03999 (C++)

Buggy submission (status: Runtime Error):
/**
 * @author torith
 * @date 2018-11-03
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  ll ans = 0;
  for (int i = 0; i < S.size(); ++i) {
    int j = 1;
    while (i + j <= S.size()) {
      int left = pow(2, max(0, i - 1));
      int right = pow(2, max(0, (int)S.size() - i - j - 1));
      ans += stoi(S.substr(i, j)) * left * right;
      j++;
    }
  }

  cout << ans << "\n";

  return 0;
}


Fixed submission:
/**
 * @author torith
 * @date 2018-11-03
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  ll ans = 0;
  for (int i = 0; i < S.size(); ++i) {
    int j = 1;
    while (i + j <= S.size()) {
      int left = pow(2, max(0, i - 1));
      int right = pow(2, max(0, (int)S.size() - i - j - 1));
      ans += stoll(S.substr(i, j)) * left * right;
      j++;
    }
  }

  cout << ans << "\n";

  return 0;
}
Problem p03999 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define f(i, a, b) for (int(i) = int(a); i <= int(b); i++)
#define ff(i, a, b) for (int(i) = int(a); i < int(b); i++)
#define F(i, a, b) for (int(i) = int(a); i >= int(b); i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vt vector
#define ll long long
#define all(x) x.begin(), x.end()
#define lower(p, x) lower_bound(all(p), x)
#define upper(p, x) upper_bound(all(p), x)
#define ms(a, x) memset(a, x, sizeof a)
typedef pair<int, int> ii;
const double pi = acos(-1.0);
const double eps = 1e-5;
const int INF = 1 << 30, mod = 1e9, N = 1e6 + 6;
/*int power(int a,int b,int p){
        int ans=1%p;
        for(;b;b>>1){
                if(b&1)  ans=(ll)ans*a%p;
                else a=(ll)a*a%p;
        }
        return ans;
}*/
string s;
ll sum = 0;
int main() {
  cin >> s;
  int k = s.size();
  for (int i = 0; i < 1 << (k - 1); i++) {
    string S = "";
    ff(j, 0, k) {
      S += s[j];
      if ((i >> j) % 2 == 0) {
        sum += stoi(S);
        S = "";
      }
    }
  }
  cout << sum;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define f(i, a, b) for (int(i) = int(a); i <= int(b); i++)
#define ff(i, a, b) for (int(i) = int(a); i < int(b); i++)
#define F(i, a, b) for (int(i) = int(a); i >= int(b); i--)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vt vector
#define ll long long
#define all(x) x.begin(), x.end()
#define lower(p, x) lower_bound(all(p), x)
#define upper(p, x) upper_bound(all(p), x)
#define ms(a, x) memset(a, x, sizeof a)
typedef pair<int, int> ii;
const double pi = acos(-1.0);
const double eps = 1e-5;
const int INF = 1 << 30, mod = 1e9, N = 1e6 + 6;
/*int power(int a,int b,int p){
        int ans=1%p;
        for(;b;b>>1){
                if(b&1)  ans=(ll)ans*a%p;
                else a=(ll)a*a%p;
        }
        return ans;
}*/
string s;
ll sum = 0;
int main() {
  cin >> s;
  int k = s.size();
  for (int i = 0; i < 1 << (k - 1); i++) {
    string S = "";
    ff(j, 0, k) {
      S += s[j];
      if ((i >> j) % 2 == 0) {
        sum += atoll(S.c_str());
        S = "";
      }
    }
  }
  cout << sum;
}