alexjercan/bugnet huggingface dataset:
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX / 2 - 1
#define pb push_back

using namespace std;

vector<int> primes;

bool isPrime(int p) {
  for (int i = 0; i < primes.size() && i <= sqrt(p); i++) {
    if (p % primes[i] == 0) {
      return false;
    }
  }
  return true;
}

void makePrimes(int n) {
  primes.pb(2);
  for (int i = 3; i < n; i += 2) {
    if (isPrime(i)) {
      primes.pb(i);
    }
  }
}

int main() {
  makePrimes(1000000);
  int a, d, n;
  while (cin >> a >> d >> n, a | d | n) {
    for (int i = 0; i < primes.size(); i++) {
      if (primes[i] == a) {
        n--;
        if (n == 0) {
          cout << primes[i] << el;
          break;
        }
      } else if (primes[i] > a) {
        a += d;
        i--;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX / 2 - 1
#define pb push_back

using namespace std;

vector<int> primes;

bool isPrime(int p) {
  for (int i = 0; i < primes.size(); i++) {
    if (p % primes[i] == 0) {
      return false;
    }
  }
  return true;
}

void makePrimes(int n) {
  primes.pb(2);
  for (int i = 3; i < n; i += 2) {
    if (isPrime(i)) {
      primes.pb(i);
    }
  }
}

int main() {
  makePrimes(1000000);
  int a, d, n;
  while (cin >> a >> d >> n, a | d | n) {
    for (int i = 0; i < primes.size(); i++) {
      if (primes[i] == a) {
        n--;
        if (n == 0) {
          cout << primes[i] << el;
          break;
        }
      } else if (primes[i] > a) {
        a += d;
        i--;
      }
    }
  }
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
const int MAX = 1000001;
char p[MAX] = {0};

void f() {
  for (int i = 2; i < MAX; i++)
    p[i] = 1;
  for (int i = 2; i * i < MAX; i++) {
    if (p[i]) {
      for (int j = i * 2; j < MAX; j += i) {
        p[j] = 0;
      }
    }
  }
}

int main() {
  int a, d, n, ans;
  f();

  while (cin >> a >> d >> n, a || d || n) {
    vector<int> v;

    for (int i = a; v.size() != n; i += d) {
      if (p[i]) {
        v.push_back(i);
      }
    }
    cout << v[v.size() - 1] << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

//  éªf©»Ê·éÖEßèl0:fÅÈ¢
// 1:f
int checkNumber(int num) {

  if (num <= 1)
    return 0; // 1ÍfÅÈ¢

  for (int i = 2; i < ((num + 1) / 2); i++) {
    if (num % i == 0) {
      return 0; // èØê½çfÅÈ¢
    }
  }

  return 1; // è«êÈ©Á½ÌÅf
}

int main() {

  int a, d, n, number, answer;
  int count;

  while (1) {
    cin >> a >> d >> n;
    number = a;
    count = 1;
    if (a == 0 && d == 0 && n == 0) {
      break; // 0 0 0ÌüÍÅI¹
    }

    while (1) { // ¦ªoéÜÅ³À[v
      if (checkNumber(number) == 1) {
        if (n == count) { // ¦¾Á½çbreak
          answer = number;
          break;
        } else {
          count++;
        }
      }
      number += d; // lðd¸Ââ·
    }

    // ¦ÌoÍ
    cout << answer << endl;
  }

  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {

  int a, d, n;
  int count;

  while (1) {
    count = 0;
    cin >> a >> d >> n;

    if (a == 0 && d == 0 && n == 0) {
      break;
    }

    if (a == 1) {
      a = a + d;
    }

    while (1) {
      int judge = 1;

      if (a % 2 != 0) {
        for (int i = 3; i * i <= a; i += 2) {
          if (a % i == 0) {
            judge = 0;
          }
        }
      } else {
        if (a == 2) {
          judge = 1;
        } else {
          judge = 0;
        }
      }
      if (judge == 1) {
        ++count;
      }
      if (count == n) {
        break;
      }
      a = a + d;
    }

    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {

  int a, d, n;
  int sum;

  while (1) {
    sum = 0;
    cin >> a >> d >> n;

    while (1) {
      int judge = 1;
      if (a % 2 != 0) {
        for (int i = 3; i * i < a; i += 2) {
          if (a % i == 0) {
            judge = 0;
          }
        }
      } else {
        judge = 0;
      }
      if (judge == 1) {
        ++sum;
      }
      if (sum == n) {
        break;
      }
      a = a + d;
    }

    cout << a << endl;
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
  const int N = 1000001;
  vector<bool> prime(N, true);
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < N; i++) {
    if (prime[i]) {
      for (int j = i + i; j < N; j += i) {
        prime[j] = false;
      }
    }
  }
  for (;;) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0)
      break;
    for (;;) {
      while (!prime[a]) {
        a += d;
      }
      n--;
      if (n == 0)
        break;
      a += d;
    }
    cout << a << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
  const int N = 1000001;
  vector<bool> prime(N, true);
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < N; i++) {
    if (prime[i]) {
      for (int j = i + i; j < N; j += i) {
        prime[j] = false;
      }
    }
  }
  for (;;) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0)
      break;
    for (;;) {
      while (!prime[a]) {
        a += d;
      }
      if (n == 0)
        break;
      a += d;
    }
    cout << a << endl;
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const int MAX_RESULT = 1000000;
std::unordered_set<int> primeset;
int Solve(int a, int d, int n) {
  int primecount = 0;
  while (primecount < n) {
    // cerr << "\\033[93m" << primecount << " " << a << "\\033[m" << endl;
    if (primeset.find(a) != primeset.end()) {
      // cerr << "\\033[93m" << a << "is prime"
      //      << "\\033[m" << endl;
      primecount++;
    }
    a += d;
  }
  return a - d;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  bool searchset[MAX_RESULT + 1] = {};
  for (int i = 2; i <= MAX_RESULT; i++) {
    searchset[i] = true;
  }

  for (int top = 2; top <= 1000; top++) {
    if (!searchset[top])
      continue;
    primeset.insert(top);
    for (int i = top; i <= MAX_RESULT; i += top) {
      searchset[i] = false;
    }
  }

  for (int i = 2; i <= MAX_RESULT; i++) {
    if (searchset[i]) {
      primeset.insert(i);
    }
  }

  while (1) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;
    cout << Solve(a, d, n) << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const int MAX_RESULT = 100000;
std::unordered_set<int> primeset;
int Solve(int a, int d, int n) {
  int primecount = 0;
  while (primecount < n) {
    if (primeset.find(a) != primeset.end()) {
      // cerr << "\\033[93m" << a << "is prime"
      //      << "\\033[m" << endl;
      primecount++;
    }
    a += d;
  }
  return a - d;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  bool searchset[100001] = {};
  for (int i = 2; i <= MAX_RESULT; i++) {
    searchset[i] = true;
  }

  for (int top = 2; top <= 1000; top++) {
    if (!searchset[top])
      continue;
    primeset.insert(top);
    for (int i = top; i <= 100000; i += top) {
      searchset[i] = false;
    }
  }

  for (int i = 2; i <= 100000; i++) {
    if (searchset[i]) {
      primeset.insert(i);
    }
  }

  while (1) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;
    cout << Solve(a, d, n) << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define maxnum 1000000
bool isprime[maxnum];

void makeprime() {
  REP(i, maxnum) {
    if (i % 2 != 0)
      isprime[i] = true;
  }
  isprime[1] = false;
  isprime[2] = true;
  for (int i = 3; i < sqrt(maxnum); i += 2) {
    for (int j = i + 2; j < maxnum; j += 2) {
      if (j % i == 0)
        isprime[j] = false;
    }
  }
}

int main() {
  int a, d, n;
  makeprime();
  while (1) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;
    ll int cnt = 0;
    ll int pos = a;
    while (1) {
      if (isprime[pos]) {
        cnt++;
      }
      if (cnt == n)
        break;
      pos += d;
    }
    cout << pos << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define maxnum 100000
bool isprime[maxnum];

void makeprime() {
  REP(i, maxnum) {
    if (i % 2 != 0)
      isprime[i] = true;
  }
  isprime[2] = true;
  for (int i = 3; i < sqrt(maxnum); i += 2) {
    for (int j = i + 2; j < maxnum; j += 2) {
      if (j % i == 0)
        isprime[j] = false;
    }
  }
}

int main() {
  int a, d, n;
  makeprime();
  cout << isprime[5] << endl;
  while (1) {
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0)
      break;
    ll int cnt = 0;
    ll int pos = a;
    while (1) {
      if (isprime[pos]) {
        cnt++;
      }
      if (cnt == n)
        break;
      pos += d;
    }
    cout << pos << endl;
  }
  return 0;
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double ESP = 1e-10;
#define MAX 1000100
using namespace std;
bool sosu[MAX] = {1, 1, 0};
int main() {
  for (int i = 4; i < MAX; i += 2)
    sosu[i] = 1;
  for (int i = 3; i < MAX; i += 2) {
    if (sosu[i])
      continue;
    for (int j = i * 3; j < MAX; j += i * 2)
      sosu[j] = 1;
  }
  int a, b, c;
  while (cin >> a >> b >> c, a || b || c) {
    int co = 0;
    if (!sosu[a])
      co++;
    while (co != c) {
      a += b;
      if (!sosu[a])
        co++;
      if (co == c)
        break;
    }
    cout << a << endl;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define pb(in, tmp) in.push_back(tmp)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) loop(i, 0, b)
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
using namespace std;
#define MAX 1001000
int num[MAX] = {1, 1, 0};
int main() {

  for (int i = 3; i < MAX; i += 2) {
    if (num[i] == 1)
      continue;
    for (int j = 3 * i; j * j <= MAX; j += i * 2)
      num[j] = 1;
  }
  for (int i = 4; i < MAX; i += 2)
    num[i] = 1;

  int a, b, c;
  while (cin >> a >> b >> c, a | b | c) {
    int co = 0;
    while (co != c) {
      if (!num[a])
        co++;
      a += b;
    }
    cout << a - b << endl;
  }
}
Problem p00722 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main(void) {
  for (;;) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0) {
      return 0;
    }
    int ans = -1;
    for (int i = 0; ((a + d * i <= 1000000) && (ans == -1)); i++) {
      bool prime = true;
      if (a + d * i == 1) {
        prime = false;
      } else {
        for (int j = 2; j * j <= a + d * i; j++) {
          if ((a + d * i) % j == 0) {
            prime = false;
          }
        }
      }
      if (prime) {
        if (n == 1) {
          ans = a + d * i;
        } else {
          n--;
        }
      }
    }
    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  for (;;) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0) {
      return 0;
    }
    int ans = -1;
    for (int i = 0; ((a + d * i <= 1000000) && (ans == -1)); i++) {
      bool prime = true;
      for (int j = 2; j <= 10000; j++) {
        if ((a + d * i) % j == 0) {
          prime = false;
        }
      }
      if (prime) {
        if (n == 1) {
          ans = a + d * i;
        } else {
          n--;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00722 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  bool prime[1000005];
  for (int i = 0; i < 1000005; i++) {
    prime[i] = true;
  }
  prime[0] = false;
  prime[1] = false;
  for (int k = 2; k < 1000005; k++) {
    if (prime[k] == true) {
      for (int j = 2; j * k < 1000005; j++) {
        prime[j * k] = false;
      }
    }
  }
  for (;;) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0) {
      return 0;
    }
    int ans;
    bool finish = false;
    for (int i = 0; (a + d * i <= 1000000) && (!finish); i++) {
      if (prime[a + d * i]) {
        if (n == 1) {
          ans = a + d * i;
          finish = true;
        } else {
          n--;
        }
      }
    }
    cout << ans << endl;
  }
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  bool prime[100005];
  for (int i = 0; i < 100005; i++) {
    prime[i] = true;
  }
  prime[0] = false;
  prime[1] = false;
  /*    for(int k = 1 ; k < 1000 ; k++){
          if(prime[k] == true){
              for(int j = 2 ; j * k < 100005 ; j++){
                  prime[j*k]=false;
              }
          }
      }*/
  for (;;) {
    int a, d, n;
    cin >> a >> d >> n;
    if (a == 0 && d == 0 && n == 0) {
      return 0;
    }
    int ans;
    for (int i = 1; i < 100005; i++) {
      if (prime[a + d * i] == true) {
        if (n == 0) {
          ans = a + d * i;
        } else {
          n--;
        }
      }
    }
    cout << ans;
  }
}
Problem p00723 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000            // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int main(void) {

  int m;

  string s;

  cin >> m;
  FOR(i, 1, m) {
    cin >> s;
    int pos = 0;
    int count = 0;
    string p, q;
    vector<string> dp(1000, "-");
    FOR(t, 1, s.size() - 1) {
      p = s.substr(0, t);
      q = s.substr(t);
      dp[pos] = p + q;
      pos++;
      dp[pos] = q + p;
      pos++;
      reverse(p.begin(), p.end());
      dp[pos] = p + q;
      pos++;
      dp[pos] = q + p;
      pos++;
      reverse(q.begin(), q.end());
      dp[pos] = p + q;
      pos++;
      dp[pos] = q + p;
      pos++;
      reverse(p.begin(), p.end());
      dp[pos] = p + q;
      pos++;
      dp[pos] = q + p;
      pos++;
    }
    /*FOR(u, 0, 999) {
            cout << dp[u] << endl;
    }*/
    sort(dp.begin(), dp.end());
    FOR(u, 0, 999) {
      FOR(r, u + 1, 999) {
        if (dp[u] == dp[r]) {
          dp[r] = "-";
        }
      }
    }
    FOR(u, 0, 999) {
      if (dp[u] != "-") {
        count++;
      }
    }
    cout << count << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000            // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int main(void) {

  int m;
  int pos = 0;
  int count = 0;
  string s;

  cin >> m;
  FOR(i, 1, m) {
    cin >> s;
    string p, q;
    vector<string> dp(5000, "-");
    FOR(t, 1, s.size() - 1) {
      p = s.substr(0, t);
      q = s.substr(t);
      dp[pos] = p + q;
      pos++;
      dp[pos] = q + p;
      pos++;
      reverse(p.begin(), p.end());
      dp[pos] = p + q;
      pos++;
      dp[pos] = q + p;
      pos++;
      reverse(q.begin(), q.end());
      dp[pos] = p + q;
      pos++;
      dp[pos] = q + p;
      pos++;
      reverse(p.begin(), p.end());
      dp[pos] = p + q;
      pos++;
      dp[pos] = q + p;
      pos++;
    }
    /*FOR(u, 0, 999) {
            cout << dp[u] << endl;
    }*/
    sort(dp.begin(), dp.end());
    FOR(u, 0, 4999) {
      FOR(r, u + 1, 4999) {
        if (dp[u] == dp[r]) {
          dp[r] = "-";
        }
      }
    }
    FOR(u, 0, 4999) {
      if (dp[u] != "-") {
        count++;
      }
    }
    cout << count << endl;
  }
}
Problem p00723 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main(void) {
  vector<string> str;
  vector<string> ans;
  string s[120];
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  for (int k = 0; k < n; k++) {
    str.clear();
    ans.clear();
    for (unsigned int i = 0; i < s[k].size(); i++) {
      string str1(s[k].substr(0, i));
      string str2(s[k].substr(i, s[k].size() - i));
      str.push_back(str1 + str2);
      str.push_back(str2 + str1);

      reverse(str1.begin(), str1.end());
      str.push_back(str1 + str2);
      str.push_back(str2 + str1);

      reverse(str1.begin(), str1.end());
      reverse(str2.begin(), str2.end());
      str.push_back(str1 + str2);
      str.push_back(str2 + str1);

      reverse(str1.begin(), str1.end());
      str.push_back(str1 + str2);
      str.push_back(str2 + str1);
    }

    unsigned int n = 1;
    ans.push_back(s[k]);
    for (unsigned int i = 0; i < str.size(); i++) {
      bool f = true;
      for (unsigned int j = 0; j < ans.size(); j++) {
        if (str[i] == ans[j]) {
          f = false;
          break;
        }
      }
      if (f) {
        n++;
        ans.push_back(str[i]);
      }
    }

    cout << n << endl;
  }

  return (0);
}

Error: TLE

Fixed submission:

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

using namespace std;

int main(void) {
  vector<string> str;
  vector<string> ans;
  string s[120];
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  for (int k = 0; k < n; k++) {
    for (unsigned int i = 0; i < s[k].size(); i++) {
      string str1(s[k].substr(0, i));
      string str2(s[k].substr(i, s[k].size() - i));
      str.push_back(str1 + str2);
      str.push_back(str2 + str1);

      reverse(str1.begin(), str1.end());
      str.push_back(str1 + str2);
      str.push_back(str2 + str1);

      reverse(str1.begin(), str1.end());
      reverse(str2.begin(), str2.end());
      str.push_back(str1 + str2);
      str.push_back(str2 + str1);

      reverse(str1.begin(), str1.end());
      str.push_back(str1 + str2);
      str.push_back(str2 + str1);
    }

    unsigned int n = 1;
    ans.push_back(s[k]);
    for (unsigned int i = 0; i < str.size(); i++) {
      bool f = true;
      for (unsigned int j = 0; j < ans.size(); j++) {
        if (str[i] == ans[j]) {
          f = false;
          break;
        }
      }
      if (f) {
        n++;
        ans.push_back(str[i]);
      }
    }

    cout << n << endl;
  }

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

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

#define ALL(c) (c).begin(), (c).end()

int main() {
  int M;
  cin >> M;
  while (M--) {
    string s;
    cin >> s;
    vector<string> v;
    for (int i = 0; i < (int)s.length() - 1; i++) {
      string front = s.substr(0, i + 1);
      string back = s.substr(i + 1);

      v.push_back(front + back);
      v.push_back(back + front);

      reverse(ALL(front));
      v.push_back(front + back);
      v.push_back(back + front);

      reverse(ALL(front));
      reverse(ALL(back));
      v.push_back(front + back);
      v.push_back(back + front);

      reverse(ALL(front));
      v.push_back(front + back);
      v.push_back(back + front);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)), v.end());

#if 0
		cerr << "-----" << endl;
		for(vector<string>::const_iterator iter = v.begin(); iter != v.end(); ++iter)
			cerr << *iter << endl;
		cerr << "-----" << endl;
#endif

    cout << v.size() << endl;
  }
}

Error: 0
-----
aa
-----
-----
aabb
abab
abba
baab
baba
bbaa
-----
-----
abcd
abdc
adcb
bacd
badc
bcda
cbad
cdab
cdba
dabc
dcab
dcba
-----
-----
abcde
abced
abedc
aedcb
bacde
baedc
bcdea
cbade
cbaed
cdeab
cdeba
dcbae
deabc
decba
eabcd
edabc
edcab
edcba
-----


Fixed submission:

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

#define ALL(c) (c).begin(), (c).end()

int main() {
  int M;
  cin >> M;
  while (M--) {
    string s;
    cin >> s;
    vector<string> v;
    for (int i = 0; i < (int)s.length() - 1; i++) {
      string front = s.substr(0, i + 1);
      string back = s.substr(i + 1);

      v.push_back(front + back);
      v.push_back(back + front);

      reverse(ALL(front));
      v.push_back(front + back);
      v.push_back(back + front);

      reverse(ALL(front));
      reverse(ALL(back));
      v.push_back(front + back);
      v.push_back(back + front);

      reverse(ALL(front));
      v.push_back(front + back);
      v.push_back(back + front);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)), v.end());

    cerr << "-----" << endl;
    for (vector<string>::const_iterator iter = v.begin(); iter != v.end();
         ++iter)
      cerr << *iter << endl;
    cerr << "-----" << endl;

    cout << v.size() << endl;
  }
}