alexjercan/bugnet huggingface dataset:
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

string str;

string print(int a, int b) {
  string str2;
  str2 = str.substr(a, b - a + 1);
  return str2;
}

string reverse(int a, int b) {
  string str2;
  str2 = str.substr(a, b - a + 1);
  int len = str2.length();
  string str3 = str2;
  for (int i = 0; i < len; i++) {
    str2[i] = str3[len - 1 - i];
  }
  str2 = str.replace(a, len, str2);
  return str2;
}

string replace(int a, string s) {
  string str2;
  int len = s.length();
  str2 = str.replace(a, len, s);
  return str2;
}

int main() {
  int n, a, b;
  string cmd, s;
  cin >> str >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd >> a >> b;
    if (cmd == "print") {
      cout << print(a, b) << endl;
    }
    if (cmd == "reverse") {
      str = reverse(a, b);
    }
    if (cmd == "replace") {
      cin >> s;
      str = replace(a, s);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

string str;

string print(int a, int b) {
  str = str.substr(a, b - a + 1);
  return str;
}

string reverse(int a, int b) {
  string str2;
  str2 = str.substr(a, b - a + 1);
  int len = str2.length();
  string str3 = str2;
  for (int i = 0; i < len; i++) {
    str2[i] = str3[len - 1 - i];
  }
  str = str.replace(a, len, str2);
  return str;
}

string replace(int a, string s) {
  int len = s.length();
  str = str.replace(a, len, s);
  return str;
}

int main() {
  int n, a, b;
  string cmd, s;
  cin >> str >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd >> a >> b;
    if (cmd == "print") {
      cout << print(a, b) << endl;
    }
    if (cmd == "reverse") {
      str = reverse(a, b);
    }
    if (cmd == "replace") {
      cin >> s;
      str = replace(a, s);
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>

int main(void) {
  char str[1001] = {};
  char tempStr[1001] = {};
  std::cin >> str;
  int q;
  std::cin >> q;
  char in[8] = {};
  for (int i = 0; i < q; i++) {
    std::cin >> in;
    if (in[0] == 'r' && in[1] == 'e' && in[2] == 'p' && in[3] == 'l' &&
        in[4] == 'a' && in[5] == 'c' && in[6] == 'e' && in[7] == '\\0') {
      int a, b;
      std::cin >> a >> b;
      std::cin >> tempStr;
      for (int i = 0; i < b - a + 1; i++) {
        str[a + i] = tempStr[i];
      }
    } else if (in[0] == 'r' && in[1] == 'e' && in[2] == 'v' && in[3] == 'e' &&
               in[4] == 'r' && in[5] == 's' && in[6] == 'e' && in[7] == '\\0') {
      int a, b;
      std::cin >> a >> b;
      for (int i = 0; i < b - a + 1; i++) {
        tempStr[i] = str[a + i];
      }
      for (int i = 0; i < b - a + 1; i++) {
        str[a + i] = tempStr[b - a - i];
      }
    } else if (in[0] == 'p' && in[1] == 'r' && in[2] == 'i' && in[3] == 'n' &&
               in[4] == 't' && in[5] == '\\0') {
      int a, b;
      std::cin >> a >> b;
      for (int i = a; i <= b; i++) {
        std::cout << str[i];
      }
      std::cout << '\\n';
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>

int main(void) {
  char str[1001];
  std::cin >> str;
  int q;
  std::cin >> q;
  char in[8];
  for (int i = 0; i < q; i++) {
    std::cin >> in;
    if (in[0] == 'r' && in[1] == 'e' && in[2] == 'p' && in[3] == 'l' &&
        in[4] == 'a' && in[5] == 'c' && in[6] == 'e' && in[7] == '\\0') {
      int a, b;
      std::cin >> a >> b;
      char *replaceStr = new char[b - a + 1];
      std::cin >> replaceStr;
      for (int i = 0; i < b - a + 1; i++) {
        str[a + i] = replaceStr[i];
      }
      delete[] replaceStr;
      replaceStr = 0;
    } else if (in[0] == 'r' && in[1] == 'e' && in[2] == 'v' && in[3] == 'e' &&
               in[4] == 'r' && in[5] == 's' && in[6] == 'e' && in[7] == '\\0') {
      int a, b;
      std::cin >> a >> b;
      char *tempStr = new char[b - a + 1];
      for (int i = 0; i < b - a + 1; i++) {
        tempStr[i] = str[a + i];
      }
      for (int i = 0; i < b - a + 1; i++) {
        str[a + i] = tempStr[b - a - i];
      }
      delete[] tempStr;
      tempStr = 0;
    } else if (in[0] == 'p' && in[1] == 'r' && in[2] == 'i' && in[3] == 'n' &&
               in[4] == 't' && in[5] == '\\0') {
      int a, b;
      std::cin >> a >> b;
      for (int i = a; i <= b; i++) {
        std::cout << str[i];
      }
      std::cout << '\\n';
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string str;
  cin >> str;
  int q;
  cin >> q;

  for (int i = 0; i < q; i++) {
    string com, strpr, p;
    int a, b;
    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 i = 0; i < n; i++) {
        str[i + a] = tmp[n - i - 1];
      }
    } else if (com == "replace") {
      cin >> p;
      str = str.replace(a, b - a + 1, p);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cctype>
#include <iostream>
#include <string>
using namespace std;

int main() {
  string str;
  cin >> str;
  int q;
  cin >> q;

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

  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: 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 - 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;
}


Error: 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, 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;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include "algorithm"
#include "iostream"
#include "string"
using namespace std;

int main(int argc, char const *argv[]) {
  string str;
  int q = 0;
  string sub1, sub4, rev;
  int sub2, sub3;
  cin >> str;
  cin >> q;

  for (int i = 0; i < q; ++i) {
    cin >> sub1;
    if (sub1 == "print") {
      cin >> sub2 >> sub3;
      cout << str.substr(sub2, sub3 - sub2 + 1) << endl;
    } else if (sub1 == "reverse") {
      cin >> sub2 >> sub3;
      rev = str.substr(sub2, sub3 - sub2 + 1);
      reverse(rev.begin(), rev.end());
      str = str.replace(sub2, rev.size(), rev);
    } else if (sub1 == "replace") {
      cin >> sub2 >> sub3 >> sub4;
      str = str.replace(sub2, sub3 - sub2 + 1, sub4);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include "algorithm"
#include "iostream"
#include "string"
using namespace std;

int main(int argc, char const *argv[]) {
  string str;
  int q = 0;
  string sub1, sub4;
  int sub2, sub3;
  cin >> str;
  cin >> q;

  for (int i = 0; i < q; ++i) {
    cin >> sub1;
    if (sub1 == "print") {
      cin >> sub2 >> sub3;
      cout << str.substr(sub2, sub3 - sub2 + 1) << endl;
    } else if (sub1 == "reverse") {
      cin >> sub2 >> sub3;
      string rev;
      rev = str.substr(sub2, sub3 - sub2 + 1);
      reverse(rev.begin(), rev.end());
      str = str.replace(sub2, rev.size(), rev);
    } else if (sub1 == "replace") {
      cin >> sub2 >> sub3 >> sub4;
      str = str.replace(sub2, sub3, sub4);
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: 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 - 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;
}


Error: 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, 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, verdict: 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[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;
}

Error: 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[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;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  string t, op, p;
  int q, a, b;

  cin >> t;
  cin >> q;

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

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  string t, op, p;
  int q, a, b;

  cin >> t;
  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> op;
    if (op == "print") {
      cin >> a >> b;
      cout << t.substr(a, b + 1) << endl;
    }
    if (op == "reverse") {
      cin >> a >> b;
      reverse(t.begin() + a, t.begin() + b + 1);
    }
    if (op == "replace") {
      cin >> a >> b >> p;
      t.replace(a, b, p);
    }
  }

  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string str;
  int i;
  cin >> str;
  cin >> i;
  while (i--) {
    string A, B;
    int X, Y;
    cin >> A >> X >> Y;
    if (A == "replace") {
      cin >> B;
      str.replace(str.begin() + X, str.begin() + Y + 1, B);
    } else if (A == "reverse") {
      reverse(str.begin() + X, str.begin() + Y + 1);
    } else {
      for (int gg = X; gg <= Y; gg++) {
        cout << str.at(gg);
      }
      cout << endl;
    }
  }
  return 0;
}

/*switch(A){
                        case "replace":cin>>B;str.replace(X,Y,B);break;
                        //case "reverse":reverse(str.X,str.Y);break;
                        case "print":for(int
   gg=X;gg<=Y;gg++){cout<<str.at(gg);}cout<<endl;break;
                }*/

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string str;
  int i;

  cin >> str;
  cin >> i;
  while (i--) {
    string A, B;
    int X, Y;
    cin >> A >> X >> Y;
    if (Y == 0)
      continue;
    if (A == "replace") {
      cin >> B;
      str.replace(str.begin() + X, str.begin() + X + X - Y + 1, B);
    } else if (A == "reverse") {
      reverse(str.begin() + X, str.begin() + Y + 1);
    } else {
      for (int gg = X; gg <= Y; gg++) {
        cout << str.at(gg);
      }
      cout << endl;
    }
  }
  return 0;
}

/*switch(A){
                        case "replace":cin>>B;str.replace(X,Y,B);break;
                        //case "reverse":reverse(str.X,str.Y);break;
                        case "print":for(int
   gg=X;gg<=Y;gg++){cout<<str.at(gg);}cout<<endl;break;
                }*/
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

int main(void) {
  std::string input;
  int q;

  std::cin >> input;
  std::cin >> q;

  for (int i = 0; i < q; i++) {
    std::string command;
    int start = 0;
    int end = 0;

    std::cin >> command;
    std::cin >> start >> end;

    if (command == "print") {
      std::string output = input.substr(start, end - start + 1);

      std::cout << output << std::endl;
    } else if (command == "reverse") {
      for (int i = 0; i < ((end - start + 1) / 2); i++) {
        char tmp = input[start + i];
        input[start + i] = input[end - i];
        input[end - i] = tmp;
      }
    } else if (command == "replace") {
      std::string target;
      std::cin >> target;

      input = input.replace(start, end - start + 1, target);
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

int main(void) {
  std::string input;
  int q;

  std::cin >> input;
  std::cin >> q;

  for (int i = 0; i < q; i++) {
    std::string command;
    int start = 0;
    int end = 0;

    std::cin >> command;
    std::cin >> start >> end;

    if (command == "print") {
      input = input.substr(start, end - start + 1);

      std::cout << input << std::endl;
    } else if (command == "reverse") {
      for (int i = 0; i < ((end - start + 1) / 2); i++) {
        char tmp = input[start + i];
        input[start + i] = input[end - i];
        input[end - i] = tmp;
      }
    } else if (command == "replace") {
      std::string target;
      std::cin >> target;

      input = input.replace(start, end - start + 1, target);
    }
  }

  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <time.h>
#include <vector>

int main(void) {

  // test??¨
  // std::ifstream in("test.txt");
  // std::cin.rdbuf(in.rdbuf());

  std::string str;
  std::cin >> str;

  int n;
  std::cin >> n;

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

    std::string cmd;
    std::cin >> cmd;
    int st, ed;
    std::cin >> st >> ed;

    if (cmd == "print") {
      std::cout << str.substr(st, ed - st + 1) << std::endl;
    } else if (cmd == "reverse") {
      std::reverse(str.begin() + st, str.begin() + ed + 1);
    } else {
      std::string temp;
      std::cin >> temp;
      str.replace(st, ed - st + 1, temp);
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <time.h>
#include <vector>

int main(void) {

  // test??¨
  // std::ifstream in("test.txt");
  // std::cin.rdbuf(in.rdbuf());

  std::string str;
  std::cin >> str;

  int n;
  std::cin >> n;

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

    std::string cmd;
    std::cin >> cmd;
    int st, ed;
    std::cin >> st >> ed;

    if (cmd == "print") {
      std::cout << str.substr(st, ed + 1) << std::endl;
    } else if (cmd == "reverse") {
      std::reverse(str.begin() + st, str.begin() + ed + 1);
    } else {
      std::string temp;
      std::cin >> temp;
      str.replace(st, ed, temp);
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str, com, temp, s;
  int q, a, b, p;
  cin >> str >> q;
  for (int i = 0; i <= q - 1; i++) {
    cin >> com >> a >> b;
    if (com == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (com == "reverse") {
      temp = str.substr(a, b - a + 1);
      int n = temp.size();
      for (int i = 0; i <= n - 1; i++) {
        str[a + i] = temp[n - 1 - i];
      }
    } else if (com == "replace") {
      cin >> s;
      str = str.replace(a, b - a + 1, s);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str, com, temp, s;
  int q, a, b, p;
  cin >> str >> q;
  for (int i = 0; i <= q - 1; i++) {
    cin >> com >> a >> b;
    if (com == "print") {
      str = str.substr(a, b - a + 1);
      cout << str << endl;
    } else if (com == "reverse") {
      temp = str.substr(a, b - a + 1);
      int n = temp.size();
      for (int i = 0; i <= n - 1; i++) {
        str[a + i] = temp[n - 1 - i];
      }
    } else if (com == "replace") {
      cin >> s;
      str = str.replace(a, b - a + 1, s);
    }
  }

  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: 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; 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;
}


Error: -11

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; 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;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <sstream>

int main(int argc, char const *argv[]) {
  std::string str;
  std::cin >> str;
  int x;
  std::cin >> x;
  for (int i = 0; i < x; i++) {
    std::string order;
    std::cin >> order;
    if (order == "replace") {
      int a, b;
      std::string s;
      std::cin >> a >> b >> s;
      str.replace(a, b - a + 1, s);
    } else if (order == "reverse") {
      int a, b;
      std::cin >> a >> b;
      reverse(str.begin() + a, str.begin() + b + 1);
    } else if (order == "print") {
      int a, b;
      std::cin >> a >> b;
      std::string print;
      print = str.substr(a, b - a + 1);
      std::cout << print << std::endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <sstream>

int main(int argc, char const *argv[]) {
  std::string str;
  std::cin >> str;
  int x;
  std::cin >> x;
  for (int i = 0; i < x; i++) {
    std::string order;
    std::cin >> order;
    if (order == "replace") {
      int a, b;
      std::string s;
      std::cin >> a >> b >> s;
      str.replace(a, b, s);
    } else if (order == "reverse") {
      int a, b;
      std::cin >> a >> b;
      int reverse = b;
      for (int i = a; i <= (b / 2); i++) {
        char temp;
        temp = str[i];
        str[i] = str[reverse];
        str[reverse] = temp;
        reverse--;
      }
    } else if (order == "print") {
      int a, b;
      std::cin >> a >> b;
      for (int i = a; i <= b; i++) {
        std::cout << str[i];
      }
      std::cout << std::endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;

int main() {
  string s, ss, sss;
  int n, m, l;
  cin >> s;
  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> ss >> m >> l;
    if (ss == "replace") {
      cin >> sss;
      s.replace(m, l - m + 1, sss);
    } else if (ss == "reverse") {
      string temp = s.substr(m, l - m + 1);
      for (int j = 0; j < temp.size(); ++j) {
        s[j + m] = temp[temp.size() - j - 1];
      }
    } else if (ss == "print") {
      cout << s.substr(m, l - m + 1) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
string rev_string(string s, int m, int l) {
  int ii = 0;
  for (ii = m; ii < (l) / 2; ii++) {
    char temp = s[ii];
    s[ii] = s[l - ii];
    s[l - ii] = temp;
  }
  return s;
}
int main() {
  string s, ss, sss;
  int n, m, l;
  cin >> s;
  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> ss >> m >> l;
    if (ss == "replace") {
      cin >> sss;
      s.replace(m, l, sss);
    } else if (ss == "reverse") {
      s = rev_string(s, m, l);
    } else if (ss == "print") {
      cout << s.substr(m, l - m + 1) << endl;
    }
  }
}