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

#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  string str, E, ttt, kkk, lll, p, O;
  long q, a, b;

  cin >> str >> q;

  for (long s = 0; s < q; s++) {
    cin >> E >> a >> b;
    if (E == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    }

    else if (E == "reverse") {
      /*ttt = str.substr(a,b - a + 1);
      kkk = str.substr(0,a);
      lll = str.substr(b - a + 1,str.size() - b - 1);

      reverse(ttt.begin(),ttt.end());
      str = kkk + ttt + lll;*/
      reverse(str.begin() + a, str.begin() + b + 1);
    }

    else if (E == "replace") {
      cin >> p;
      str.replace(a, p.length(), p);

      /*cin >> p;

      O = p;
      kkk = str.substr(0,a);
      lll = str.substr(b - a + 1,str.size() - b - 1);

      str = kkk + O + lll;*/
    }
  }
}

Error: -6
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string: construction from null is not valid


Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  string str, E, ttt, kkk, lll, p = 0, O = 0;
  int q, a, b;

  cin >> str >> q;
  cout << str << q;
  for (int s = 0; s < q; s++) {
    cin >> E >> a >> b;
    if (E == "print") {
      cout << str.substr(a, b) << endl;
    }

    else if (E == "reverse") {
      ttt = str.substr(a, b);
      kkk = str.substr(0, a);
      lll = str.substr(b, str.size());

      reverse(ttt.begin() + a, ttt.end() + b + 1);
      str = kkk + ttt + lll;
    }

    else if (E == "repleace") {

      cin >> p;

      O = p;
      kkk = str.substr(0, a);
      lll = str.substr(b, str.size());

      str = kkk + O + lll;
    }

    if (s == q) {
      break;
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: 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[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;
}


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


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

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  int q;
  cin >> s >> q;
  cin.ignore();

  string buf;
  while (q) {
    getline(cin, buf);

    // cout << "DEBUG:" << buf << endl;

    if (buf.find("replace ") != string::npos) {
      char cmd[10] = {0};
      int a1, a2;
      char a3[1001] = {0};
      sscanf(buf.c_str(), "%s %d %d %s", cmd, &a1, &a2, a3);
      s.replace(a1, (a2 + 1) - a1, string(a3));
      // cout << "DEBUG:replaced:" << s << endl;
    } else if (buf.find("reverse ") != string::npos) {
      char cmd[10] = {0};
      int a1, a2;
      sscanf(buf.c_str(), "%s %d %d", cmd, &a1, &a2);
      string sub = s.substr(a1, (a2 + 1) - a1);
      // cout << "DEBUG:sub( ):" << sub << endl;
      reverse(sub.begin(), sub.end());
      // cout << "DEBUG:sub(r):" << sub << endl;
      size_t subsize = sub.size();
      for (int i = a1, j = 0; i < a1 + subsize; i++, j++) {
        s[i] = sub[j];
      }
      // cout << "DEBUG:reversed:" << s << endl;
    } else if (buf.find("print ") != string::npos) {
      char cmd[10] = {0};
      int a1, a2;
      sscanf(buf.c_str(), "%s %d %d", cmd, &a1, &a2);
      cout << s.substr(a1, (a2 + 1) - a1) << endl;
    }
    q--;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  int q;
  cin >> s >> q;
  cin.ignore();

  string buf;
  while (q) {
    getline(cin, buf);

    // cout << "DEBUG:" << buf << endl;

    if (buf.find("replace ") != string::npos) {
      char cmd[10] = {0};
      int a1, a2;
      char a3[1001] = {0};
      sscanf(buf.c_str(), "%s %d %d %s", cmd, &a1, &a2, a3);
      s = s.replace(a1, a2, string(a3));
      // cout << "DEBUG:replaced:" << s << endl;
    } else if (buf.find("reverse ") != string::npos) {
      char cmd[10] = {0};
      int a1, a2;
      sscanf(buf.c_str(), "%s %d %d", cmd, &a1, &a2);
      string sub = s.substr(a1, a2 + 1);
      // cout << "DEBUG:sub:" << sub << endl;
      size_t subsize = sub.size() - 1;
      for (int i = a1; i < a2 + 1; i++) {
        s[i] = sub[subsize];
        subsize--;
      }
      // cout << "DEBUG:reversed:" << s << endl;
    } else if (buf.find("print ") != string::npos) {
      char cmd[10] = {0};
      int a1, a2;
      sscanf(buf.c_str(), "%s %d %d", cmd, &a1, &a2);
      cout << s.substr(a1, (a2 + 1) - a1) << endl;
    }
    q--;
  }

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

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

#define FOR(i, a, b) for (int i = int(a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)

int q;

int main() {
  int a, b;
  string str, q_str, m_str;
  cin >> str;
  cin >> q;
  REP(i, q) {
    cin >> q_str;
    cin >> a >> b;
    if (q_str == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (q_str == "replace") {
      cin >> q_str;
      m_str = str.erase(a, b - a + 1);
      str = m_str.insert(a, q_str);
    } else {
      reverse(str.begin() + a, str.begin() + b + 1);
    }
    // cout << str << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

#define FOR(i, a, b) for (int i = int(a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)

int q;

int main() {
  int a, b;
  string str, q_str, m_str;
  cin >> str;
  cin >> q;
  REP(i, q) {
    cin >> q_str;
    cin >> a >> b;
    if (q_str == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (q_str == "replace") {
      cin >> q_str;
      m_str = str.erase(a, b);
      str = m_str.insert(a, q_str);
    } else {
      reverse(str.begin() + a, str.begin() + b + 1);
    }
    // cout << str << endl;
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
int main() {
  char s[1010];
  int n, a, b;
  string str[3] = {"replace", "reverse", "print"};
  cin >> s >> n;
  string s0 = s;
  rep(i, n) {
    char p[110];
    cin >> p >> a >> b;
    string s1 = p;
    if (!s1.compare(str[0])) {
      char q[1010];
      cin >> q;
      s0.replace(a, b - a + 1, q);
    } else if (!s1.compare(str[1])) {
      string s2 = s0.substr(0, a);
      string s3 = s0.substr(a, b - a + 1);
      string s4 = s0.substr(b + 1);
      string s5;
      for (int j = 0; j < b - a + 1; ++j) {
        s5 += s3.at(b - a - j);
      }
      s0 = s2 + s5 + s4;
    } else if (!s1.compare(str[2])) {
      rep2(j, a, b + 1) { cout << s0.at(j); }
      cout << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
int main() {
  char s[1010];
  int n, a, b;
  string str[3] = {"replace", "reverse", "print"};
  cin >> s >> n;
  string s0 = s;
  rep(i, n) {
    char p[110];
    cin >> p >> a >> b;
    string s1 = p;
    if (!s1.compare(str[0])) {
      char q[110];
      cin >> q;
      s0.replace(a, b - a + 1, q);
    } else if (!s1.compare(str[1])) {
      string s2 = s0.substr(0, a);
      string s3 = s0.substr(a, b - a + 1);
      string s4 = s0.substr(b + 1);
      const char *s5 = s3.c_str();
      string s6;
      for (int j = 0; j < b - a + 1; ++j) {
        s6 += s5[b - a - j];
      }
      s0 = s2 + s6 + s4;
    } else if (!s1.compare(str[2])) {
      rep2(j, a, b + 1) { cout << s0.at(j); }
      cout << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

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

  cin >> str >> q;

  for (int32_t i = 0; i < q; i++) {
    cin >> op >> a >> b;

    if (op == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (op == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else if (op == "replace") {
      cin >> p;
      str.replace(str.begin() + a, str.begin() + b + 1, p);
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

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

  cin >> str >> q;

  for (int32_t i = 0; i < q; i++) {
    cin >> op;

    if (op == "print") {
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    } else if (op == "reverse") {
      cin >> a >> b;
      string target = str.substr(a, b - a + 1);
      reverse(target.begin(), target.end());
      str = str.substr(0, a) + target + str.substr(b - a + 1, str.length());
    } else if (op == "replace") {
      cin >> a >> b >> p;
      str = str.substr(0, a) + p + str.substr(b - a + 2, str.length());
    }
  }

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

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

string str, str1, str2, str3;
int main() {
  int i = 0, a = 0, b = 0;
  cin >> str >> i;
  for (int i2 = 0; i2 < i; i2++) {
    cin >> str1;
    if (str1 == "replace") {
      cin >> a >> b >> str2;
      str.replace(a, b - a + 1, str2);
    }
    if (str1 == "reverse") {
      cin >> a >> b;
      str2 = str.substr(a, b - a + 1);
      str.erase(a, b - a + 1);
      str3 = "";
      for (int i3 = 0; i3 <= b - a; i3++) {
        str3 += str2[str2.size() - i3 - 1];
      }
      str.insert(a, str3);
    }
    if (str1 == "print") {
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

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

string str, str1, str2, str3;
int main() {
  int i = 0, a = 0, b = 0;
  cin >> str >> i;
  for (int i2 = 0; i2 < i; i2++) {
    cin >> str1;
    if (str1 == "replace") {
      cin >> a >> b >> str2;
      str.replace(a, b - a + 1, str2);
    }
    if (str1 == "reverse") {
      cin >> a >> b;
      str2 = str.substr(a, b - a + 1);
      str.erase(a, b - a + 1);
      for (int i3 = 0; i3 <= b - a; i3++) {
        str3.insert(i3, str2.substr(b - i3, 1));
      }
      str.insert(a, str3);
      str3 = "";
    }
    if (str1 == "print") {
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string str;
  cin >> str;
  int n;
  cin >> n;
  string buf;
  for (int i = 0; i < n; i++) {
    cin >> buf;
    if (buf == "replace") {
      int a, b;
      string ptn;
      cin >> a >> b >> ptn;
      str.replace(a, b - a + 1, ptn);
    }
    if (buf == "reverse") {
      int a, b;
      cin >> a >> b;
      auto itr = str.begin();
      reverse(itr + a, itr + b + 1);
    }
    if (buf == "print") {
      int a, b;
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  string str;
  cin >> str;
  int n;
  cin >> n;
  string buf;
  for (int i = 0; i < n; i++) {
    cin >> buf;
    if (buf == "replace") {
      int a, b;
      string ptn;
      cin >> a >> b >> ptn;
      str.replace(a, b, ptn);
    }
    if (buf == "reverse") {
      int a, b;
      cin >> a >> b;
      auto itr = str.begin();
      reverse(itr + a, itr + b + 1);
    }
    if (buf == "print") {
      int a, b;
      cin >> a >> b;
      cout << str.substr(a, b + 1) << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#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 command;
    cin >> command;
    int a, b;
    cin >> a >> b;
    // cerr << command << endl;
    if (command == "replace") {
      string p;
      cin >> p;
      // cerr << "str:" << str << "p:" << p << endl;
      str.replace(a, b - a + 1, p);
    } else if (command == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else {
      cout << str.substr(a, b - a + 1) << endl;
    }
  }
  return 0;
}

Error: 0
replace
str:abcdep:xyz
reverse
print


Fixed submission:

#include <algorithm>
#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 command;
    cin >> command;
    int a, b;
    cin >> a >> b;
    cerr << command << endl;
    if (command == "replace") {
      string p;
      cin >> p;
      cerr << "str:" << str << "p:" << p << endl;
      str.replace(a, b - a + 1, p);
    } else if (command == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else {
      cout << str.substr(a, b - a + 1) << endl;
    }
  }
  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;
  for (cin >> n; n > 0; n--) {
    string op;
    cin >> op;

    if (op == "print") {
      int a, b;

      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    } else if (op == "reverse") {
      int a, b;
      string t;

      cin >> a >> b;
      t = str.substr(a, b - a + 1);
      reverse(t.begin(), t.end());
      str.replace(a, b - a + 1, t);
    } else if (op == "replace") {
      int a, b;
      string p;

      cin >> a >> b >> p;
      str.replace(a, b - a + 1, p);
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  int n;

  cin >> str;
  for (cin >> n; n > 0; n--) {
    string op;
    cin >> op;

    if (op == "print") {
      int a, b;

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

      cin >> a >> b;
      reverse(str.begin() + a, str.begin() + b + 1);
    } else if (op == "replace") {
      int a, b;
      string p;

      cin >> a >> b >> p;
      str.replace(a, b, p);
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string> StringList;

void exeOrder(string &src, const StringList &order) {
  int a = stoi(order[1]);
  int b = stoi(order[2]);
  if (order[0] == "print") {
    cout << src.substr(a, b - a + 1) << endl;
  } else if (order[0] == "reverse") {
    string rev = src.substr(a, b - a + 1);
    reverse(rev.begin(), rev.end());
    src = src.substr(0, a) + rev + src.substr(b + 1);

  } else if (order[0] == "replace") {
    src = src.substr(0, a) + order[3] + src.substr(b + 1);
  }
}

int main() {
  string str;
  getline(cin, str);

  string buf;
  getline(cin, buf);
  int n = stoi(buf);
  for (int i = 0; i < n; i++) {
    getline(cin, buf);
    stringstream ss(buf);

    StringList list;
    string tmp;
    while (getline(ss, tmp, ' ')) {
      list.push_back(tmp);
    }
    exeOrder(str, list);
  }

  return 0;
}

Error: -11

Fixed submission:


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string> StringList;

void exeOrder(string &src, const StringList &order) {
  int a = stoi(order[1]);
  int b = stoi(order[2]);
  if (order[0] == "print") {
    cout << src.substr(a, b) << endl;
  } else if (order[0] == "reverse") {
    reverse(src.begin() + a, src.begin() + b);
  } else if (order[0] == "replace") {
    src = src.substr(0, a) + order[3] + src.substr(b + 1);
  }
}

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

  string buf;
  cin >> buf;
  int n = stoi(buf);
  for (int i = 0; i < n; i++) {
    getline(cin, buf);
    stringstream ss(buf);

    StringList list;
    string tmp;
    while (getline(ss, tmp, ' ')) {
      list.push_back(tmp);
    }
    exeOrder(str, list);
  }

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

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

string rep(int a, int b, string c, string d) {
  string s1 = c, s2 = d;
  s1 = s1.replace(a, b - a + 1, s2);
  return s1;
}

string rev(int a, int b, string c) {
  string s1 = c, s2, s3;
  s2 = s1.substr(a, b - a + 1);
  for (int i = s2.size() - 1; i != -1; i--) {
    s3 += s2[i];
  }
  s1 = s1.replace(a, s3.size(), s3);
  return s1;
}

string pri(int a, int b, string c) {
  string s1 = c;
  s1 = s1.substr(a, b - a + 1);
  return s1;
}

int main() {
  int cnt, a, b;
  string st1, st2, st3;
  cin >> st1 >> cnt;
  for (int i = 0; i < cnt; i++) {
    cin >> st2;
    if (st2 == "replace") {
      cin >> a >> b >> st3;
      st1 = rep(a, b, st1, st3);
    } else if (st2 == "reverse") {
      cin >> a >> b;
      st1 = rev(a, b, st1);
    } else if (st2 == "print") {
      cin >> a >> b;
      cout << pri(a, b, st1) << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

string rep(int a, int b, string c, string d) {
  string s1 = c, s2 = d;
  s1 = s1.replace(a, b, s2);
  return s1;
}

string rev(int a, int b, string c) {
  string s1 = c, s2, s3;
  s2 = s1.substr(a, b + 1);
  for (int i = s2.size() - 1; i != -1; i--) {
    s3 += s2[i];
  }
  s1 = s1.replace(a, s3.size(), s3);
  return s1;
}

string pri(int a, int b, string c) {
  string s1 = c;
  s1 = s1.substr(a, b + 1);
  return s1;
}

int main() {
  int cnt, a, b;
  string st1, st2, st3;
  cin >> st1 >> cnt;
  for (int i = 0; i < cnt; i++) {
    cin >> st2;
    if (st2 == "replace") {
      cin >> a >> b >> st3;
      st1 = rep(a, b, st1, st3);
    } else if (st2 == "reverse") {
      cin >> a >> b;
      st1 = rev(a, b, st1);
    } else if (st2 == "print") {
      cin >> a >> b;
      cout << pri(a, b, st1) << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

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

string reverse(string str, int a, int b) {
  string sub;
  for (int i = 0; i < b - a + 1; i++) {
    sub[i] = str[b - i];
  }
  for (int i = 0; i < b - a + 1; i++) {
    str[a + i] = sub[i];
  }
  return str;
}

string replace(string str, int a, int b, string p) {
  return str.replace(a, b - a + 1, p);
}

int main() {
  int q;
  string str;

  cin >> str;
  cin >> q;

  for (int i = 0; i < q; i++) {
    int a, b;
    string command, p;
    cin >> command;
    if (command == "print") {
      cin >> a >> b;
      cout << print(str, a, b) << endl;
    } else if (command == "reverse") {
      cin >> a >> b;
      str = reverse(str, a, b);
    } else if (command == "replace") {
      cin >> a >> b >> p;
      str = replace(str, a, b, p);
    }
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 18446744073709551615) > this->size() (which is 8646911284551352325)


Fixed submission:

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

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

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

string replace(string str, int a, int b, string p) {
  return str.replace(a, b - a + 1, p);
}

int main(int argc, char const *argv[]) {
  int q;
  string str;

  cin >> str;
  cin >> q;

  for (int i = 0; i < q; i++) {
    int a, b;
    string command, q;
    cin >> command;
    if (command == "print") {
      cin >> a >> b;
      cout << print(str, a, b);
    } else if (command == "reverse") {
      cin >> a >> b;
      str = reverse(str, a, b);
    } else if (command == "replace") {
      cin >> a >> b >> q;
      str = replace(str, a, b, q);
    }
  }
  return 0;
}