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

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

string s;
int k;

int main() {
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a')
      continue;
    if ('a' + 26 - s[i] <= k) {
      k -= 'a' + 26 - s[i];
      s[i] = 'a';
    }
  }
  for (int i = 0; i < k; i++)
    s[s.size() - 1] = (s[s.size() - 1] - 'a' + 1) % 26 + 'a';
  cout << s << endl;
  return 0;
}


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

string s;
int k;

int main() {
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a')
      continue;
    if ('a' + 26 - s[i] <= k) {
      k -= 'a' + 26 - s[i];
      s[i] = 'a';
    }
  }
  k %= 26;
  for (int i = 0; i < k; i++)
    s[s.size() - 1] = (s[s.size() - 1] - 'a' + 1) % 26 + 'a';
  cout << s << endl;
  return 0;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a) for (int i = 0; i < (a); i++)
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main() {
  string s;
  int k;
  cin >> s;
  cin >> k;
  REP(i, s.size()) {
    if (s[i] != 'a' && k >= 26 - (s[i] - 'a')) {
      k -= 26 - (s[i] - 'a');
      s[i] = 'a';
    }
  }
  while (k > 0) {
    if (s[s.size() - 1] == 'z') {
      s[s.size() - 1] = 'a';
    } else {
      s[s.size() - 1]++;
    }
    k--;
  }
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a) for (int i = 0; i < (a); i++)
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main() {
  string s;
  int k;
  cin >> s;
  cin >> k;
  REP(i, s.size()) {
    if (s[i] != 'a' && k >= 26 - (s[i] - 'a')) {
      k -= 26 - (s[i] - 'a');
      s[i] = 'a';
    }
  }
  k %= 26;
  while (k > 0) {
    if (s[s.size() - 1] == 'z') {
      s[s.size() - 1] = 'a';
    } else {
      s[s.size() - 1]++;
    }
    k--;
  }
  cout << s << endl;
}
Problem p03994 (C++)

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

using namespace std;

int main() {
  string str;
  long long k;
  cin >> str;
  cin >> k;
  int count = 0;
  int minn = 0;
  while (minn < str.length()) {
    if (str[minn] != 'a' && 'z' - str[minn] < k - count) {
      count += 'z' - str[minn] + 1;
      str[minn] = 'a';
    }
    minn++;
  }
  for (int i = count; i < k; i++) {
    str[str.length() - 1]++;
    if (str[str.length() - 1] == 'z' + 1)
      str[str.length() - 1] = 'a';
  }
  cout << str << endl;

  return 0;
}

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

using namespace std;

int main() {
  string str;
  long long k;
  cin >> str;
  cin >> k;
  int count = 0;
  int minn = 0;
  while (minn < str.length()) {
    if (str[minn] != 'a' && 'z' - str[minn] < k - count) {
      count += 'z' - str[minn] + 1;
      str[minn] = 'a';
    }
    minn++;
  }

  str[str.length() - 1] += (k - count) % 26;
  cout << str << endl;

  return 0;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main() {
  string s;
  int n, k;
  cin >> s >> k;
  n = s.size();
  for (int i = 0; i < n; i++) {
    int cgs = 'z' + 1 - s[i];
    if (s[i] == 'a')
      cgs = 0;
    if (k >= cgs) {
      s[i] = 'a';
      k -= cgs;
    }
  }
  if (k > 0) {
    int rem = k % 26;
    for (int i = 0; i < k; i++) {
      s[n - 1]++;
      if (s[n - 1] == 'z' + 1)
        s[n - 1] = 'a';
    }
  }
  cout << s << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main() {
  string s;
  int n, k;
  cin >> s >> k;
  n = s.size();
  for (int i = 0; i < n; i++) {
    int cgs = 'z' + 1 - s[i];
    if (s[i] == 'a')
      cgs = 0;
    if (k >= cgs) {
      s[i] = 'a';
      k -= cgs;
    }
  }
  if (k > 0) {
    int rem = k % 26;
    for (int i = 0; i < rem; i++) {
      s[n - 1]++;
      if (s[n - 1] == 'z' + 1)
        s[n - 1] = 'a';
    }
  }
  cout << s << endl;
  return 0;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
  rep(j, sz(v)) i >> v[j];
  return i;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
  return i >> v.fi >> v.se;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

  string s;
  cin >> s;
  int n = sz(s);
  int k;
  cin >> k;

  int pos = 0;
  rep(i, k) {
    while (s[pos] == 'a' && pos < n - 1)
      pos++;
    while ('z' - s[pos] + 1 > k - i && pos < n - 1)
      pos++;
    s[pos] = (s[pos] - 'a' + 1) % 26 + 'a';
  }
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
  rep(j, sz(v)) i >> v[j];
  return i;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
  return i >> v.fi >> v.se;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

  string s;
  cin >> s;
  int n = sz(s);
  int k;
  cin >> k;

  rep(i, n) {
    if (i == n - 1) {
      s[i] = (s[i] - 'a' + k) % 26 + 'a';
      continue;
    }
    if (s[i] == 'a')
      continue;
    if ('z' - s[i] + 1 > k)
      continue;
    k -= 'z' - s[i] + 1;
    s[i] = 'a';
  }
  cout << s << endl;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define maxn 100005
#define ll long long
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define rc(s) return cout << s, 0
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cerr.tie(0);                                                                 \
  cout.tie(0);
#define db(x) cerr << #x << " = " << x << '\n'
#define pb push_back
#define mp make_pair
#define sz(x) (int)((x).size())
// # define int ll
using namespace std;

string s;
int k;

int32_t main() {
  _
          // freopen("input","r",stdin);
          cin >>
      s;
  cin >> k;
  for (int i = 0; i < sz(s); i++) {
    if (s[i] != 'a' && k >= 26 - s[i] + 'a') {
      k -= 26 - s[i] + 'a';
      s[i] = 'a';
    }
  }
  while (k) {
    k--;
    s[sz(s) - 1] = (s[sz(s) - 1] == 'z' ? 'a' : s[sz(s) - 1] + 1);
  }
  rc(s);
}


Fixed submission:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define maxn 100005
#define ll long long
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define rc(s) return cout << s, 0
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cerr.tie(0);                                                                 \
  cout.tie(0);
#define db(x) cerr << #x << " = " << x << '\n'
#define pb push_back
#define mp make_pair
#define sz(x) (int)((x).size())
// # define int ll
using namespace std;

string s;
int k;

int32_t main() {
  _
          // freopen("input","r",stdin);
          cin >>
      s;
  cin >> k;
  for (int i = 0; i < sz(s); i++) {
    if (s[i] != 'a' && k >= 26 - s[i] + 'a') {
      k -= 26 - s[i] + 'a';
      s[i] = 'a';
    }
  }
  int x = s[sz(s) - 1] - 'a';
  x += k;
  x %= 26;
  s[sz(s) - 1] = 'a' + x;
  rc(s);
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'a')
      continue;
    int a = 26 - (S[i] - 97);
    if (a <= K) {
      S[i] = 'a';
      K -= a;
    }
  }
  for (int i = 0; i < K; i++) {
    S[S.length() - 1] = (S[S.length() - 1] - 97 + 1) % 26 + 97;
  }
  cout << S;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'a')
      continue;
    int a = 26 - (S[i] - 97);
    if (a <= K) {
      S[i] = 'a';
      K -= a;
    }
  }
  S[S.length() - 1] = (S[S.length() - 1] - 97 + K) % 26 + 97;
  cout << S;
}
Problem p03994 (C++)

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

int need(char c) {
  if (c == 'a') {
    return 0;
  } else {
    return 'a' + 26 - c;
  }
}

int main() {
  int i, K;
  string s;
  cin >> s;
  scanf("%d", &K);
  for (i = 0; i < s.size(); i++) {
    if (need(s[i]) <= K) {
      K -= need(s[i]);
      s[i] = 'a';
    }
  }
  while (K > 0) {
    K--;
    s[s.size() - 1]++;
    if (s[s.size() - 1] > 'z') {
      s[s.size() - 1] = 'a';
    }
  }
  cout << s << endl;
  return 0;
}

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

int need(char c) {
  if (c == 'a') {
    return 0;
  } else {
    return 'a' + 26 - c;
  }
}

int main() {
  int i, K;
  string s;
  cin >> s;
  scanf("%d", &K);
  for (i = 0; i < s.size(); i++) {
    if (need(s[i]) <= K) {
      K -= need(s[i]);
      s[i] = 'a';
    }
  }
  K %= 26;
  while (K > 0) {
    K--;
    s[s.size() - 1]++;
    if (s[s.size() - 1] > 'z') {
      s[s.size() - 1] = 'a';
    }
  }
  cout << s << endl;
  return 0;
}
Problem p03994 (C++)

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

int main() {
  string s;
  cin >> s;
  long long k, i = 0;
  cin >> k;

  while (k) {
    if (s[i] == 'a') {
      i++;
      continue;
    }
    if (('z' - s[i] + 1LL) <= k) {
      k -= ('z' - s[i] + 1LL);
      // cout << 'z'-s[i] << endl;
      s[i] = 'a';
    }
    i++;
    if (i == s.size())
      break;
  }

  if (k > 0LL) {
    k %= 26LL;
    s[s.size() - 1] += k;
  }

  cout << s << endl;

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  long long k, i = 0;
  cin >> k;

  while (k) {
    if (s[i] == 'a') {
      i++;
      if (i == s.size())
        break;
      continue;
    }
    if (('z' - s[i] + 1LL) <= k) {
      k -= ('z' - s[i] + 1LL);
      // cout << 'z'-s[i] << endl;
      s[i] = 'a';
    }
    i++;
    if (i == s.size())
      break;
  }

  if (k > 0LL) {
    k %= 26LL;
    s[s.size() - 1] += k;
  }

  cout << s << endl;

  return 0;
}
Problem p03994 (C++)

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

char s[100010];
int K;

char n(char c) {
  int i = (int)c - (int)'a';
  return (char)((i + 1) % 26 + (int)'a');
}

void rotate(int i) { s[i] = n(s[i]); }

int main() {
  cin >> s;
  cin >> K;
  int l = strlen(s);
  int x = K;
  int i = 0;
  while (x > 0 && i < l) {
    int d = ((int)'a' - (int)s[i] + 26) % 26;
    if (d > x) {
      i++;
      continue;
    }
    s[i] = 'a';
    x -= d;
    i++;
  }
  for (int j = 0; j < x; j++)
    rotate(l - 1);
  cout << s << "\n";
  return 0;
}


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

char s[100010];
int K;

char n(char c) {
  int i = (int)c - (int)'a';
  return (char)((i + 1) % 26 + (int)'a');
}

void rotate(int i) { s[i] = n(s[i]); }

int main() {
  cin >> s;
  cin >> K;
  int l = strlen(s);
  int x = K;
  int i = 0;
  while (x > 0 && i < l) {
    int d = ((int)'a' - (int)s[i] + 26) % 26;
    if (d > x) {
      i++;
      continue;
    }
    s[i] = 'a';
    x -= d;
    i++;
  }
  for (int j = 0; j < (x % 26); j++)
    rotate(l - 1);
  cout << s << "\n";
  return 0;
}
Problem p03994 (C++)

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

char a[100010];
int n, k;

int main() {
  scanf("%s", a);
  cin >> k;
  for (n = 0; a[n]; n++)
    ;
  for (int i = 0; i < n; i++) {
    if (a[i] == 'a')
      continue;
    else if ('z' + 1 - a[i] <= k) {
      k -= ('z' + 1 - a[i]);
      a[i] = 'a';
    } else
      continue;
  }
  k % 26;
  while (k) {
    a[n - 1]++;
    if (a[n - 1] > 'z')
      a[n - 1] = 'a';
    k--;
  }
  puts(a);
  return 0;
}

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

char a[100010];
int n, k;

int main() {
  scanf("%s", a);
  cin >> k;
  for (n = 0; a[n]; n++)
    ;
  for (int i = 0; i < n; i++) {
    if (a[i] == 'a')
      continue;
    else if ('z' + 1 - a[i] <= k) {
      k -= ('z' + 1 - a[i]);
      a[i] = 'a';
    } else
      continue;
  }
  k %= 26;
  while (k) {
    a[n - 1]++;
    if (a[n - 1] > 'z')
      a[n - 1] = 'a';
    k--;
  }
  puts(a);
  return 0;
}
Problem p03994 (C++)

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

/*
sの中で、
・aまでの距離がk以下であるもののうち、もっとも左にあるものを選ぶ
・全てaになれば、もっとも右にあるもので残りを回す
*/

void solve() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int i = 0;
  int siz = s.size();
  while (i < siz) {
    if ((26 - (s[i] - 'a')) <= k && s[i] != 'a') {
      k = k - (26 - (s[i] - 'a'));
      // cout << k << endl;
      s[i] = 'a';
      i = 0;
      // break;
    } else {
      i++;
    }
  }
  char c = s[siz - 1];
  // c-'a'とkの和が26を超えていたら、26で割った余りをとる
  c = ((c - 'a') + k) % 26 + 'a';
  s[siz - 1] = c;

  cout << s << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

/*
sの中で、
・aまでの距離がk以下であるもののうち、もっとも左にあるものを選ぶ
・全てaになれば、もっとも右にあるもので残りを回す
*/

void solve() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int i = 0;
  int siz = s.size();
  while (i < siz) {
    if ((26 - (s[i] - 'a')) <= k && s[i] != 'a') {
      k = k - (26 - (s[i] - 'a'));
      // cout << k << endl;
      s[i] = 'a';
      // i=0;
      // break;
    } else {
      i++;
    }
  }
  char c = s[siz - 1];
  // c-'a'とkの和が26を超えていたら、26で割った余りをとる
  c = ((c - 'a') + k) % 26 + 'a';
  s[siz - 1] = c;

  cout << s << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rer(i, l, u) for (int(i) = (int)(l); (i) <= (int)(u); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
template <typename T, typename U> static void amin(T &x, U y) {
  if (y < x)
    x = y;
}
template <typename T, typename U> static void amax(T &x, U y) {
  if (x < y)
    x = y;
}

int main() {
  char s[100001];
  while (scanf("%s", s)) {
    int K;
    scanf("%d", &K);
    int n = strlen(s);
    rep(i, n) {
      if (s[i] != 'a') {
        int k = 'z' + 1 - s[i];
        if (k <= K) {
          s[i] = 'a';
          K -= k;
        }
      }
    }
    s[n - 1] = (s[n - 1] - 'a' + K) % 26 + 'a';
    puts(s);
  }
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rer(i, l, u) for (int(i) = (int)(l); (i) <= (int)(u); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
template <typename T, typename U> static void amin(T &x, U y) {
  if (y < x)
    x = y;
}
template <typename T, typename U> static void amax(T &x, U y) {
  if (x < y)
    x = y;
}

int main() {
  char s[100001];
  while (~scanf("%s", s)) {
    int K;
    scanf("%d", &K);
    int n = strlen(s);
    rep(i, n) {
      if (s[i] != 'a') {
        int k = 'z' + 1 - s[i];
        if (k <= K) {
          s[i] = 'a';
          K -= k;
        }
      }
    }
    s[n - 1] = (s[n - 1] - 'a' + K) % 26 + 'a';
    puts(s);
  }
  return 0;
}
Problem p03994 (C++)

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
constexpr auto INF = 4000000000; // 4*10^9;
constexpr auto MOD = 1000000007; // 10^9+7;

char nextab(char c) {
  if (c == 'z')
    return 'a';
  else
    return c + 1;
}

int main() {

  string s;
  cin >> s;
  int k;
  cin >> k;

  vector<char> c(s.size());
  rep(i, s.size()) c[i] = s[i];

  rep(i, s.size() - 1) {
    if (c[i] == 'a')
      continue;
    if ('z' - c[i] + 1 <= k) {
      for (; c[i] != 'a' && k > 0;) {
        c[i] = nextab(c[i]);
        k--;
      }
    }
  }

  if (k > 0) {
    rep(i, k) { c[s.size() - 1] = nextab(c[s.size() - 1]); }
  }

  rep(i, s.size()) cout << c[i];
  cout << endl;
}

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
constexpr auto INF = 4000000000; // 4*10^9;
constexpr auto MOD = 1000000007; // 10^9+7;

char nextab(char c) {
  if (c == 'z')
    return 'a';
  else
    return c + 1;
}

int main() {

  string s;
  cin >> s;
  int k;
  cin >> k;

  vector<char> c(s.size());
  rep(i, s.size()) c[i] = s[i];

  rep(i, s.size() - 1) {
    if (c[i] == 'a')
      continue;
    if ('z' - c[i] + 1 <= k) {
      for (; c[i] != 'a' && k > 0;) {
        c[i] = nextab(c[i]);
        k--;
      }
    }
  }

  k %= 26;

  if (k > 0) {
    rep(i, k) { c[s.size() - 1] = nextab(c[s.size() - 1]); }
  }

  rep(i, s.size()) cout << c[i];
  cout << endl;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <fstream>
#include <iostream>
#include <streambuf>
#include <string>
using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  int k;
  cin >> s;
  cin >> k;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'a') {
      continue;
    }
    if (k >= 'z' + 1 - s[i]) {
      k = k - ('z' + 1 - s[i]);
      s[i] = 'a';
      continue;
    }
  }
  long last = s.length() - 1;
  while (k) {
    s[last] = s[last] + 1;
    if (s[last] > 'z') {
      s[last] = 'a';
    }
    k--;
  }
  cout << s << endl;

  return 0;
}


Fixed submission:

#include <fstream>
#include <iostream>
#include <streambuf>
#include <string>
using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  int k;
  cin >> s;
  cin >> k;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'a') {
      continue;
    }
    if (k >= 'z' + 1 - s[i]) {
      k = k - ('z' + 1 - s[i]);
      s[i] = 'a';
      continue;
    }
  }
  long last = s.length() - 1;
  s[last] = 'a' + (s[last] - 'a' + k) % 26;
  cout << s << endl;

  return 0;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
// const ll p = 1e9 + 7;
// const ll p = 998244353;
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }

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

  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();

  vll cnt(n, 0);
  for (ll i = 0; i < n; i++) {
    if (s[i] != 'a') {
      cnt[i] = 26 - (s[i] - 'a');
    }
  }

  for (ll i = 0; i < n; i++) {
    if (cnt[i] <= k) {
      s[i] = 'a';
      k -= cnt[i];
    }
  }
  while (k) {
    if (s[n - 1] == 'z')
      s[n - 1] = 'a';
    else
      s[n - 1]++;
    k--;
  }

  cout << s << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
// const ll p = 1e9 + 7;
// const ll p = 998244353;
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }

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

  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();

  vll cnt(n, 0);
  for (ll i = 0; i < n; i++) {
    if (s[i] != 'a') {
      cnt[i] = 26 - (s[i] - 'a');
    }
  }

  for (ll i = 0; i < n; i++) {
    if (cnt[i] <= k) {
      s[i] = 'a';
      k -= cnt[i];
    }
  }
  k %= 26;
  while (k) {
    if (s[n - 1] == 'z')
      s[n - 1] = 'a';
    else
      s[n - 1]++;
    k--;
  }

  cout << s << endl;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
using namespace std;

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int N = 2e5 + 5;
int ans = 0, q = 0;

int can(char t, int ost) {
  int am = ('z' - t + 1);
  if (ost < am)
    return -1;
  return am;
}
char next(char c) { return ((c == 'z') ? 'a' : c + 1); }
void solve() {
  string s;
  int k;
  cin >> s >> k;
  int res;
  for (auto &c : s) {
    if (c == 'a')
      continue;
    res = can(c, k);
    if (res == -1)
      continue;
    k -= res;
    c = 'a';
  }
  while (k != 0) {
    k--;
    s[s.size() - 1] = next(s[s.size() - 1]);
  }
  cout << s;
}

int main() {
#ifdef _DEBUG27_
  if (1)
    freopen("input.txt", "r", stdin);
#else
  if (0) {
    freopen("weapons.in", "r", stdin);
    freopen("weapons.out", "w", stdout);
  }
#endif

  solve();

#ifdef _DEBUG27_
  cout << endl << "Time: " << clock() / 1000.0 << " ms";
#endif
  return 0;
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


Fixed submission:
using namespace std;

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int N = 2e5 + 5;
int ans = 0, q = 0;

int can(char t, int ost) {
  int am = ('z' - t + 1);
  if (ost < am)
    return -1;
  return am;
}
char next(char c) { return ((c == 'z') ? 'a' : c + 1); }
void solve() {
  string s;
  int k;
  cin >> s >> k;
  int res;
  for (auto &c : s) {
    if (c == 'a')
      continue;
    res = can(c, k);
    if (res == -1)
      continue;
    k -= res;
    c = 'a';
  }
  k %= 26;
  while (k != 0) {
    k--;
    s[s.size() - 1] = next(s[s.size() - 1]);
  }
  cout << s;
}

int main() {
#ifdef _DEBUG27_
  if (1)
    freopen("input.txt", "r", stdin);
#else
  if (0) {
    freopen("weapons.in", "r", stdin);
    freopen("weapons.out", "w", stdout);
  }
#endif

  solve();

#ifdef _DEBUG27_
  cout << endl << "Time: " << clock() / 1000.0 << " ms";
#endif
  return 0;
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/
Problem p03994 (C++)

Buggy submission (status: Runtime Error):
// 問題の URL を書いておく
//

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

// #define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v)                                                               \
  do {                                                                         \
    cout << #v << ": " << v << endl;                                           \
  } while (0)

#define PrintVec(v)                                                            \
  do {                                                                         \
    for (int __i = 0; __i < v.size(); ++__i) {                                 \
      cout << #v << "[" << __i << "]: " << v[__i] << endl;                     \
    }                                                                          \
  } while (0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

int nums[10005];

int main(int, const char **) {
  string s;
  cin >> s;
  int K;
  cin >> K;
  rep(i, (int)s.size()) { nums[i] = s[i] - 'a'; }
  int k = K;
  string ans = "";
  rep(i, (int)s.size() - 1) {
    auto t = (26 - nums[i]) % 26;
    if (k >= t) {
      k -= t;
      ans += 'a';
    } else {
      ans += s[i];
    }
  }
  auto lastNum = (nums[s.size() - 1] + k) % 26;
  ans += (char)('a' + lastNum);

  cout << ans << endl;

  return 0;
}


Fixed submission:
// 問題の URL を書いておく
//

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

// #define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v)                                                               \
  do {                                                                         \
    cout << #v << ": " << v << endl;                                           \
  } while (0)

#define PrintVec(v)                                                            \
  do {                                                                         \
    for (int __i = 0; __i < v.size(); ++__i) {                                 \
      cout << #v << "[" << __i << "]: " << v[__i] << endl;                     \
    }                                                                          \
  } while (0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

int nums[100005];

int main(int, const char **) {
  string s;
  cin >> s;
  int K;
  cin >> K;
  rep(i, (int)s.size()) { nums[i] = s[i] - 'a'; }
  int k = K;
  string ans = "";
  rep(i, (int)s.size() - 1) {
    auto t = (26 - nums[i]) % 26;
    if (k >= t) {
      k -= t;
      ans += 'a';
    } else {
      ans += s[i];
    }
  }
  auto lastNum = (nums[s.size() - 1] + k) % 26;
  ans += (char)('a' + lastNum);

  cout << ans << endl;

  return 0;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

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

  int len = s.size();
  int count = 0;
  int ind = 0;
  while (count < K) {
    if (ind == len - 1) {
      ++count;
      s[ind] = (s[ind] - 'a' + 1) % 26 + 'a';
    } else if (s[ind] == 'a') {
      ++ind;
    } else if (K - count >= 26 - (s[ind] - 'a')) {
      count += 26 - (s[ind] - 'a');
      s[ind] = 'a';
    } else {
      ++ind;
    }
  }

  cout << s << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

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

  int len = s.size();
  int count = 0;
  int ind = 0;
  while (count < K) {
    if (ind == len - 1) {
      int n = (K - count) % 26;
      s[ind] = (s[ind] - 'a' + n) % 26 + 'a';
      count = 1000000001;
    } else if (s[ind] == 'a') {
      ++ind;
    } else if (K - count >= 26 - (s[ind] - 'a')) {
      count += 26 - (s[ind] - 'a');
      s[ind] = 'a';
    } else {
      ++ind;
    }
  }

  cout << s << endl;

  return 0;
}
Problem p03994 (C++)

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

using namespace std;

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

  int n = s.length();
  for (int i = 0; i < n; i++) {
    int need = s[i] == 'a' ? 0 : 'z' - s[i] + 1;
    if (need <= k) {
      k -= need;
      s[i] = 'a';
    }
  }

  while (k > 0) {
    if (s[n - 1] == 'z')
      s[n - 1] = 'a';
    else
      s[n - 1]++;

    k--;
  }

  cout << s << endl;

  return 0;
}


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

using namespace std;

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

  int n = s.length();
  for (int i = 0; i < n; i++) {
    int need = s[i] == 'a' ? 0 : 'z' - s[i] + 1;
    if (need <= k) {
      k -= need;
      s[i] = 'a';
    }
  }

  k %= ('z' - 'a' + 1);

  while (k > 0) {
    if (s[n - 1] == 'z')
      s[n - 1] = 'a';
    else
      s[n - 1]++;

    k--;
  }

  cout << s << endl;

  return 0;
}
Problem p03994 (C++)

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

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

  for (int i = 0; i < s.size(); i++) {
    if (s[i] != 'a' && 'z' - s[i] + 1 <= K) {
      K -= 'z' - s[i] + 1;
      s[i] = 'a';
    }
  }

  while (K > 0) {
    s[s.size() - 1] = (s[s.size() - 1] - 'a' + 1) % 26 + 'a';
    K--;
  }

  cout << s << endl;
}

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

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

  for (int i = 0; i < s.size(); i++) {
    if (s[i] != 'a' && 'z' - s[i] + 1 <= K) {
      K -= 'z' - s[i] + 1;
      s[i] = 'a';
    }
  }

  K = K % 26;
  while (K > 0) {
    s[s.size() - 1] = (s[s.size() - 1] - 'a' + 1) % 26 + 'a';
    K--;
  }

  cout << s << endl;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  int L = s.length();
  for (int i = 0; i < L; i++) {
    int x = 'z' - s[i] + 1;
    if (x == 26)
      continue;
    else {
      if (k >= x) {
        s[i] = 'a';
        k -= 1LL * x;
      }
    }
  }
  while (k > 0) {
    k--;
    if (s[L - 1] == 'z')
      s[L - 1] = 'a';
    else {
      char x = s[L - 1] + 1;
      s[L - 1] = x;
    }
  }
  cout << s << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  int L = s.length();
  for (int i = 0; i < L; i++) {
    int x = 'z' - s[i] + 1;
    if (x == 26)
      continue;
    else {
      if (k >= x) {
        s[i] = 'a';
        k -= 1LL * x;
      }
    }
  }
  k %= 26;
  while (k > 0) {
    k--;
    if (s[L - 1] == 'z')
      s[L - 1] = 'a';
    else {
      char x = s[L - 1] + 1;
      s[L - 1] = x;
    }
  }
  cout << s << endl;
  return 0;
}
Problem p03995 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define chmin(a, b) a = min(a, b);
#define N 10
vector<P> g[2 * N];
ll d[2 * N], n, h, w;

ll mi[2];
bool dfs(ll x, ll dis, ll col) {
  if (d[x] != -1e17) {
    if (d[x] != dis)
      return 0;
    return 1;
  } // cout<<"#"<<x<<" "<<dis<<" "<<col<<endl;
  d[x] = dis;
  chmin(mi[col], dis);
  for (auto y : g[x]) {
    if (!dfs(y.first, y.second - dis, col ^ 1))
      return 0;
  }
  return 1;
}

int main() {
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    b += N;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  for (int i = 0; i < 2 * N; i++)
    d[i] = -1e17;
  bool ok = 1;
  for (int i = 0; i < 2 * N; i++) {
    if (d[i] != -1e17)
      continue;
    mi[0] = mi[1] = 1e17;
    ok &= dfs(i, 1, 0);
    if (mi[0] + mi[1] < 0)
      ok = 0; // cout<<"%"<<mi[0]<<" "<<mi[1]<<endl;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define chmin(a, b) a = min(a, b);
#define N 100010
vector<P> g[2 * N];
ll d[2 * N], n, h, w;

ll mi[2];
bool dfs(ll x, ll dis, ll col) {
  if (d[x] != -1e17) {
    if (d[x] != dis)
      return 0;
    return 1;
  } // cout<<"#"<<x<<" "<<dis<<" "<<col<<endl;
  d[x] = dis;
  chmin(mi[col], dis);
  for (auto y : g[x]) {
    if (!dfs(y.first, y.second - dis, col ^ 1))
      return 0;
  }
  return 1;
}

int main() {
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    b += N;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  for (int i = 0; i < 2 * N; i++)
    d[i] = -1e17;
  bool ok = 1;
  for (int i = 0; i < 2 * N; i++) {
    if (d[i] != -1e17)
      continue;
    mi[0] = mi[1] = 1e17;
    ok &= dfs(i, 1, 0);
    if (mi[0] + mi[1] < 0)
      ok = 0; // cout<<"%"<<mi[0]<<" "<<mi[1]<<endl;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}
Problem p03997 (Python)

Buggy submission (status: Runtime Error):
a, b, h = [input() for _ in range(3)]
print(int((a + b) * h / 2))


Fixed submission:
a, b, h = [int(input()) for _ in range(3)]
print(int((a + b) * h / 2))
Problem p03997 (Python)

Buggy submission (status: Runtime Error):
SA = list(input())
SB = list(input())
SC = list(input())

D = {"a": SA, "b": SB, "c": SC}
now = "a"

while D[now]:
    now = D[now].pop()

print(now)


Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print((a + b) * h // 2)
Problem p03997 (Python)

Buggy submission (status: Runtime Error):
def resolve():
    a, b, h = map(int, input().split())
    print((a + b) * h // 2)


if __name__ == "__main__":
    resolve()


Fixed submission:
def resolve():
    a = int(input())
    b = int(input())
    h = int(input())
    print((a + b) * h // 2)


if __name__ == "__main__":
    resolve()
Problem p03997 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <stdlib.h>
int main(void) {
  int a, b, h, S;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &h);

  S = a + b;
  S = S * h;
  S = S / 2;
  printf("%S\n", S);
  system("pause");
  return 0;
}

Fixed submission:
#include <cstdio>
int main() {
  int a, b, h;
  scanf("%d %d %d", &a, &b, &h);
  printf("%d", (a + b) * h / 2);
  return 0;
}
Problem p03997 (C++)

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

int main() {
  int a, b, h;
  std::cin >> a >> b >> h;
  return (a + b) * h / 2;
}

Fixed submission:
#include <iostream>

int main() {
  int a, b, h;
  std::cin >> a >> b >> h;
  std::cout << (a + b) * h / 2 << std::endl;
}
Problem p03997 (C++)

Buggy submission (status: Time Limit Exceeded):
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define out(s) cout << s << endl

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


Fixed submission:
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define out(s) cout << s << endl

int main() {
  int a, b, h;
  cin >> a >> b >> h;

  cout << ((a + b) * h) / 2 << endl;
  return 0;
}
Problem p03997 (Python)

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

print((a + b) * h / 2)


Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print((a + b) * h // 2)
Problem p03997 (C++)

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

using namespace std;

int main() {
  int a, b, h;

  cin >> a >> b >> h;

  return (a + b) * h / 2;
  return 0;
}

Fixed submission:
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a, b, h;

  cin >> a >> b >> h;

  cout << (a + b) * h / 2;
  return 0;
}
Problem p03997 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
int main() {
  int a = 0, b = 0, h = 0;
  scanf("%d", a);
  scanf("%d", b);
  scanf("%d", h);
  printf("%lf\n", (a + b) * h / 2);
  return 0;
}

Fixed submission:
#include <cstdio>
main() {
  int a, b, h, area;
  scanf("%d %d %d", &a, &b, &h);
  area = (a + b) * h / 2;
  printf("%d\n", area);
  return 0;
}
Problem p03998 (Python)

Buggy submission (status: Runtime Error):
def str2turn(c: str) -> int:
    if c.lower() == "a":
        return 0
    elif c.lower() == "b":
        return 1
    return 2


def turn2str(t: int) -> str:
    if t == 0:
        return "a"
    elif t == 1:
        return "b"
    return "c"


def card_game_for_three(Sa: str, Sb: str, Sc: str) -> str:
    indexes = [0, 0, 0]
    limits = [len(Sa), len(Sb), len(Sc)]
    cards = [Sa, Sb, Sc]

    turn = 0
    while indexes[turn] < limits[turn]:
        next_turn = cards[turn][indexes[turn]]
        indexes[turn] += 1
        turn = next_turn

    return turn2str(turn).upper()


if __name__ == "__main__":
    Sa = input()
    Sb = input()
    Sc = input()
    ans = card_game_for_three(Sa, Sb, Sc)
    print(ans)


Fixed submission:
def str2turn(c: str) -> int:
    if c.lower() == "a":
        return 0
    elif c.lower() == "b":
        return 1
    return 2


def turn2str(t: int) -> str:
    if t == 0:
        return "a"
    elif t == 1:
        return "b"
    return "c"


def card_game_for_three(Sa: str, Sb: str, Sc: str) -> str:
    indexes = [0, 0, 0]
    limits = [len(Sa), len(Sb), len(Sc)]
    cards = [Sa, Sb, Sc]

    turn = 0
    while indexes[turn] < limits[turn]:
        next_turn = str2turn(cards[turn][indexes[turn]])
        indexes[turn] += 1
        turn = next_turn

    return turn2str(turn).upper()


if __name__ == "__main__":
    Sa = input()
    Sb = input()
    Sc = input()
    ans = card_game_for_three(Sa, Sb, Sc)
    print(ans)
Problem p03998 (C++)

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

int main() {
  string Sa, Sb, Sc;
  cin >> Sa >> Sb >> Sc;
  int len_A = Sa.length();
  int len_B = Sb.length();
  int len_C = Sc.length();
  string direction = Sa.substr(0, 1);
  Sa = Sa.substr(1, len_A);
  while (len_A + len_B + len_C > 0) {
    if (direction == "a" && len_A != 0) {
      direction = Sa.substr(0, 1);
      Sa = Sa.substr(1, len_A);
      len_A = Sa.length();
    } else if (direction == "a" && len_A == 0) {
      cout << "A" << endl;
      break;
    } else if (direction == "b" && len_B != 0) {
      direction = Sb.substr(0, 1);
      Sb = Sb.substr(1, len_B);
      len_B = Sb.length();
    } else if (direction == "b" && len_B == 0) {
      cout << "B" << endl;
      break;
    } else if (direction == "c" && len_C != 0) {
      direction = Sc.substr(0, 1);
      Sc = Sc.substr(1, len_C);
      len_C = Sc.length();
    } else if (direction == "c" && len_C == 0) {
      cout << "C" << endl;
      break;
    }
  }
}

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

int main() {
  string Sa, Sb, Sc;
  cin >> Sa >> Sb >> Sc;
  int len_A = Sa.length();
  int len_B = Sb.length();
  int len_C = Sc.length();
  string direction = Sa.substr(0, 1);
  Sa = Sa.substr(1, len_A);
  len_A = Sa.length();
  while (len_A + len_B + len_C > 0) {
    if (direction == "a" && len_A != 0) {
      direction = Sa.substr(0, 1);
      Sa = Sa.substr(1, len_A);
      len_A = Sa.length();
    } else if (direction == "a" && len_A == 0) {
      cout << "A" << endl;
      break;
    } else if (direction == "b" && len_B != 0) {
      direction = Sb.substr(0, 1);
      Sb = Sb.substr(1, len_B);
      len_B = Sb.length();
    } else if (direction == "b" && len_B == 0) {
      cout << "B" << endl;
      break;
    } else if (direction == "c" && len_C != 0) {
      direction = Sc.substr(0, 1);
      Sc = Sc.substr(1, len_C);
      len_C = Sc.length();
    } else if (direction == "c" && len_C == 0) {
      cout << "C" << endl;
      break;
    }
  }
}
Problem p03998 (C++)

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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  string next;
  next.push_back(s1[0]);
  int a = {}, b = {}, c = {};
  while (true) {
    if (next == "a") {
      if (s1.empty()) {
        cout << "A"
             << "\n";
        break;
      }
      next = *s1.begin();
      s1.erase(s1.begin());
      a++;
    }
    if (next == "b") {
      if (s2.empty()) {
        cout << "B"
             << "\n";
        break;
      }
      next = *s2.begin();
      s2.erase(s2.begin());
      b++;
    }
    if (next == "c") {
      if (s2.empty()) {
        cout << "C"
             << "\n";
        break;
      }
      next = *s3.begin();
      s3.erase(s3.begin());
      c++;
    }
  }
  return 0;
}


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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  string next;
  next.push_back(s1[0]);
  int a = {}, b = {}, c = {};
  while (true) {
    if (next == "a") {
      if (s1.empty()) {
        cout << "A"
             << "\n";
        break;
      }
      next = *s1.begin();
      s1.erase(s1.begin());
      a++;
    }
    if (next == "b") {
      if (s2.empty()) {
        cout << "B"
             << "\n";
        break;
      }
      next = *s2.begin();
      s2.erase(s2.begin());
      b++;
    }
    if (next == "c") {
      if (s3.empty()) {
        cout << "C"
             << "\n";
        break;
      }
      next = *s3.begin();
      s3.erase(s3.begin());
      c++;
    }
  }
  return 0;
}
Problem p03998 (C++)

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

int main() {
  string X, Y, Z;
  cin >> X >> Y >> Z;
  int lx = X.size();
  int ly = Y.size();
  int lz = Z.size();
  int p = 1, q = 0, r = 0;
  char S = X.at(0);
  char ans;
  while (true) {
    if (S == 'a') {
      S = X.at(p);
      p++;
    } else if (S == 'b') {
      S = Y.at(q);
      q++;
    } else {
      S = Z.at(r);
      r++;
    }
    if (S == 'a' && p == lx) {
      ans = 'A';
      break;
    } else if (S == 'b' && q == ly) {
      ans = 'B';
      break;
    } else if (S == 'c' && r == lz) {
      ans = 'C';
      break;
    }
  }
  cout << ans << endl;
}


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

int main() {
  string X, Y, Z;
  cin >> X >> Y >> Z;
  int lx = X.size();
  int ly = Y.size();
  int lz = Z.size();
  int p = 1, q = 0, r = 0;
  char S = X.at(0);
  char ans;
  while (true) {
    if (lx == 1 && S == 'a') {
      ans = 'A';
      break;
    }
    if (S == 'a') {
      S = X.at(p);
      p++;
    } else if (S == 'b') {
      S = Y.at(q);
      q++;
    } else {
      S = Z.at(r);
      r++;
    }
    if (S == 'a' && p == lx) {
      ans = 'A';
      break;
    } else if (S == 'b' && q == ly) {
      ans = 'B';
      break;
    } else if (S == 'c' && r == lz) {
      ans = 'C';
      break;
    }
  }
  cout << ans << endl;
}
Problem p03998 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x[5] = {};
  int p;
  string a[5];
  for (int i = 0; i < 3; i++)
    cin >> a[i];
  while (a[p][x[p]])
    p = a[p][x[p]++] - 'a';
  cout << char('A' + p) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x[5] = {};
  int p = 0;
  string a[5];
  for (int i = 0; i < 3; i++)
    cin >> a[i];
  while (a[p][x[p]])
    p = a[p][x[p]++] - 'a';
  cout << char('A' + p) << endl;
}