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

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

using namespace std;

int main() {

  string A;
  int x, y;

  while (cin >> A) {

    int n;
    cin >> n;

    string Action;

    for (int i = 0; i < n; i++) {

      cin >> Action;
      if (Action == "replace") {

        string replaces;

        cin >> x >> y >> replaces;
        A.replace(x, y, replaces);

      } else if (Action == "reverse") {

        cin >> x >> y;
        reverse(A.begin() + x, A.begin() + y + 1);

      } else {

        cin >> x >> y;
        cout << A.substr(x, y - x + 1) << "\n";
      }
    }
  }
  return 0;
}


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

using namespace std;

int main() {

  string A;
  int x, y;

  while (cin >> A) {

    int n;
    cin >> n;

    string Action;

    for (int i = 0; i < n; i++) {

      cin >> Action;
      if (Action == "replace") {

        string replaces;

        cin >> x >> y >> replaces;
        A.replace(x, y - x + 1, replaces);

      } else if (Action == "reverse") {

        cin >> x >> y;
        reverse(A.begin() + x, A.begin() + y + 1);

      } else {

        cin >> x >> y;
        cout << A.substr(x, y - x + 1) << "\n";
      }
    }
  }
  return 0;
}
Problem p02422 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  string str, moji, m;
  int q = 0;
  cin >> str;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a = 0, b = 0;
    cin >> moji >> a >> b;
    if (moji == "print") {
      str = str.substr(a, b - a + 1);
      cout << str << endl;
    } else if (moji == "reverse") {
      string str2 = str.substr(a, b - a + 1);
      reverse(str2.begin(), str2.end());
      str = str.replace(a, b - a + 1, str2);
    } else if (moji == "replace") {
      cin >> m;
      str = str.replace(a, b - a + 1, m);
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  string str, moji, m;
  int q = 0;
  cin >> str;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a = 0, b = 0;
    cin >> moji >> a >> b;
    if (moji == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (moji == "reverse") {
      string str2 = str.substr(a, b - a + 1);
      reverse(str2.begin(), str2.end());
      str = str.replace(a, b - a + 1, str2);
    } else if (moji == "replace") {
      cin >> m;
      str = str.replace(a, b - a + 1, m);
    }
  }
  return 0;
}
Problem p02422 (C++)

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

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  rep(i, q) {
    string t;
    cin >> t;
    if (t == "print") {
      int a, b;
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
    if (t == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    }
    if (t == "replace") {
      int a, b;
      string p;
      cin >> a >> b >> p;
      s.replace(a, b, p);
    }
  }
}

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

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  rep(i, q) {
    string t;
    cin >> t;
    if (t == "print") {
      int a, b;
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
    if (t == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    }
    if (t == "replace") {
      int a, b;
      string p;
      cin >> a >> b >> p;
      s.replace(a, b - a + 1, p);
    }
  }
}
Problem p02422 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  string str, W, p;
  long long int q, a, b;
  cin >> str >> q;
  REP(i, q) {
    cin >> W >> a >> b;
    if (W == "print") {
      string c(str, a, b - a + 1);
      cout << c << "\n";
    } else if (W == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else if (W == "replace") {
      cin >> p;
      str.replace(a, b, p);
    }
  }
  return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  string str, W, p;
  long long int q, a, b;
  cin >> str >> q;
  REP(i, q) {
    cin >> W >> a >> b;
    if (W == "print") {
      string c(str, a, b - a + 1);
      cout << c << "\n";
    } else if (W == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else if (W == "replace") {
      cin >> p;
      str.replace(a, b - a + 1, p);
    }
  }
  return 0;
}
Problem p02422 (C++)

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

int main() {
  int n;
  string str, s1;
  string order;
  int a, b;
  cin >> str;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> order >> a >> b;
    if (order == "print") {
      for (int i = a; i <= b; i++) {
        cout << str[i];
      }
      cout << "\n";
    } else if (order == "reverse") {
      for (int i = a, j = b; i < j; i++, j--)
        swap(str[i], str[j]);
    } else if (order == "replace") {
      cin >> s1;
      str.replace(a, b, s1);
    }
  }
  return 0;
}


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

int main() {
  int n;
  string str, s1;
  string order;
  int a, b;
  cin >> str;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> order >> a >> b;
    if (order == "print") {
      for (int i = a; i <= b; i++) {
        cout << str[i];
      }
      cout << "\n";
    } else if (order == "reverse") {
      for (int i = a, j = b; i < j; i++, j--)
        swap(str[i], str[j]);
    } else if (order == "replace") {
      cin >> s1;
      str.replace(a, b - a + 1, s1);
    }
  }
  return 0;
}
Problem p02422 (C++)

Buggy submission (status: Runtime Error):
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int q, num1, num2;
  string str, str2, str3; // str1=最初の文字列 str2=条件当てはめる
  cin >> str >> q;

  for (int i = 0; i < q; i++) {
    cin >> str2 >> num1 >> num2;
    if (str2 == "replace") {
      cin >> str3;
      str = str.replace(num1, num2, str3);
    }

    else if (str2 == "reverse") {
      while (num1 <= num2) {
        char tmp;
        tmp = str[num1];
        str[num1] = str[num2];
        str[num2] = tmp;
        num1++;
        num2--;
      }
    }

    else if (str2 == "print") {
      cout << str.substr(num1, num2 - num1 + 1) << endl;
    }
  }

  return 0;
}


Fixed submission:
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int q, num1, num2;
  string str, str2, str3; // str1=最初の文字列 str2=条件当てはめる
  cin >> str >> q;

  for (int i = 0; i < q; i++) {
    cin >> str2 >> num1 >> num2;
    if (str2 == "replace") {
      cin >> str3;
      str = str.replace(num1, num2 - num1 + 1, str3);
    }

    else if (str2 == "reverse") {
      while (num1 <= num2) {
        char tmp;
        tmp = str[num1];
        str[num1] = str[num2];
        str[num2] = tmp;
        num1++;
        num2--;
      }
    }

    else if (str2 == "print") {
      cout << str.substr(num1, num2 - num1 + 1) << endl;
    }
  }

  return 0;
}
Problem p02422 (C++)

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

using namespace std;

int main() {
  string s;
  int q;
  int a, b;

  cin >> s;

  cin >> q;

  string order, str;

  for (int i = 0; i < q; i++) {
    cin >> order;
    if (order == "replace") {
      cin >> a >> b >> str;
      s.replace(a, b, str);
    } else if (order == "reverse") {
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    } else if (order == "print") {
      cin >> a >> b;
      for (int i = a; i <= b; i++) {
        printf("%c", s[i]);
      }
      printf("\n");
    }
  }
  return 0;
}


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

using namespace std;

int main() {
  string s;
  int q;
  int a, b;

  cin >> s;

  cin >> q;

  string order, str;

  for (int i = 0; i < q; i++) {
    cin >> order;
    if (order == "replace") {
      cin >> a >> b >> str;
      s.replace(a, str.size(), str);
    } else if (order == "reverse") {
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    } else if (order == "print") {
      cin >> a >> b;
      for (int i = a; i <= b; i++) {
        printf("%c", s[i]);
      }
      printf("\n");
    }
  }
  return 0;
}
Problem p02422 (C++)

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

int main() {
  char str[1001];
  char com[8];
  int l = 0;
  int a, b;
  int q;
  char c;
  scanf("%s", &str);

  scanf("%d", &q);

  for (int i = 0; i < q; i++) {
    scanf("%s %d %d", &com, &a, &b);
    if (com[2] == 'i') {
      for (int i = a; i <= b; i++) {
        printf("%c", str[i]);
      }
      printf("\n");
    } else if (com[2] == 'v') {
      char t;
      for (int i = 0; i < ((b - a + 1) / 2); i++) {
        t = str[a + i];
        str[a + i] = str[b - i];
        str[b - i] = t;
      }
    } else {
      char r[100];
      scanf("%s", &r);
      for (int j = a; j <= b; j++) {
        str[j] = r[j - a];
      }
    }
  }
  return 0;
}

Fixed submission:
#include <cstdio>

int main() {
  char str[1001];
  char com[8];
  int l = 0;
  int a, b;
  int q;
  char c;
  scanf("%s", &str);

  scanf("%d", &q);

  for (int i = 0; i < q; i++) {
    scanf("%s %d %d", &com, &a, &b);
    if (com[2] == 'i') {
      for (int i = a; i <= b; i++) {
        printf("%c", str[i]);
      }
      printf("\n");
    } else if (com[2] == 'v') {
      char t;
      for (int i = 0; i < ((b - a + 1) / 2); i++) {
        t = str[a + i];
        str[a + i] = str[b - i];
        str[b - i] = t;
      }
    } else {
      char r[1001];
      scanf("%s", &r);
      for (int j = a; j <= b; j++) {
        str[j] = r[j - a];
      }
    }
  }
  return 0;
}
Problem p02422 (C++)

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

int main(void) {
  std::string str;
  int a;
  int b;
  int q;
  std::string start = "";
  std::string sub = "";
  std::string end = "";
  std::string s = "";
  std::cin >> str >> q;

  for (int i = 0; i < q; i++) {
    std::string order;
    std::cin >> order;
    std::cin >> a >> b;
    start = str.substr(0, a);
    sub = str.substr(a, b - a + 1);
    end = str.substr(b + 1, str.size() - b);

    if (order == "replace") {
      s = "";
      std::cin >> s;
      str = start + s + end;
    } else if (order == "reverse") {
      std::reverse(sub.begin(), sub.end());
      str = start + sub + end;
    } else if (order == "print") {
      str = sub;
      std::cout << str << std::endl;
    }
  }

  return EXIT_SUCCESS;
}

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

int main(void) {
  std::string str;
  int a;
  int b;
  int q;
  std::string start = "";
  std::string sub = "";
  std::string end = "";
  std::string s = "";
  std::cin >> str >> q;

  for (int i = 0; i < q; i++) {
    std::string order;
    std::cin >> order;
    std::cin >> a >> b;
    start = str.substr(0, a);
    sub = str.substr(a, b - a + 1);
    end = str.substr(b + 1, str.size() - b);

    if (order == "replace") {
      s = "";
      std::cin >> s;
      str = start + s + end;
    } else if (order == "reverse") {
      std::reverse(sub.begin(), sub.end());
      str = start + sub + end;
    } else if (order == "print") {
      std::cout << sub << std::endl;
    } else {
    }
  }

  return EXIT_SUCCESS;
}
Problem p02422 (C++)

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

void p(char *str, int a, int b) {
  for (int i = a; i <= b; i++)
    std::cout << str[i];
  std::cout << std::endl;
}

void replace(char *str, int a, int b, char *replace_str) {
  for (int i = a; i <= b; i++)
    str[i] = replace_str[i - a];
}

void reverse(char *str, int a, int b) {
  char temp;
  for (int i = 0; i < (b - a + 1) / 2; i++) {
    temp = str[a + i];
    str[a + i] = str[b - i];
    str[b - i] = temp;
  }
}

int main() {
  char str[100], replace_str[100], command[100];
  int q, a, b;
  std::cin >> str >> q;

  for (int i = 0; i < q; i++) {
    std::cin >> command >> a >> b;
    // std::cout << str << "\n\n";
    switch (command[2]) {
    case 'p':
      std::cin >> replace_str;
      replace(str, a, b, replace_str);
      break;
    case 'v':
      reverse(str, a, b);
      break;
    case 'i':
      p(str, a, b);
      break;
    }
    // std::cout << command << " " << a << " " << b << std::endl;
    // std::cout << str << std::endl;;
  }
  return 0;
}


Fixed submission:
#include <iostream>

void p(char *str, int a, int b) {
  for (int i = a; i <= b; i++)
    std::cout << str[i];
  std::cout << std::endl;
}

void replace(char *str, int a, int b, char *replace_str) {
  for (int i = a; i <= b; i++)
    str[i] = replace_str[i - a];
}

void reverse(char *str, int a, int b) {
  char temp;
  for (int i = 0; i < (b - a + 1) / 2; i++) {
    temp = str[a + i];
    str[a + i] = str[b - i];
    str[b - i] = temp;
  }
}

int main() {
  char str[1000], replace_str[1000], command[100];
  int q, a, b;
  std::cin >> str >> q;

  for (int i = 0; i < q; i++) {
    std::cin >> command >> a >> b;
    // std::cout << str << "\n\n";
    switch (command[2]) {
    case 'p':
      std::cin >> replace_str;
      replace(str, a, b, replace_str);
      break;
    case 'v':
      reverse(str, a, b);
      break;
    case 'i':
      p(str, a, b);
      break;
    }
    // std::cout << command << " " << a << " " << b << std::endl;
    // std::cout << str << std::endl;;
  }
  return 0;
}
Problem p02422 (C++)

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

int main() {
  string str, com, p;
  int q, a, b;

  cin >> str >> q;

  for (int i = 0; i < q; i++) {
    cin >> com >> a >> b;
    if (com == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (com == "reverse") {
      string tmp = str.substr(a, b - a + 1);
      int n = tmp.size();
      for (int j = 0; i < n; j++)
        str[j + a] = tmp[n - j - 1];
    } else if (com == "replace") {
      cin >> p;
      str = str.replace(a, b - a + 1, p);
    }
  }
  return 0;
}


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

int main() {
  string str, com, p;
  int q, a, b;

  cin >> str >> q;

  for (int i = 0; i < q; i++) {
    cin >> com >> a >> b;
    if (com == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (com == "reverse") {
      string tmp = str.substr(a, b - a + 1);
      int n = tmp.size();
      for (int j = 0; j < n; j++)
        str[j + a] = tmp[n - j - 1];
    } else if (com == "replace") {
      cin >> p;
      str = str.replace(a, b - a + 1, p);
    }
  }
  return 0;
}
Problem p02422 (C++)

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

int main() {
  int a, b;
  string which, p;

  string str;
  int y;

  cin >> str;
  cin >> y;

  for (int i = 0; i < y; i++) {
    cin >> which >> a >> b;
    if (which == "print") {
      str = str.substr(a, b - a + 1);
      cout << str << endl;
    } else if (which == "replace") {
      cin >> p;
      str = str.replace(a, b - a + 1, p);
    } else if (which == "reverse") {
      string tmp = str.substr(a, b - a + 1);
      int n = tmp.size();
      for (int i = 0; i < n; i++) {
        str[a + i] = tmp[n - i - 1];
      }
    }
  }
  return 0;
}

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

int main() {
  int a, b;
  string which, p;

  string str;
  int y;

  cin >> str;
  cin >> y;

  for (int i = 0; i < y; i++) {
    cin >> which >> a >> b;
    if (which == "print")
      cout << str.substr(a, b - a + 1) << endl;
    else if (which == "replace") {
      cin >> p;
      str = str.replace(a, b - a + 1, p);
    } else if (which == "reverse") {
      string tmp = str.substr(a, b - a + 1);
      int n = tmp.size();
      for (int i = 0; i < n; i++) {
        str[a + i] = tmp[n - i - 1];
      }
    }
  }
  return 0;
}
Problem p02422 (C++)

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

int main() {

  string str;
  int n;
  cin >> str >> n;
  string com;
  for (int i = 0; i < n; i++) {
    cin >> com;
    if (com == "replace") {
      string str1;
      int a, b;
      cin >> a >> b;
      cin >> str1;
      str.replace(a, b, str1);

    } else if (com == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(&str[a], &str[b] + 1);
    } else if (com == "print") {
      int a, b;
      cin >> a >> b;
      b = b - a + 1;
      cout << str.substr(a, b) << endl;
    }

    // cout<<str<<endl;
  }

  return 0;
}


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

int main() {

  string str;
  int n;
  cin >> str >> n;
  string com;
  for (int i = 0; i < n; i++) {
    cin >> com;
    if (com == "replace") {
      string str1;
      int a, b;
      cin >> a >> b;
      cin >> str1;
      str.replace(a, b - a + 1, str1);
      // if(b!=str.size())str+=str.substr(b+1);

    } else if (com == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(&str[a], &str[b] + 1);
    } else if (com == "print") {
      int a, b;
      cin >> a >> b;
      b = b - a + 1;
      cout << str.substr(a, b) << endl;
    }

    // cout<<str<<endl;
  }

  return 0;
}
Problem p02422 (C++)

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

int main() {
  string str;
  int i;
  int a, b;
  string order, str1;

  cin >> str >> i;
  for (int j = 0; j < i; j++) {
    cin >> order >> a >> b;
    if (order == "replace") {
      cin >> str1;
      str.replace(a, b, str1);
    } else if (order == "reverse") {
      while (b - a > 0) {
        swap(str[a], str[b]);
        a++;
        b--;
      }
    } else {
      cout << str.substr(a, b - a + 1) << endl;
    }
    // cout << str << endl;
  }

  return 0;
}


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

int main() {
  string str;
  int i;
  int a, b;
  string order, str1;

  cin >> str >> i;
  for (int j = 0; j < i; j++) {
    cin >> order >> a >> b;
    if (order == "replace") {
      cin >> str1;
      for (int k = 0; k < b - a + 1; k++)
        str[a + k] = str1[k];
    } else if (order == "reverse") {
      while (b - a > 0) {
        swap(str[a], str[b]);
        a++;
        b--;
      }
    } else {
      cout << str.substr(a, b - a + 1) << endl;
    }
    // cout << str << endl;
  }

  return 0;
}
Problem p02422 (C++)

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

int main() {
  string str;
  vector<string> strs;
  int n;
  cin >> str >> n;

  for (int i = 0; i < n; i++) {
    string op;
    int a, b;
    cin >> op >> a >> b;
    if (op == "replace") {
      string rep;
      cin >> rep;
      str = str.replace(a, b, rep);
    } else if (op == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else {
      strs.push_back(str.substr(a, b - a + 1));
    }
  }

  for (int i = 0; i < strs.size(); i++)
    cout << strs[i] << endl;
}


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

int main() {
  string str;
  vector<string> strs;
  int n;
  cin >> str >> n;

  for (int i = 0; i < n; i++) {
    string op;
    int a, b;
    cin >> op >> a >> b;
    if (op == "replace") {
      string tmp;
      cin >> tmp;
      // str.replace(a, b, tmp);
      tmp = str.substr(0, a) + tmp + str.substr(b + 1);
      str = tmp;
    } else if (op == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else {
      strs.push_back(str.substr(a, b - a + 1));
    }
  }

  for (int i = 0; i < strs.size(); i++)
    cout << strs[i] << endl;
}
Problem p02422 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
int main() {
  string s, order, p;
  char ch;
  cin >> s;
  int n, i, a, b;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> order;
    if (order == "replace") {
      cin >> a >> b >> p;
      s.replace(a, b, p);
    }
    if (order == "reverse") {
      cin >> a >> b;
      int left = a;
      int right = b;
      while (left < right) {
        ch = s.at(right);
        s.at(right) = s.at(left);
        s.at(left) = ch;
        right--;
        left++;
      }
    }
    if (order == "print") {
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
  }
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
int main() {
  string s, order, p;
  char ch;
  cin >> s;
  int n, i, a, b;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> order;
    if (order == "replace") {
      cin >> a >> b >> p;
      s.replace(a, b - a + 1, p);
    }
    if (order == "reverse") {
      cin >> a >> b;
      int left = a;
      int right = b;
      while (left < right) {
        ch = s.at(right);
        s.at(right) = s.at(left);
        s.at(left) = ch;
        right--;
        left++;
      }
    }
    if (order == "print") {
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
  }
}
Problem p02422 (C++)

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

using namespace std;

char str[1000 + 1] = {0};

void print(int a, int b) {
  for (; a <= b; a++)
    cout << str[a];
  cout << endl;
}
void reverse(int a, int b) {
  char temp = '\0';
  while (a < b) {
    temp = str[a];
    str[a] = str[b];
    str[b] = temp;
    a++;
    b--;
  }
}
void replace(int a, int b, const char *p) {
  for (int i = 0; i < b - a + 1; i++)
    str[i + a] = p[i];
}

int main() {
  char command[7 + 1] = {0}, p[100 + 1] = {0};

  int q = 0, a = 0, b = 0;

  cin >> str >> q;
  for (int i = 0; i < q; i++) {
    cin >> command >> a >> b;
    if (command[0] == 'p') {
      print(a, b);
    } else if (command[2] == 'v') {
      reverse(a, b);
    } else {
      cin >> p;
      replace(a, b, p);
    }
  }
  return 0;
}

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

using namespace std;

char str[1000 + 1] = {0};

void print(int a, int b) {
  for (; a <= b; a++)
    cout << str[a];
  cout << endl;
}
void reverse(int a, int b) {
  char temp = '\0';
  while (a < b) {
    temp = str[a];
    str[a] = str[b];
    str[b] = temp;
    a++;
    b--;
  }
}
void replace(int a, int b, const char *p) {
  for (int i = 0; i < b - a + 1; i++)
    str[i + a] = p[i];
}

int main() {
  char command[7 + 1] = {0}, p[1000 + 1] = {0};

  int q = 0, a = 0, b = 0;

  cin >> str >> q;
  for (int i = 0; i < q; i++) {
    cin >> command >> a >> b;
    if (command[0] == 'p') {
      print(a, b);
    } else if (command[2] == 'v') {
      reverse(a, b);
    } else {
      cin >> p;
      replace(a, b, p);
    }
  }
  return 0;
}
Problem p02433 (C++)

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

int main() {
  list<int> a;
  list<int>::iterator it = a.end();
  int q, query, t, x;

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> query;
    if (query == 0) {
      cin >> x;
      it = a.insert(it, x);
    } else if (query == 1) {
      cin >> x;
      if (x > 0)
        for (int i = 0; i < x; i++)
          it++;
      else {
        x *= -1;
        for (int i = 0; i < x; i++)
          it--;
      }
    } else {
      a.erase(it);
    } // cout<<" "<<i<<endl;
  }

  for (it = a.begin(); it != a.end(); it++) {
    cout << *it << endl;
  }

  return 0;
}


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

int main() {
  list<int> a;
  list<int>::iterator it = a.end();
  int q, query, t, x;

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> query;
    if (query == 0) {
      cin >> x;
      it = a.insert(it, x);
    } else if (query == 1) {
      cin >> x;
      if (x > 0)
        for (int i = 0; i < x; i++)
          it++;
      else {
        x *= -1;
        for (int i = 0; i < x; i++)
          it--;
      }
    } else {
      it = a.erase(it);
    } // cout<<" "<<i<<endl;
  }

  for (it = a.begin(); it != a.end(); it++) {
    cout << *it << endl;
  }

  return 0;
}
Problem p02435 (C++)

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

int main() {
  int n, q;
  cin >> n >> q;
  vector<stack<int>> vs(n);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    if (a == 0) {
      int t, x;
      cin >> t >> x;
      vs.at(t).push(x);
    }
    if (a == 1) {
      int t;
      cin >> t;
      cout << vs.at(t).top() << endl;
    }
    if (a == 2) {
      int t;
      cin >> t;
      if (!vs.at(t).empty())
        vs.at(t).pop();
    }
  }
}


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

int main() {
  int n, q;
  cin >> n >> q;
  vector<stack<int>> vs(n);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    if (a == 0) {
      int t, x;
      cin >> t >> x;
      vs.at(t).push(x);
    }
    if (a == 1) {
      int t;
      cin >> t;
      if (!vs.at(t).empty())
        cout << vs.at(t).top() << endl;
    }
    if (a == 2) {
      int t;
      cin >> t;
      if (!vs.at(t).empty())
        vs.at(t).pop();
    }
  }
}
Problem p02435 (C++)

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

  int n, q;
  cin >> n >> q;
  stack<int> a[n];

  for (int i = 0; i < q; i++) {
    int n, t;
    cin >> n >> t;
    if (!n) {
      int x;
      cin >> x;
      a[t].push(x);
    } else if (n == 1 && !a[t].empty())
      cout << a[t].top() << endl;
    else
      a[t].pop();
  }

  return 0;
}


Fixed submission:
#include <iostream>
#include <stack>
using namespace std;
int main() {

  int n, q;
  cin >> n >> q;
  stack<int> a[n];

  for (int i = 0; i < q; i++) {
    int n, t;
    cin >> n >> t;
    if (!n) {
      int x;
      cin >> x;
      a[t].push(x);
    } else if (n == 1 && !a[t].empty())
      cout << a[t].top() << endl;
    else if (!a[t].empty())
      a[t].pop();
  }

  return 0;
}
Problem p02435 (C++)

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

int main() {
  int n, q;
  cin >> n >> q;
  vector<stack<int>> s(n);
  while (q--) {
    int y;
    cin >> y;
    if (y == 0) {
      int t, x;
      cin >> t >> x;
      s[t].push(x);
    } else if (y == 1) {
      int t;
      cin >> t;
      if (!s[t].empty()) {
        cout << s[t].top() << endl;
      }
    } else {
      int t;
      cin >> t;
      s[t].pop();
    }
  }
  return 0;
}


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

int main() {
  int n, q;
  cin >> n >> q;
  vector<stack<int>> s(n);
  while (q--) {
    int y;
    cin >> y;
    if (y == 0) {
      int t, x;
      cin >> t >> x;
      s[t].push(x);
    } else if (y == 1) {
      int t;
      cin >> t;
      if (!s[t].empty()) {
        cout << s[t].top() << endl;
      }
    } else {
      int t;
      cin >> t;
      if (!s[t].empty()) {
        s[t].pop();
      }
    }
  }
  return 0;
}
Problem p02435 (C++)

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

using namespace std;

vector<stack<int>> st;

void f0() {
  int p1, p2;
  cin >> p1 >> p2;

  st[p1].push(p2);
}

void f1() {
  int p;
  cin >> p;

  cout << st[p].top() << endl;
}

void f2() {
  int p;
  cin >> p;

  if (!st[p].empty())
    st[p].pop();
}

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

  cin >> n >> q;

  st.resize(n);

  while (q--) {
    int op;
    cin >> op;

    switch (op) {
    case 0:
      f0();
      break;
    case 1:
      f1();
      break;
    case 2:
      f2();
      break;
    }
  }

  return 0;
}


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

using namespace std;

vector<stack<int>> st;

void f0() {
  int p1, p2;
  cin >> p1 >> p2;

  st[p1].push(p2);
}

void f1() {
  int p;
  cin >> p;

  if (!st[p].empty())
    cout << st[p].top() << endl;
}

void f2() {
  int p;
  cin >> p;

  if (!st[p].empty())
    st[p].pop();
}

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

  cin >> n >> q;

  st.resize(n);

  while (q--) {
    int op;
    cin >> op;

    switch (op) {
    case 0:
      f0();
      break;
    case 1:
      f1();
      break;
    case 2:
      f2();
      break;
    }
  }

  return 0;
}
Problem p02435 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <typename T = lint> inline T in() {
  T x;
  cin >> x;
  return x;
}
#define INF 1e9
#define INFL static_cast<lint>(INF)
#define REP(i, n) for (lint i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (lint i = 1, i##_len = (n); i <= i##_len; ++i)
#define REPI(i, ini, n) for (lint i = (ini), i##_len = (n); i < i##_len; ++i)
#define REPC(i, obj) for (auto i : obj)
#define R_UP(a, b) (((a) + (b)-1) / (b))
#define ALL(obj) (obj).begin(), (obj).end()
int main() {
  int n = in(), q = in();
  vector<stack<int>> s(n);
  REP(i, q) {
    int t, x;
    switch (in()) {
    case 0:
      t = in(), x = in();
      s[t].push(x);
      break;
    case 1:
      t = in();
      if (s[t].size() != 0)
        cout << s[t].top() << endl;
      break;
    case 2:
      t = in();
      s[t].pop();
      break;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <typename T = lint> inline T in() {
  T x;
  cin >> x;
  return x;
}
#define INF 1e9
#define INFL static_cast<lint>(INF)
#define REP(i, n) for (lint i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (lint i = 1, i##_len = (n); i <= i##_len; ++i)
#define REPI(i, ini, n) for (lint i = (ini), i##_len = (n); i < i##_len; ++i)
#define REPC(i, obj) for (auto i : obj)
#define R_UP(a, b) (((a) + (b)-1) / (b))
#define ALL(obj) (obj).begin(), (obj).end()
int main() {
  int n = in(), q = in();
  vector<stack<int>> s(n);
  REP(i, q) {
    int t, x;
    switch (in()) {
    case 0:
      t = in(), x = in();
      s[t].push(x);
      break;
    case 1:
      t = in();
      if (s[t].size() != 0)
        cout << s[t].top() << endl;
      break;
    case 2:
      t = in();
      if (s[t].size() != 0)
        s[t].pop();
      break;
    }
  }
}
Problem p02435 (C++)

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

int main() {
  int n, q;
  cin >> n >> q;
  stack<int> s[n];
  while (q--) {
    int a, b, c;
    cin >> a >> b;
    if (!a) {
      cin >> c;
      s[b].push(c);
    } else if (a == 1) {
      cout << s[b].top() << endl;
    } else if (!s[b].empty())
      s[b].pop();
  }
}


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

int main() {
  int n, q;
  cin >> n >> q;
  stack<int> s[n];
  while (q--) {
    int a, b, c;
    cin >> a >> b;
    if (!a) {
      cin >> c;
      s[b].push(c);
    } else if (a == 1) {
      if (!s[b].empty())
        cout << s[b].top() << endl;
    } else if (!s[b].empty())
      s[b].pop();
  }
}
Problem p02435 (Python)

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

if __name__ == "__main__":
    n, q = input().split()
    n, q = int(n), int(q)
    S = [deque([]) for i in range(n)]

    for i in range(q):
        query = input().split()

        if query[0] == "0":
            S[int(query[1])].append(query[2])

        else:
            if len(S) == 0:
                pass
            elif query[0] == "1":
                print(S[int(query[1])][-1])
            else:
                S[int(query[1])].pop()


Fixed submission:
from collections import deque

if __name__ == "__main__":
    n, q = input().split()
    n, q = int(n), int(q)
    S = [deque([]) for i in range(n)]

    for i in range(q):
        query = input().split()

        if query[0] == "0":
            S[int(query[1])].append(query[2])

        else:
            if len(S[int(query[1])]) == 0:
                pass
            elif query[0] == "1":
                print(S[int(query[1])][-1])
            else:
                S[int(query[1])].pop()
Problem p02435 (Python)

Buggy submission (status: Runtime Error):
n, q = list(map(int, input().split(" ")))
stacks = [[] for i in range(n)]

for i in range(q):
    op = list(map(int, input().split(" ")))
    if op[0] == 0:
        stacks[op[1]].append(op[2])
    elif op[0] == 1:
        if len(stacks[op[1]]) != 0:
            print(stacks[op[1]][-1])
    elif op[0] == 2:
        stacks[op[1]].pop()


Fixed submission:
n, q = list(map(int, input().split(" ")))
stacks = [[] for i in range(n)]

for i in range(q):
    op = list(map(int, input().split(" ")))
    if op[0] == 0:
        stacks[op[1]].append(op[2])
    elif op[0] == 1:
        if len(stacks[op[1]]) != 0:
            print(stacks[op[1]][-1])
    elif op[0] == 2:
        if len(stacks[op[1]]) != 0:
            stacks[op[1]].pop()
Problem p02435 (C++)

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

int main() {

  int n, q;
  cin >> n >> q;

  vector<stack<int>> s(n);

  for (int i = 0; i < q; i++) {

    int a, t, x;
    cin >> a;
    if (a == 0) {
      cin >> t >> x;

      s[t].push(x);
    }

    if (a == 1) {
      cin >> t;
      if (!s[t].empty()) {
        cout << s[t].top() << endl;
      }
    }

    if (a == 2) {
      cin >> t;
      s[t].pop();
    }
  }

  return 0;
}


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

int main() {

  int n, q;
  cin >> n >> q;

  vector<stack<int>> s(n);

  for (int i = 0; i < q; i++) {

    int a, t, x;
    cin >> a;
    if (a == 0) {
      cin >> t >> x;

      s[t].push(x);
    }

    if (a == 1) {
      cin >> t;
      if (!s[t].empty()) {
        cout << s[t].top() << endl;
      }
    }

    if (a == 2) {
      cin >> t;
      if (!s[t].empty()) {
        s[t].pop();
      }
    }
  }

  return 0;
}
Problem p02437 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define long long long
#define LF '\n'
using namespace std;
typedef pair<int, int> pii;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a ? a = b, 1 : 0;
}
constexpr int INF = 0x3f3f3f3f;

priority_queue<int> pq[1005];

signed main() {
  cin.tie(nullptr), ios::sync_with_stdio(false);

  int n, q;
  cin >> n >> q;

  while (q--) {
    int com, t, x;
    cin >> com;

    if (com == 0) {
      cin >> t >> x;
      pq[t].emplace(x);
    } else if (com == 1) {
      cin >> t;
      cout << pq[t].top() << LF;
    } else {
      cin >> t;
      if (pq[t].size())
        pq[t].pop();
    }
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define long long long
#define LF '\n'
using namespace std;
typedef pair<int, int> pii;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a ? a = b, 1 : 0;
}
constexpr int INF = 0x3f3f3f3f;

priority_queue<int> pq[1005];

signed main() {
  cin.tie(nullptr), ios::sync_with_stdio(false);

  int n, q;
  cin >> n >> q;

  while (q--) {
    int com, t, x;
    cin >> com;

    if (com == 0) {
      cin >> t >> x;
      pq[t].emplace(x);
    } else if (com == 1) {
      cin >> t;
      if (pq[t].size())
        cout << pq[t].top() << LF;
    } else {
      cin >> t;
      if (pq[t].size())
        pq[t].pop();
    }
  }

  return 0;
}
Problem p02440 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
  int n, q;
  set<int> a;

  cin >> n;
  for (int i = 0, t; i < n && cin >> t; i++)
    a.insert(t);
  cin >> q;
  for (int i = 0, k; i < q; i++) {
    cin >> k;
    cout << binary_search(a.begin(), a.end(), k) << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
  int n, q;
  set<int> a;

  cin >> n;
  for (int i = 0, t; i < n && cin >> t; i++)
    a.insert(t);
  cin >> q;
  for (int i = 0, k; i < q; i++) {
    cin >> k;
    cout << (a.find(k) != a.end()) << endl;
  }

  return 0;
}
Problem p02441 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cin >> q;
  for (int i = 0, k; i < q; i++) {
    cin >> k;
    cout << distance(a.begin(), lower_bound(a.begin(), a.end(), k)) << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cin >> q;
  for (int i = 0, k; i < q; i++) {
    cin >> k;
    cout << distance(a.begin(), lower_bound(a.begin(), a.end(), k)) << endl;
  }

  return 0;
}
Problem p02449 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int n;
vector<vector<int>> v;
vector<int> a, c;
int kaijo(int x) {
  int ans = 1;
  for (int i = 1; i <= x; i++)
    ans *= i;
  return ans;
}
int main() {
  cin >> n;
  a.resize(n);
  c.resize(n);
  rep(i, n) cin >> a[i];
  rep(i, n) c[i] = i + 1;
  do {
    v.push_back(c);
  } while (next_permutation(c.begin(), c.end()));
  rep(i, v.size()) {
    if (v[i] == a) {
      if (i == 0) {
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        i++;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        return 0;
      } else if (i == v.size() - 1) {
        i--;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        i++;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        return 0;
      } else {
        i--;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        i++;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        i++;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        return 0;
      }
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int n;
vector<vector<int>> v;
vector<int> a, c;
int kaijo(int x) {
  int ans = 1;
  for (int i = 1; i <= x; i++)
    ans *= i;
  return ans;
}
int main() {
  cin >> n;
  a.resize(n);
  c.resize(n);
  rep(i, n) cin >> a[i];
  if (n == 1) {
    puts("1");
    return 0;
  }
  rep(i, n) c[i] = i + 1;
  do {
    v.push_back(c);
  } while (next_permutation(c.begin(), c.end()));
  rep(i, v.size()) {
    if (v[i] == a) {
      if (i == 0) {
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        i++;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        return 0;
      } else if (i == v.size() - 1) {
        i--;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        i++;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        return 0;
      } else {
        i--;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        i++;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        i++;
        rep(j, v[i].size()) cout << v[i][j]
                                 << (j == v[i].size() - 1 ? "\n" : " ");
        return 0;
      }
    }
  }
  return 0;
}
Problem p02452 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX_N = 100000;

int n, a[MAX_N], m, b[MAX_N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cin >> m;
  for (int i = 0; i < m; i++)
    cin >> b[i];
  bool flag = true;
  for (int i = 0; i < m; i++) {
    if ((upper_bound(a, a + n, b[i])) - a == lower_bound(a, a + n, b[i]) - a)
      flag = false;
  }
  if (flag)
    cout << 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX_N = 200000;

int n, a[MAX_N], m, b[MAX_N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cin >> m;
  for (int i = 0; i < m; i++)
    cin >> b[i];
  bool flag = true;
  for (int i = 0; i < m; i++) {
    if ((upper_bound(a, a + n, b[i])) - a == lower_bound(a, a + n, b[i]) - a)
      flag = false;
  }
  if (flag)
    cout << 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}
Problem p02452 (C++)

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

long long a[200000];

int main() {
  int n, m, j = 0;
  bool f = 1;

  cin >> n;

  for (int i = 0; i < n; i++)
    cin >> a[i];

  cin >> m;

  for (int i = 0; i < m; i++) {
    long long b;
    cin >> b;

    while (b > a[j])
      j++;

    if (b < a[j]) {
      f = 0;
      break;
    }
  }

  cout << f << endl;

  return 0;
}


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

long long a[200000];

int main() {
  int n, m, j = 0;
  bool f = 1;

  cin >> n;

  for (int i = 0; i < n; i++)
    cin >> a[i];
  a[n] = 1000000001;

  cin >> m;

  for (int i = 0; i < m; i++) {
    long long b;
    cin >> b;

    while (b > a[j])
      j++;

    if (b < a[j]) {
      f = 0;
      break;
    }
  }

  cout << f << endl;

  return 0;
}
Problem p02456 (Python)

Buggy submission (status: Runtime Error):
numset = set([])
q = int(input())
for i in range(q):
    query, x = list(map(int, input().split(" ")))
    if query == 0:
        numset.add(x)
        print(len(numset))
    elif query == 1:
        if set([x]).issubset(numset):
            print(1)
        else:
            print(0)
    else:
        numset.remove(x)


Fixed submission:
numset = set([])
q = int(input())
for i in range(q):
    query, x = list(map(int, input().split(" ")))
    if query == 0:
        numset.add(x)
        print(len(numset))
    elif query == 1:
        if set([x]).issubset(numset):
            print(1)
        else:
            print(0)
    else:
        if set([x]).issubset(numset):
            numset.remove(x)
Problem p02457 (C++)

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

int main() {
  int q;
  cin >> q;
  set<int> st;
  for (int i = 0; i < q; i++) {
    int cmd;
    cin >> cmd;
    if (cmd == 0) {
      int x;
      cin >> x;
      st.insert(x);
      cout << st.size() << endl;
    }
    if (cmd == 1) {
      int x;
      cin >> x;
      cout << st.count(x) << endl;
    }
    if (cmd == 2) {
      int x;
      cin >> x;
      st.erase(x);
    }
    if (cmd == 3) {
      int l, r;
      cin >> l >> r;
      for (int i = l; i <= r; i++) {
        if (st.count(i)) {
          auto itr = st.find(i);
          cout << *itr << endl;
        }
      }
    }
  }
}


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

int main() {
  int q;
  cin >> q;
  set<int> st;
  for (int i = 0; i < q; i++) {
    int cmd;
    cin >> cmd;
    if (cmd == 0) {
      int x;
      cin >> x;
      st.insert(x);
      cout << st.size() << endl;
    }
    if (cmd == 1) {
      int x;
      cin >> x;
      cout << st.count(x) << endl;
    }
    if (cmd == 2) {
      int x;
      cin >> x;
      st.erase(x);
    }
    if (cmd == 3) {
      int l, r;
      cin >> l >> r;
      for (auto itr = st.lower_bound(l), end = st.upper_bound(r); itr != end;
           itr++) {
        cout << *itr << endl;
      }
    }
  }
}
Problem p02457 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iterator>
#include <set>
#include <stdio.h>
using namespace std;
int main() {
  int n, temp, k;
  set<int> s;
  set<int>::iterator u;
  scanf("%d", &n);
  while (n--) {
    scanf("%d%d", &k, &temp);
    if (k == 0) {
      s.insert(temp);
      printf("%ld\n", s.size());
    } else if (k == 1) {
      if (s.find(temp) == s.end())
        printf("0\n");
      else
        printf("1\n");
    } else if (k == 2)
      s.erase(temp);
    else {
      u = s.lower_bound(temp);
      scanf("%d", &temp);
      while (u != s.end()) {
        if (*u > temp)
          break;
        printf("%d\n", *u);
      }
    }
  }
}


Fixed submission:
#include <iterator>
#include <set>
#include <stdio.h>
using namespace std;
int main() {
  int n, temp, k;
  set<int> s;
  set<int>::iterator u;
  scanf("%d", &n);
  while (n--) {
    scanf("%d%d", &k, &temp);
    if (k == 0) {
      s.insert(temp);
      printf("%ld\n", s.size());
    } else if (k == 1) {
      if (s.find(temp) == s.end())
        printf("0\n");
      else
        printf("1\n");
    } else if (k == 2)
      s.erase(temp);
    else {
      u = s.lower_bound(temp);
      scanf("%d", &temp);
      while (u != s.end()) {
        if (*u > temp)
          break;
        printf("%d\n", *u);
        u++;
      }
    }
  }
}
Problem p02457 (C++)

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

int main(void) {
  set<int> S;
  int q, com, x, y;
  cin >> q;
  while (q--) {
    cin >> com;
    switch (com) {
    case 0:
      cin >> x;
      S.insert(x);
      cout << S.size() << endl;
      break;
    case 1:
      cin >> x;
      if (S.find(x) != S.end()) {
        cout << "1\n";
      } else {
        cout << "0\n";
      }
      break;
    case 2:
      cin >> x;
      S.erase(x);
      break;
    case 3:
      cin >> x >> y;
      for (int i = x; i <= y; i++) {
        if (S.find(i) != S.end()) {
          cout << i << endl;
        }
      }
      break;
    }
  }
}


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

int main(void) {
  set<int> S;
  int q, com, x, y;
  cin >> q;
  while (q--) {
    cin >> com;
    switch (com) {
    case 0:
      cin >> x;
      S.insert(x);
      cout << S.size() << endl;
      break;
    case 1:
      cin >> x;
      if (S.find(x) != S.end()) {
        cout << "1\n";
      } else {
        cout << "0\n";
      }
      break;
    case 2:
      cin >> x;
      S.erase(x);
      break;
    case 3:
      cin >> x >> y;
      set<int>::iterator it = S.lower_bound(x);
      set<int>::iterator end = S.upper_bound(y);
      while (it != end) {
        cout << *it << endl;
        it++;
      }
      break;
    }
  }
}