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

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

int main() {
  char res[100000] = {};
  int q;
  deque<char> d;
  string s;
  cin >> s >> q;
  for (char &c : s) {
    d.push_back(c);
  }
  int rflag = 0;
  for (int i = 0; i < q; i++) {
    int t, f;
    char c;
    cin >> t;
    if (t == 1) {
      rflag ^= 1;
      continue;
    }
    cin >> f >> c;
    if (rflag == 0 && f == 1) {
      d.push_front(c);
    } else if (rflag == 0 && f == 2) {
      d.push_back(c);
    } else if (rflag == 1 && f == 1) {
      d.push_back(c);
    } else if (rflag == 1 && f == 2) {
      d.push_front(c);
    }
  }
  int i = 0;
  if (rflag) {
    for (auto di = d.rbegin(); di != d.rend(); ++di) {
      res[i++] = *di;
    }
  } else {
    for (auto di = d.begin(); di != d.end(); ++di) {
      res[i++] = *di;
    }
  }
  cout << res << endl;
}


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

int main() {
  char res[300010] = {};
  int q;
  deque<char> d;
  string s;
  cin >> s >> q;
  for (char &c : s) {
    d.push_back(c);
  }
  int rflag = 0;
  for (int i = 0; i < q; i++) {
    int t, f;
    char c;
    cin >> t;
    if (t == 1) {
      rflag ^= 1;
      continue;
    }
    cin >> f >> c;
    if (rflag == 0 && f == 1) {
      d.push_front(c);
    } else if (rflag == 0 && f == 2) {
      d.push_back(c);
    } else if (rflag == 1 && f == 1) {
      d.push_back(c);
    } else if (rflag == 1 && f == 2) {
      d.push_front(c);
    }
  }
  int i = 0;
  if (rflag) {
    for (auto di = d.rbegin(); di != d.rend(); ++di) {
      res[i++] = *di;
    }
  } else {
    for (auto di = d.begin(); di != d.end(); ++di) {
      res[i++] = *di;
    }
  }
  cout << res << endl;
}
Problem p02756 (C++)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 1e6 + 5;

const ll mod = 1e9 + 7;

char s[maxn];

int main() {
  scanf("%s", s + 100000);
  int beg = 100000;
  int end = strlen(s + beg) + beg;
  int flg = 1;
  int q;
  scanf("%d", &q);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      flg = (3 - flg);
    } else {
      int k;
      char c;
      scanf("%d %c", &k, &c);
      if (flg == 1) {
        if (k == 1) {
          s[beg - 1] = c;
          beg--;
        } else {
          s[end++] = c;
        }
      } else {
        if (k == 2) {
          s[beg - 1] = c;
          beg--;
        } else {
          s[end++] = c;
        }
      }
    }
  }
  if (flg == 1) {
    for (int i = beg; i < end; i++) {
      printf("%c", s[i]);
    }
  } else {
    for (int i = end - 1; i >= beg; i--) {
      printf("%c", s[i]);
    }
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 1e6 + 5;

const ll mod = 1e9 + 7;

char s[maxn];

int main() {
  scanf("%s", s + 300000);
  int beg = 300000;
  int end = strlen(s + beg) + beg;
  int flg = 1;
  int q;
  scanf("%d", &q);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      flg = (3 - flg);
    } else {
      int k;
      char c;
      scanf("%d %c", &k, &c);
      if (flg == 1) {
        if (k == 1) {
          s[beg - 1] = c;
          beg--;
        } else {
          s[end++] = c;
        }
      } else {
        if (k == 2) {
          s[beg - 1] = c;
          beg--;
        } else {
          s[end++] = c;
        }
      }
    }
  }
  if (flg == 1) {
    for (int i = beg; i < end; i++) {
      printf("%c", s[i]);
    }
  } else {
    for (int i = end - 1; i >= beg; i--) {
      printf("%c", s[i]);
    }
  }
  return 0;
}
Problem p02756 (C++)

Buggy submission (status: Runtime Error):
/*
        Author: ankrypt
*/

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);

ll N, K, A, B, C;
char arr[1000005];
vector<ll> V;
string S;
ll cases;
ll type;
char X;

int main() {
  IOS;
  cin >> S;
  ll ind = 150005;
  ll l = ind;
  for (int i = 0; i < S.size(); i++) {
    arr[ind] = S[i];
    ind++;
  }
  ll r = ind - 1;
  // cout << l << " " << r << " " << arr[l] << " ";

  // scanf("%lld", &cases);
  cin >> cases;
  ll mark = 0;
  while (cases--) {
    cin >> A;
    if (A == 2) {
      cin >> B;
      cin >> X;
      if (!mark) {
        if (B == 2) {
          r++;
          arr[r] = X;
        } else {
          l--;
          arr[l] = X;
        }
      } else {
        if (B == 2) {
          r--;
          arr[r] = X;
        } else {
          l++;
          arr[l] = X;
        }
      }
    } else {
      mark ^= 1;
      swap(r, l);
    }
  }
  string ans = "";
  if (mark) {
    for (int i = l; i >= r; i--) {
      ans.push_back(arr[i]);
    }
  } else {
    for (int i = l; i <= r; i++) {
      ans.push_back(arr[i]);
    }
  }
  cout << ans << " \n";

  return 0;
}
/*
        Powered by Buggy Plugin
*/


Fixed submission:
/*
        Author: ankrypt
*/

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);

ll N, K, A, B, C;
char arr[1000005];
vector<ll> V;
string S;
ll cases;
ll type;
char X;

int main() {
  IOS;
  cin >> S;
  ll ind = 550005;
  ll l = ind;
  for (int i = 0; i < S.size(); i++) {
    arr[ind] = S[i];
    ind++;
  }
  ll r = ind - 1;
  // cout << l << " " << r << " " << arr[l] << " ";

  // scanf("%lld", &cases);
  cin >> cases;
  ll mark = 0;
  while (cases--) {
    cin >> A;
    if (A == 2) {
      cin >> B;
      cin >> X;
      if (!mark) {
        if (B == 2) {
          r++;
          arr[r] = X;
        } else {
          l--;
          arr[l] = X;
        }
      } else {
        if (B == 2) {
          r--;
          arr[r] = X;
        } else {
          l++;
          arr[l] = X;
        }
      }
    } else {
      mark ^= 1;
      swap(r, l);
    }
  }
  string ans = "";
  if (mark) {
    for (int i = l; i >= r; i--) {
      ans.push_back(arr[i]);
    }
  } else {
    for (int i = l; i <= r; i++) {
      ans.push_back(arr[i]);
    }
  }
  cout << ans << " \n";

  return 0;
}
/*
        Powered by Buggy Plugin
*/
Problem p02756 (C++)

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

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

  string S;
  int Q;
  cin >> S >> Q;

  vector<char> V(300000);
  int l = 100000;
  int r = l + S.size() - 1;
  for (int i = 0; i < S.size(); ++i) {
    V.at(l + i) = S.at(i);
  }
  int fr = 1;

  while (Q--) {
    int T;
    cin >> T;
    if (T == 1) {
      fr ^= 1;
    } else {
      int F;
      char C;
      cin >> F >> C;
      if (F == 1) {
        V.at((fr) ? --l : ++r) = C;
      } else {
        V.at((fr) ? ++r : --l) = C;
      }
    }
  }

  if (fr) {
    for (int i = l; i <= r; ++i) {
      cout << V.at(i);
    }
  } else {
    for (int i = r; i >= l; --i) {
      cout << V.at(i);
    }
  }
  cout << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

  string S;
  int Q;
  cin >> S >> Q;

  vector<char> V(700000);
  int l = 300000;
  int r = l + S.size() - 1;
  for (int i = 0; i < S.size(); ++i) {
    V.at(l + i) = S.at(i);
  }
  int fr = 1;

  while (Q--) {
    int T;
    cin >> T;
    if (T == 1) {
      fr ^= 1;
    } else {
      int F;
      char C;
      cin >> F >> C;
      if (F == 1) {
        V.at((fr) ? --l : ++r) = C;
      } else {
        V.at((fr) ? ++r : --l) = C;
      }
    }
  }

  if (fr) {
    for (int i = l; i <= r; ++i) {
      cout << V.at(i);
    }
  } else {
    for (int i = r; i >= l; --i) {
      cout << V.at(i);
    }
  }
  cout << endl;

  return 0;
}
Problem p02756 (C++)

Buggy submission (status: Runtime Error):


#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char str[10010];
char str1[20010];
char str2[20010];

int main(int argc, char *argv[]) {
  int q = 0;
  int f = 0;
  int t;
  int ff;
  char c;
  int s1 = 0;
  int s2 = 0;
  int i;

  scanf("%s", str);
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &t);
    if (t == 1) {
      if (f)
        f = 0;
      else
        f = 1;
    } else {
      scanf("%d %c", &ff, &c);
      if ((f == 0 && ff == 1) || (f == 1 && ff == 2)) {
        str1[s1++] = c;
      } else {
        str2[s2++] = c;
      }
    }
  }

  // printf( "%d %s %s %s\n", f, str1, str, str2 );

  if (f == 0) {
    int sss;
    for (i = 0; i < s1; i++) {
      printf("%c", str1[s1 - i - 1]);
    }
    sss = strlen(str);
    for (i = 0; i < sss; i++) {
      printf("%c", str[i]);
    }
    for (i = 0; i < s2; i++) {
      printf("%c", str2[i]);
    }
  } else {
    int sss;
    for (i = 0; i < s2; i++) {
      printf("%c", str2[s2 - i - 1]);
    }
    sss = strlen(str);
    for (i = 0; i < sss; i++) {
      printf("%c", str[sss - i - 1]);
    }
    for (i = 0; i < s1; i++) {
      printf("%c", str1[i]);
    }
  }
}


Fixed submission:


#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char str[100010];
char str1[200010];
char str2[200010];

int main(int argc, char *argv[]) {
  int q = 0;
  int f = 0;
  int t;
  int ff;
  char c;
  int s1 = 0;
  int s2 = 0;
  int i;

  scanf("%s", str);
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &t);
    if (t == 1) {
      if (f)
        f = 0;
      else
        f = 1;
    } else {
      scanf("%d %c", &ff, &c);
      if ((f == 0 && ff == 1) || (f == 1 && ff == 2)) {
        str1[s1++] = c;
      } else {
        str2[s2++] = c;
      }
    }
  }

  // printf( "%d %s %s %s\n", f, str1, str, str2 );

  if (f == 0) {
    int sss;
    for (i = 0; i < s1; i++) {
      printf("%c", str1[s1 - i - 1]);
    }
    sss = strlen(str);
    for (i = 0; i < sss; i++) {
      printf("%c", str[i]);
    }
    for (i = 0; i < s2; i++) {
      printf("%c", str2[i]);
    }
  } else {
    int sss;
    for (i = 0; i < s2; i++) {
      printf("%c", str2[s2 - i - 1]);
    }
    sss = strlen(str);
    for (i = 0; i < sss; i++) {
      printf("%c", str[sss - i - 1]);
    }
    for (i = 0; i < s1; i++) {
      printf("%c", str1[i]);
    }
  }
}
Problem p02756 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define been(ix) (ix).begin(), (ix).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix, a) for(auto& (ix) : (a)
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a;
  string s;
  cin >> s >> a;
  ll count = 0;
  rep(i, a) {
    int q;
    cin >> q;
    if (q == 1) {
      count++;
      count = count % 2;
    } else {
      int x;
      char y;
      cin >> x >> y;
      if ((x == 2 && count % 2 == 0))
        s = s + y;
      else if ((x == 1 && count % 2 == 1))
        s = s + y;
      else {
        s = y + s;
      }
    }
  }
  if (count % 2 == 1)
    reverse(been(s));
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define been(ix) (ix).begin(), (ix).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix, a) for(auto& (ix) : (a)
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a;
  string s;
  cin >> s >> a;
  ll count = 0;
  rep(i, a) {
    int q;
    cin >> q;
    if (q == 1) {
      count++;
      count = count % 2;
    } else {
      int x;
      cin >> x;
      if ((x == 2 && count % 2 == 0)) {
        char y;
        cin >> y;
        s.push_back(y);
      } else if ((x == 1 && count % 2 == 1)) {
        char y;
        cin >> y;
        s.push_back(y);
      } else {
        string y;
        cin >> y;
        s.insert(0, y);
      }
    }
  }
  if (count % 2 == 1)
    reverse(been(s));
  cout << s << endl;
}
Problem p02756 (C++)

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

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/

int main() {
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  int rv = 0;
  for (int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      rv++;
    }
    if (t == 2) {
      int f;
      cin >> f;
      char c;
      cin >> c;
      if ((f + rv) % 2 == 0) {
        S.push_back(c);
      } else {
        S = c + S;
      }
    }
  }
  if (rv % 2 == 1) {
    reverse(S.begin(), S.end());
  }
  cout << S << endl;
}

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

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/

int main() {
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  int rv = 0;
  for (int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      rv++;
    }
    if (t == 2) {
      int f;
      cin >> f;
      char c;
      cin >> c;
      if ((f + rv) % 2 == 0) {
        S.push_back(c);
      } else {
        S.insert(S.begin(), c);
      }
    }
  }
  if (rv % 2 == 1) {
    reverse(S.begin(), S.end());
  }
  cout << S << endl;
}
Problem p02756 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n)                                                        \
  std::vector<type> c(n);                                                      \
  for (auto &i : c)                                                            \
    std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main() {
  string s;
  int q;
  cin >> s >> q;
  int cnt = 0;
  int d = 0;
  rep(i, q) {
    int a;
    cin >> a;
    if (a == 1)
      cnt++;
    if (a == 2) {
      int b;
      char c;
      cin >> b >> c;
      if (cnt % 2 == 1) {
        d++;
        if (b == 1)
          b = 2;
        else if (b == 2)
          b = 1;
      }
      if (b == 1)
        s.insert(s.begin(), c);
      if (b == 2)
        s = s + c;
    }
  }
  if (cnt % 2 == 1)
    reverse(ALL(s));
  cout << s << endl;
}


Fixed submission:
#include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n)                                                        \
  std::vector<type> c(n);                                                      \
  for (auto &i : c)                                                            \
    std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main() {
  string s;
  int q;
  cin >> s >> q;
  int cnt = 0;
  int d = 0;
  rep(i, q) {
    int a;
    cin >> a;
    if (a == 1)
      cnt++;
    if (a == 2) {
      int b;
      char c;
      cin >> b >> c;
      if (cnt % 2 == 1) {
        d++;
        if (b == 1)
          b = 2;
        else if (b == 2)
          b = 1;
      }
      if (b == 1)
        s.insert(s.begin(), c);
      if (b == 2)
        s.push_back(c);
    }
  }
  if (cnt % 2 == 1)
    reverse(ALL(s));
  cout << s << endl;
}
Problem p02756 (C++)

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

int main() {
  string s;
  int q, t, f;
  char c;
  cin >> s;
  cin >> q;

  bool is_rev = false; // 文字列が反転しているか否かを表す
  rep(i, q) {
    cin >> t;
    if (t == 1) {
      is_rev = !is_rev;
    } else {
      cin >> f >> c;
      // cout << f << c;
      if (((f == 1) && (is_rev == false)) || ((f == 2) && (is_rev == true))) {
        s = c + s;
      } else {
        s += c;
      }
    }
  }

  if (is_rev == true) {
    reverse(s.begin(), s.end());
  }
  cout << s << endl;

  return 0;
}


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

int main() {
  string s;
  int q, t, f;
  char c;
  cin >> s;
  cin >> q;

  bool is_rev = false; // 文字列が反転しているか否かを表す
  rep(i, q) {
    cin >> t;
    if (t == 1) {
      is_rev = !is_rev;
    } else {
      cin >> f >> c;
      // cout << f << c;
      if (((f == 1) && (is_rev == false)) || ((f == 2) && (is_rev == true))) {
        s.insert(s.begin(), c);
      } else {
        s += c;
      }
    }
  }

  if (is_rev == true) {
    reverse(s.begin(), s.end());
  }
  cout << s << endl;

  return 0;
}
Problem p02756 (C++)

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

const ll MOD = 1e9 + 7;
const int INF = (int)1e9 + 7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int main() {
  deque<char> S;
  string s;
  cin >> s;
  rep(i, s.length()) { S.push_back(s[i]); }
  int Q;
  cin >> Q;
  int T;
  int F;
  char C;
  int revflag = -1;
  rep(i, Q) {
    cin >> T;
    if (T == 1) {
      revflag *= -1;
    } else if (T == 2) {
      cin >> F >> C;
      if (F == 1) {
        if (revflag == 1)
          S.push_back(C);
        else
          S.push_front(C);
      } else if (F == 2) {
        if (revflag == 1)
          S.push_front(C);
        else
          S.push_back(C);
      }
    }
  }
  if (revflag == 1)
    reverse(S.begin(), S.end());
  rep(i, Q + s.length()) { cout << S[i]; }
  cout << endl;
}


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

const ll MOD = 1e9 + 7;
const int INF = (int)1e9 + 7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int main() {
  deque<char> S;
  string s;
  cin >> s;
  rep(i, s.length()) { S.push_back(s[i]); }
  int Q;
  cin >> Q;
  int T;
  int F;
  char C;
  int revflag = -1;
  rep(i, Q) {
    cin >> T;
    if (T == 1) {
      revflag *= -1;
    } else if (T == 2) {
      cin >> F >> C;
      if (F == 1) {
        if (revflag == 1)
          S.push_back(C);
        else
          S.push_front(C);
      } else if (F == 2) {
        if (revflag == 1)
          S.push_front(C);
        else
          S.push_back(C);
      }
    }
  }
  if (revflag == 1)
    reverse(S.begin(), S.end());
  rep(i, S.size()) { cout << S[i]; }
  cout << endl;
}
Problem p02756 (Python)

Buggy submission (status: Runtime Error):
from collections import deque

s = input().strip()
s = deque([*s])
q = int(input())

queries = [input().strip().split() for _ in range(q)]
is_reversed = False

for query in queries:
    t = query[0]
    if t == "1":
        is_reversed = not is_reversed
    else:
        f = query[1]
        c = query[2]
        if f == "1":
            if is_reversed:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if is_reversed:
                s.appendleft(c)
            else:
                s.append(c)

str_list = list(s)
if is_reversed:
    str_list = reversed(str_list)

ans = "".join(str_list)
print(ans)


Fixed submission:
from collections import deque

s = input().strip()
s = deque(list(s))
q = int(input())

queries = [input().strip().split() for _ in range(q)]
is_reversed = False

for query in queries:
    t = query[0]
    if t == "1":
        is_reversed = not is_reversed
    else:
        f = query[1]
        c = query[2]
        if f == "1":
            if is_reversed:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if is_reversed:
                s.appendleft(c)
            else:
                s.append(c)

str_list = list(s)
if is_reversed:
    str_list = reversed(str_list)

ans = "".join(str_list)
print(ans)
Problem p02756 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int, int>
const int mod = 1e9 + 7;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

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

#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif

  string s;
  cin >> s;

  int q;
  cin >> q;
  int st = 1, en = -1;
  int cnt = 0;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      swap(st, en);
      cnt++;
    } else if (t == 2) {

      int x;
      cin >> x;
      string c;
      cin >> c;
      if (x == 1) {
        if (st == 1) {
          s.insert(0, c);
        } else
          s += c;
      } else {
        if (en == 1) {
          s.insert(0, c);
        } else
          s += c;
      }
    }
  }
  if (cnt & 1)
    reverse(s.begin(), s.end());
  cout << s;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int, int>
const int mod = 1e9 + 7;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

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

  string s;
  cin >> s;

  int q;
  cin >> q;
  int st = 1, en = -1;
  int cnt = 0;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      swap(st, en);
      cnt++;
    } else if (t == 2) {

      int x;
      cin >> x;
      string c;
      cin >> c;
      if (x == 1) {
        if (st == 1) {
          s.insert(0, c);
        } else
          s += c;
      } else {
        if (en == 1) {
          s.insert(0, c);
        } else
          s += c;
      }
    }
  }
  if (cnt & 1)
    reverse(s.begin(), s.end());
  cout << s;
}
Problem p02756 (C++)

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

string S, C;
int Q, T, F;
bool rev;

int main() {
  cin >> S >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> T;
    if (T == 1)
      rev ^= 1;
    else {
      cin >> F >> C;
      if (rev ^ (F == 1)) {
        S = C + S;
      } else {
        S += C;
      }
    }
  }
  if (rev)
    reverse(S.begin(), S.end());
  cout << S << endl;
}

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

string S, C;
int Q, T, F;
bool rev;

int main() {
  cin >> S >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> T;
    if (T == 1)
      rev ^= 1;
    else {
      cin >> F >> C;
      if (rev ^ (F == 1)) {
        S.insert(0, C);
      } else {
        S += C;
      }
    }
  }
  if (rev)
    reverse(S.begin(), S.end());
  cout << S << endl;
}
Problem p02756 (C++)

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

using namespace std;

int main(void) {
  string S, beforeS = "", afterS = "";
  int Q, input, count = 0;
  bool flag = false;
  char inputC;
  cin >> S;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> input;
    if (input == 2) {
      cin >> input;
      if (input == 1 && !flag) {
        cin >> inputC;
        beforeS += inputC;
      } else if (input == 1 && flag) {
        cin >> inputC;
        afterS += S;
      } else if (input == 2 && !flag) {
        cin >> inputC;
        afterS += inputC;
      } else {
        cin >> inputC;
        beforeS += inputC;
      }
    } else {
      count++;
      flag = !flag;
    }
  }
  reverse(beforeS.begin(), beforeS.end());
  S = beforeS + S + afterS;
  if (count % 2 == 1) {
    reverse(S.begin(), S.end());
  }
  cout << S << endl;
  return 0;
}

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

using namespace std;

int main(void) {
  string S, beforeS = "", afterS = "";
  int Q, input, count = 0;
  bool flag = false;
  char inputC;
  cin >> S;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> input;
    if (input == 2) {
      cin >> input;
      if (input == 1 && !flag) {
        cin >> inputC;
        beforeS += inputC;
      } else if (input == 1 && flag) {
        cin >> inputC;
        afterS += inputC;
      } else if (input == 2 && !flag) {
        cin >> inputC;
        afterS += inputC;
      } else {
        cin >> inputC;
        beforeS += inputC;
      }
    } else {
      count++;
      flag = !flag;
    }
  }
  reverse(beforeS.begin(), beforeS.end());
  S = beforeS + S + afterS;
  if (count % 2 == 1) {
    reverse(S.begin(), S.end());
  }
  cout << S << endl;
  return 0;
}
Problem p02756 (C++)

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

const int N = 3e5 + 10;
const int INF = 1e5;
char c[N];
string s;
int main() {
  cin >> s;

  int l = INF, r = INF;
  for (int i = 0; i < s.size(); i++, r++) {
    c[r] = s[i];
  }
  r--;

  int n;
  cin >> n;
  bool f = true;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      f = !f;
    } else {
      int p;
      string str;
      cin >> p >> str;

      if (f) {
        if (p == 1) {
          l--;
          c[l] = str[0];
          // s = c + s;
        } else {
          r++;
          c[r] = str[0];
          // s = s + c;
        }
      } else {
        if (p == 1) {
          r++;
          c[r] = str[0];
          // s = s + c;
        } else {
          l--;
          c[l] = str[0];
          // s = c + s;
        }
      }
    }
  }

  if (f) {
    for (int i = l; i <= r; i++)
      cout << c[i];
    cout << endl;
  } else {
    for (int i = r; i >= l; i--)
      cout << c[i];
    cout << endl;
  }

  return 0;
}

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

const int N = 5e5 + 10;
const int INF = 3e5;
char c[N];
string s;
int main() {
  cin >> s;

  int l = INF, r = INF;
  for (int i = 0; i < s.size(); i++, r++) {
    c[r] = s[i];
  }
  r--;

  int n;
  cin >> n;
  bool f = true;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      f = !f;
    } else {
      int p;
      string str;
      cin >> p >> str;

      if (f) {
        if (p == 1) {
          l--;
          c[l] = str[0];
          // s = c + s;
        } else {
          r++;
          c[r] = str[0];
          // s = s + c;
        }
      } else {
        if (p == 1) {
          r++;
          c[r] = str[0];
          // s = s + c;
        } else {
          l--;
          c[l] = str[0];
          // s = c + s;
        }
      }
    }
  }

  if (f) {
    for (int i = l; i <= r; i++)
      cout << c[i];
    cout << endl;
  } else {
    for (int i = r; i >= l; i--)
      cout << c[i];
    cout << endl;
  }

  return 0;
}
Problem p02756 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
list<char> lst;
string s;
int q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> q;
  int n = s.size();
  bool re = 0;
  for (int i = 0; i < n; i++)
    lst.push_back(s[i]);
  while (q--) {
    int t;
    cin >> t;
    if (t == 1)
      re = !re;
    else {
      int f;
      char c;
      cin >> f >> c;
      f--;
      f ^= re;
      if (f == 0)
        lst.push_front(c);
      else
        lst.push_back(c);
    }
  }
  while (lst.size())
    if (re) {
      cout << lst.back();
      lst.pop_back();
    } else {
      cout << lst.front();
      lst.pop_front();
    }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
list<char> lst;
string s;
int q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> q;
  int n = s.size();
  bool re = 0;
  for (int i = 0; i < n; i++)
    lst.push_back(s[i]);
  while (q--) {
    int t;
    cin >> t;
    if (t == 1)
      re = !re;
    else {
      int f;
      char c;
      cin >> f >> c;
      f--;
      f ^= re;
      if (f == 0)
        lst.push_front(c);
      else
        lst.push_back(c);
    }
  }
  if (re == 0)
    for (list<char>::iterator i = lst.begin(); i != lst.end(); i++)
      cout << *i;
  else
    for (list<char>::reverse_iterator i = lst.rbegin(); i != lst.rend(); i++)
      cout << *i;
  return 0;
}
Problem p02756 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define i64 int64_t
#define ff(ii, nn, mm) for (int ii = nn; ii < mm; ii++)
#define ffrvs(ii, nn, mm) for (int ii = nn; ii >= mm; ii--)
#define srt(vvv) sort(vvv.begin(), vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(), vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

i64 cup(i64 xxx, i64 yyy) { // 切り上げ
  return (xxx + yyy - 1) / yyy;
}

// メモリ置き場
deque<string> s;
int q;

// inputします
void input() {
  cin >> s[0];
  cin >> q;
}

// ライブラリ置き場

// main
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  input();
  int gk = 0;
  ff(i, 0, q) {
    int t;
    // scanf("%d", &t);
    cin >> t;
    if (t == 1) {
      gk++;
    }
    if (t == 2) {
      int f;
      // scanf("%d", &f);
      cin >> f;
      string cc;
      // scanf("%s", &cc, 1);
      cin >> cc;
      if ((f + gk) % 2 == 1) {
        s.push_front(cc);
      }
      if ((f + gk) % 2 == 0) {
        s.push_back(cc);
      }
    }
  }
  if (gk % 2 == 1) {
    ffrvs(i, s.size() - 1, 0) {
      ffrvs(j, s[i].size() - 1, 0) { cout << s[i][j]; }
    }
    return 0;
  }
  ff(i, 0, s.size()) { cout << s[i]; }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define i64 int64_t
#define ff(ii, nn, mm) for (int ii = nn; ii < mm; ii++)
#define ffrvs(ii, nn, mm) for (int ii = nn; ii >= mm; ii--)
#define srt(vvv) sort(vvv.begin(), vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(), vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

i64 cup(i64 xxx, i64 yyy) { // 切り上げ
  return (xxx + yyy - 1) / yyy;
}

// メモリ置き場
deque<string> s;
int q;

// inputします
void input() {
  string ss;
  cin >> ss;
  s.push_back(ss);
  cin >> q;
}

// ライブラリ置き場

// main
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  input();
  int gk = 0;
  ff(i, 0, q) {
    int t;
    // scanf("%d", &t);
    cin >> t;
    if (t == 1) {
      gk++;
    }
    if (t == 2) {
      int f;
      // scanf("%d", &f);
      cin >> f;
      string cc;
      // scanf("%s", &cc, 1);
      cin >> cc;
      if ((f + gk) % 2 == 1) {
        s.push_front(cc);
      }
      if ((f + gk) % 2 == 0) {
        s.push_back(cc);
      }
    }
  }
  if (gk % 2 == 1) {
    ffrvs(i, s.size() - 1, 0) {
      ffrvs(j, s[i].size() - 1, 0) { cout << s[i][j]; }
    }
    return 0;
  }
  ff(i, 0, s.size()) { cout << s[i]; }
  return 0;
}
Problem p02756 (C++)

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

using namespace std;

int main() {
  string s;
  cin >> s;
  deque<char> dq;
  for (int i = 0; i < s.size(); ++i) {
    dq.push_back(s[i]);
  }

  int q;
  cin >> q;
  bool rev = false;
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      rev = !rev;
    } else {
      int f;
      char c;
      cin >> f;
      cin >> c;
      if (rev)
        f = 3 - f;
      if (f == 1) {
        dq.push_front(c);
      } else {
        dq.push_back(c);
      }
      string qq(dq.begin(), dq.end());
      // cout << qq << endl;
    }
  }

  if (!rev) {
    cout << string(dq.begin(), dq.end()) << endl;
  } else {
    cout << string(dq.rbegin(), dq.rend()) << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  deque<char> dq;
  for (int i = 0; i < s.size(); ++i) {
    dq.push_back(s[i]);
  }

  int q;
  cin >> q;
  bool rev = false;
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      rev = !rev;
    } else {
      int f;
      char c;
      cin >> f;
      cin >> c;
      if (rev)
        f = 3 - f;
      if (f == 1) {
        dq.push_front(c);
      } else {
        dq.push_back(c);
      }
    }
  }

  if (!rev) {
    cout << string(dq.begin(), dq.end()) << endl;
  } else {
    cout << string(dq.rbegin(), dq.rend()) << endl;
  }

  return 0;
}
Problem p02756 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  bool arr = false;
  int Q;
  cin >> Q;
  S.reserve(S.size() + Q + 10);
  REP(i, Q) {
    int T, F;
    char C;
    cin >> T;
    if (T == 1)
      arr = !arr;
    else {
      cin >> F >> C;
      if (F - 1 ^ arr == 0)
        S = C + S;
      else
        S.append(1, C);
    }
  }
  if (arr == true)
    reverse(S.begin(), S.end());
  cout << S << "\n";
  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;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  bool arr = false;
  int Q;
  cin >> Q;
  S.reserve(S.size() + Q + 10);
  REP(i, Q) {
    int T, F;
    char C;
    cin >> T;
    if (T == 1)
      arr = !arr;
    else {
      cin >> F >> C;
      if (F - 1 ^ arr == 0)
        S.insert(S.begin(), C);
      else
        S.append(1, C);
    }
  }
  if (arr == true)
    reverse(S.begin(), S.end());
  cout << S << "\n";
  return 0;
}
Problem p02756 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main() {
  string s;
  ll q;
  cin >> s >> q;
  ll nrev = 0;
  ll fro = 50000, bck = 50001;
  char ans[100010];
  fro -= s.size() / 2;
  bck += (s.size() + 1) / 2;
  rep(i, fro + 1, bck) ans[i] = s[i - fro - 1];
  rep(i, 0, q) {
    int t;
    cin >> t;
    if (t == 1) {
      nrev++;
    } else {
      int f;
      char c;
      cin >> f >> c;
      if (nrev % 2 == 0) {
        if (f == 1) {
          ans[fro] = c;
          fro--;
        } else {
          ans[bck] = c;
          bck++;
        }
      } else {
        if (f == 1) {
          ans[bck] = c;
          bck++;
        } else {
          ans[fro] = c;
          fro--;
        }
      }
    }
  }

  if (nrev % 2 == 0) {
    rep(i, fro + 1, bck) { cout << ans[i]; }
  } else {
    for (ll i = bck - 1; i > fro; i--) {
      cout << ans[i];
    }
  }
  cout << endl;
  return 0;
}

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

int main() {
  string s;
  ll q;
  cin >> s >> q;
  ll nrev = 0;
  ll fro = 500000, bck = 500001;
  char ans[1000010];
  fro -= s.size() / 2;
  bck += (s.size() + 1) / 2;
  rep(i, fro + 1, bck) ans[i] = s[i - fro - 1];
  rep(i, 0, q) {
    int t;
    cin >> t;
    if (t == 1) {
      nrev++;
    } else {
      int f;
      char c;
      cin >> f >> c;
      if (nrev % 2 == 0) {
        if (f == 1) {
          ans[fro] = c;
          fro--;
        } else {
          ans[bck] = c;
          bck++;
        }
      } else {
        if (f == 1) {
          ans[bck] = c;
          bck++;
        } else {
          ans[fro] = c;
          fro--;
        }
      }
    }
  }

  if (nrev % 2 == 0) {
    rep(i, fro + 1, bck) { cout << ans[i]; }
  } else {
    for (ll i = bck - 1; i > fro; i--) {
      cout << ans[i];
    }
  }
  cout << endl;
  return 0;
}
Problem p02756 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <deque>
using namespace std;
int n, q;
string s;
deque<char> str;
int main() {
  // freopen("main.inp","r",stdin);
  // freopen("main.out","w",stdout);
  cin >> s;
  for (int i = 0; i < s.size(); ++i)
    str.push_back(s[i]);
  cin >> q;
  int dem = 0;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      ++dem;
    } else {
      int r;
      char c;
      cin >> r >> c;
      if (dem % 2 == 0) {
        if (r == 1)
          str.push_front(c);
        else
          str.push_back(c);
      } else {
        if (r == 2)
          str.push_front(c);
        else
          str.push_back(c);
      }
    }
  }
  if (dem % 2 == 0)
    for (int i = 0; i < str.size(); ++i)
      cout << str[i];
  else {
    for (int i = str.size() - 1; i >= 0; ++i)
      cout << str[i];
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <deque>
using namespace std;
int n, q;
string s;
deque<char> str;
int main() {
  // freopen("main.inp","r",stdin);
  // freopen("main.out","w",stdout);
  cin >> s;
  for (int i = 0; i < s.size(); ++i)
    str.push_back(s[i]);
  cin >> q;
  int dem = 0;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      ++dem;
    } else {
      int r;
      char c;
      cin >> r >> c;
      if (dem % 2 == 0) {
        if (r == 1)
          str.push_front(c);
        else
          str.push_back(c);
      } else {
        if (r == 2)
          str.push_front(c);
        else
          str.push_back(c);
      }
    }
  }
  if (dem % 2 == 0)
    for (int i = 0; i < str.size(); ++i)
      cout << str[i];
  else {
    reverse(str.begin(), str.end());
    for (int i = 0; i < str.size(); ++i)
      cout << str[i];
  }
  return 0;
}
Problem p02756 (C++)

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

int main() {
  string S;
  int Q;
  cin >> S >> Q;
  bool rev = false;
  deque<char> deq;
  for (auto e : S)
    deq.push_back(e);
  rep(i, Q) {
    int q = 0;
    cin >> q;
    if (q == 1) {
      rev = !rev;
      continue;
    }
    int F;
    char C;
    cin >> F >> C;
    if (!rev) {
      if (F == 1)
        deq.push_front(C);
      else
        deq.push_back(C);

    } else {
      if (F == 1)
        deq.push_back(C);
      else
        deq.push_front(C);
    }
  }

  if (!rev) {
    for (auto e : deq)
      cout << e;
  } else {
    for (auto it = deq.rbegin(); it != deq.rend(); --it) {
      cout << *it;
    }
  }
  cout << endl;
}

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

int main() {
  string S;
  int Q;
  cin >> S >> Q;
  bool rev = false;
  deque<char> deq;
  for (auto e : S)
    deq.push_back(e);
  rep(i, Q) {
    int q = 0;
    cin >> q;
    if (q == 1) {
      rev = !rev;
      continue;
    }
    int F;
    char C;
    cin >> F >> C;
    if (!rev) {
      if (F == 1)
        deq.push_front(C);
      else
        deq.push_back(C);

    } else {
      if (F == 1)
        deq.push_back(C);
      else
        deq.push_front(C);
    }
  }

  if (!rev) {
    for (auto e : deq)
      cout << e;
  } else {
    for (int i = deq.size() - 1; i >= 0; --i) {
      cout << deq[i];
    }
  }
  cout << endl;
}
Problem p02756 (C++)

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

typedef long long ll;

int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i;
  string s;
  cin >> s;
  int n = s.length();
  vector<char> characs;
  for (i = 0; i < n; i++) {
    characs.push_back(s[i]);
  }

  ll q;
  cin >> q;
  bool reversed = false;
  while (q--) {

    int c;
    cin >> c;
    if (c == 1) {
      if (reversed == true)
        reversed = false;
      else
        reversed = true;
    } else {
      int c1;
      char s1;
      cin >> c1;
      cin >> s1;
      if (c1 == 1) {
        if (reversed)
          characs.push_back(s1);
        else
          characs.insert(characs.begin(), s1);
      } else {
        if (reversed)
          characs.insert(characs.begin(), s1);
        else
          characs.push_back(s1);
      }
    }
    // cout<<reversed<<endl;
  }
  // cout<<s<<endl;
  if (reversed == true) {
    for (i = characs.size() - 1; i >= 0; i--) {
      cout << characs[i];
    }
  } else {
    for (i = 0; i < characs.size(); i++) {
      cout << characs[i];
    }
  }
  cout << endl;

  return 0;
}

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

typedef long long ll;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i;
  string s;
  cin >> s;
  int n = s.length();
  vector<char> characs;
  for (i = 0; i < n; i++) {
    characs.push_back(s[i]);
  }

  ll q;
  cin >> q;
  bool reversed = false;
  while (q--) {

    int c;
    cin >> c;
    if (c == 1) {
      if (reversed == true)
        reversed = false;
      else
        reversed = true;
    } else {
      int c1;
      char s1;
      cin >> c1;
      cin >> s1;
      if (c1 == 1) {
        if (reversed)
          characs.push_back(s1);
        else
          characs.insert(characs.begin(), s1);
      } else {
        if (reversed)
          characs.insert(characs.begin(), s1);
        else
          characs.push_back(s1);
      }
    }
    // cout<<reversed<<endl;
  }
  // cout<<s<<endl;
  if (reversed == true) {
    for (i = characs.size() - 1; i >= 0; i--) {
      cout << characs[i];
    }
  } else {
    for (i = 0; i < characs.size(); i++) {
      cout << characs[i];
    }
  }
  cout << endl;

  return 0;
}
Problem p02756 (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 rep2(s, i, n) for (int i = (int)s; i < (int)(n); i++)

int main() {
  string s;
  int Q;
  int len_s;
  int list_f[100001];
  char list_c[100001];
  int list_t[100001];
  list<char> lst;
  cin >> s >> Q;
  len_s = s.length();
  rep(i, len_s) { lst.push_back(s[i]); }

  bool muki = true;
  for (int i = 1; i <= Q; i++) {
    cin >> list_t[i];
    if (list_t[i] == 2)
      cin >> list_f[i] >> list_c[i];
  }
  for (int i = 1; i <= Q; i++) {
    if (list_t[i] == 1) {
      muki = !muki;
    } else if (list_t[i] == 2) {
      if (list_f[i] == 1) {
        if (muki)
          lst.push_front(list_c[i]);
        else {
          lst.push_back(list_c[i]);
        }
      } else {
        if (muki)
          lst.push_back(list_c[i]);
        else {
          lst.push_front(list_c[i]);
        }
      }
    }
  }

  if (muki) {
    for (auto itr = lst.begin(); itr != lst.end(); ++itr) {
      cout << *itr;
    }
    cout << endl;
  } else {
    for (auto itr = lst.rbegin(); itr != lst.rend(); ++itr) {
      cout << *itr;
    }
    cout << endl;
  }

  return 0;
}

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

int main() {
  string s;
  int Q;
  int len_s;
  int list_f[200001];
  char list_c[200001];
  int list_t[200001];
  list<char> lst;
  cin >> s >> Q;
  len_s = s.length();
  rep(i, len_s) { lst.push_back(s[i]); }

  bool muki = true;
  for (int i = 1; i <= Q; i++) {
    cin >> list_t[i];
    if (list_t[i] == 2)
      cin >> list_f[i] >> list_c[i];
  }
  for (int i = 1; i <= Q; i++) {
    if (list_t[i] == 1) {
      muki = !muki;
    } else if (list_t[i] == 2) {
      if (list_f[i] == 1) {
        if (muki)
          lst.push_front(list_c[i]);
        else {
          lst.push_back(list_c[i]);
        }
      } else {
        if (muki)
          lst.push_back(list_c[i]);
        else {
          lst.push_front(list_c[i]);
        }
      }
    }
  }

  if (muki) {
    for (auto itr = lst.begin(); itr != lst.end(); ++itr) {
      cout << *itr;
    }
    cout << endl;
  } else {
    for (auto itr = lst.rbegin(); itr != lst.rend(); ++itr) {
      cout << *itr;
    }
    cout << endl;
  }

  return 0;
}
Problem p02756 (Python)

Buggy submission (status: Runtime Error):
from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
c = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0]) == 1:
        if c == 0:
            c = 1
        else:
            c = 0
    else:
        if c == 0:
            if int(q[1]) == 1:
                S.appendleft(q[2])
            else:
                S.append[q[2]]
        else:
            if int(q[1]) == 2:
                S.appendleft(q[2])
            else:
                S.append(q[2])
S = list(S)
if c == 0:
    print("".join(S))
else:
    S = S[::-1]
    print("".join(S))


Fixed submission:
from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
c = 0
for _ in range(Q):
    q = list(input().split())
    if int(q[0]) == 1:
        if c == 0:
            c = 1
        else:
            c = 0
    else:
        if c == 0:
            if int(q[1]) == 1:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if int(q[1]) == 2:
                S.appendleft(q[2])
            else:
                S.append(q[2])
S = list(S)
if c == 0:
    print("".join(S))
else:
    S = S[::-1]
    print("".join(S))