Problem p03293 (C++)

Buggy submission (status: Runtime Error):
//============================================================================
// Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Online Judge: Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i, a, b) for (int i = a; i < b; i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define EMPP emplace_back
#define vii vector<int>
#define ipair pair<int, int>
#define lpair pair<LL, LL>
#define El3zba                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d", &v);
#define sfll2(v1, v2) scanf("%I64d %I64d", &v1, &v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d", &v1, &v2, &v3)
// std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
  return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a, LL b) { return !b ? a : gcd(b, a % b); }
LL LCM(LL a, LL b) { return (a * b) / gcd(a, b); }
void PrimeFactor(LL n) {
  while (n % 2 == 0) {
    // printf("%d ", 2);
    //		aa.insert(2);
    n /= 2;
  }
  for (int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      // printf("%d ", i);
      // aa.insert(i);
      n /= i;
    }
  }
  if (n > 2) {
    // printf("%d ", n);
    //	aa.insert(n);
  };
}
bool is_square(LL x) {
  LL l = 0, r = x;
  while (l <= r) {
    LL mid = l + (r - l) / 2;
    if (mid * mid == x)
      return true;
    if (mid * mid > x)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return false;
}
LL power(LL x, LL y) {
  LL temp;
  if (y == 0)
    return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
bool is_Prime(int x) {
  if (x == 2)
    return 1;
  else if (x % 2 == 0 || x < 2)
    return 0;
  for (int i = 3; i * i <= x; i += 2)
    if (x % i == 0)
      return 0;
  return 1;
}
const int N = 1e+5;
int aseg[4], seg[4];
void SEGBuild(int pos, int low, int hig) {
  if (low == hig)
    seg[pos] = aseg[low];
  else {
    int mid = low + (hig - low) / 2;
    SEGBuild(2 * pos, low, mid);         // Recurse left;;
    SEGBuild(2 * pos + 1, mid + 1, hig); // Recurse right;
    if (seg[2 * pos] < seg[2 * pos + 1])
      seg[pos] = seg[2 * pos];
    else
      seg[pos] = seg[2 * pos + 1];
  }
}
void SEGUpdate(int pos, int idx, int low, int hig, int val) {
  if (low == hig) {
    aseg[idx] = val;
    seg[pos] = val;
  } else {
    int mid = low + (hig - low) / 2;
    if (idx >= low && idx <= mid)
      SEGUpdate(2 * pos, idx, low, mid, val); // Recurse left;
    else
      SEGUpdate(2 * pos + 1, idx, mid + 1, hig, val); // Recurse right;
    seg[pos] = min(seg[2 * pos + 1], seg[2 * pos]);
  }
}
int ANSQuery(int pos, int low, int hig, int l, int r) {
  if (l > hig || low > r) // completely  outside;
    return 1e+5;
  if (l <= low && r >= hig)
    return seg[pos];
  else {
    int p1, p2;
    int mid = low + (hig - low) / 2;
    p1 = ANSQuery(2 * pos, low, mid, l, r);         // Recurse left;
    p2 = ANSQuery(2 * pos + 1, mid + 1, hig, l, r); // Recurse right;
    return min(p1, p2);
  }
}
int main() {
  El3zba;
  /***  بسم الله الرحمن الرحيم   ***/
  string s, t;
  cin >> s >> t;
  bool ok = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    s.PB(s[0]);
    s.erase(s[i]);
    if (s == t) {
      ok |= 1;
      break;
    }
  }
  if (ok)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}

Fixed submission:
//============================================================================
// Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Online Judge: Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i, a, b) for (int i = a; i < b; i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define EMPP emplace_back
#define vii vector<int>
#define ipair pair<int, int>
#define lpair pair<LL, LL>
#define El3zba                                                                 \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d", &v);
#define sfll2(v1, v2) scanf("%I64d %I64d", &v1, &v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d", &v1, &v2, &v3)
// std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
  return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a, LL b) { return !b ? a : gcd(b, a % b); }
LL LCM(LL a, LL b) { return (a * b) / gcd(a, b); }
void PrimeFactor(LL n) {
  while (n % 2 == 0) {
    // printf("%d ", 2);
    //		aa.insert(2);
    n /= 2;
  }
  for (int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) {
      // printf("%d ", i);
      // aa.insert(i);
      n /= i;
    }
  }
  if (n > 2) {
    // printf("%d ", n);
    //	aa.insert(n);
  };
}
bool is_square(LL x) {
  LL l = 0, r = x;
  while (l <= r) {
    LL mid = l + (r - l) / 2;
    if (mid * mid == x)
      return true;
    if (mid * mid > x)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return false;
}
LL power(LL x, LL y) {
  LL temp;
  if (y == 0)
    return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
bool is_Prime(int x) {
  if (x == 2)
    return 1;
  else if (x % 2 == 0 || x < 2)
    return 0;
  for (int i = 3; i * i <= x; i += 2)
    if (x % i == 0)
      return 0;
  return 1;
}
const int N = 1e+5;
int aseg[4], seg[4];
void SEGBuild(int pos, int low, int hig) {
  if (low == hig)
    seg[pos] = aseg[low];
  else {
    int mid = low + (hig - low) / 2;
    SEGBuild(2 * pos, low, mid);         // Recurse left;;
    SEGBuild(2 * pos + 1, mid + 1, hig); // Recurse right;
    if (seg[2 * pos] < seg[2 * pos + 1])
      seg[pos] = seg[2 * pos];
    else
      seg[pos] = seg[2 * pos + 1];
  }
}
void SEGUpdate(int pos, int idx, int low, int hig, int val) {
  if (low == hig) {
    aseg[idx] = val;
    seg[pos] = val;
  } else {
    int mid = low + (hig - low) / 2;
    if (idx >= low && idx <= mid)
      SEGUpdate(2 * pos, idx, low, mid, val); // Recurse left;
    else
      SEGUpdate(2 * pos + 1, idx, mid + 1, hig, val); // Recurse right;
    seg[pos] = min(seg[2 * pos + 1], seg[2 * pos]);
  }
}
int ANSQuery(int pos, int low, int hig, int l, int r) {
  if (l > hig || low > r) // completely  outside;
    return 1e+5;
  if (l <= low && r >= hig)
    return seg[pos];
  else {
    int p1, p2;
    int mid = low + (hig - low) / 2;
    p1 = ANSQuery(2 * pos, low, mid, l, r);         // Recurse left;
    p2 = ANSQuery(2 * pos + 1, mid + 1, hig, l, r); // Recurse right;
    return min(p1, p2);
  }
}
int main() {
  El3zba;
  /***  بسم الله الرحمن الرحيم   ***/
  string s, t;
  cin >> s >> t;
  bool ok = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    s.PB(s[0]);
    s.erase(s.begin());
    if (s == t) {
      ok |= 1;
      break;
    }
  }
  if (ok)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}