Problem p03543 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define PI 3.14159265359
#define all(v) v.begin(), v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(), v.rend())
#define sortaa(a, n) sort(a, a + n)
#define sortad(a, n) sort(a, a + n), reverse(a, a + n)
#define sfi1(v) scanf("%d", &v)
#define sfi2(v1, v2) scanf("%d %d", &v1, &v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d", &v1, &v2, &v3)
#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)
#define sfstr(v) scanf("%s", v);
#define sz(v) (int)v.size()
#define ndl puts("")
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

void PLAY() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

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

  string s;
  cin >> s;
  for (int i = 0; i < sz(s); i++) {
    int cnt2 = 0;
    if (i + 3 <= sz(s)) {
      int idx = i;
      int cnt = 3;
      cnt2 = 0;
      while (cnt--) {
        if (idx >= sz(s)) {
          if (cnt2 == 3) {
            cout << "Yes" << endl;
            return 0;
          }
          break;
        }
        cnt2 += s[idx] == s[i];
        idx++;
      }
      if (cnt2 == 3) {
        cout << "Yes" << endl;
        return 0;
      }
    }
    if (cnt2 == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define PI 3.14159265359
#define all(v) v.begin(), v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(), v.rend())
#define sortaa(a, n) sort(a, a + n)
#define sortad(a, n) sort(a, a + n), reverse(a, a + n)
#define sfi1(v) scanf("%d", &v)
#define sfi2(v1, v2) scanf("%d %d", &v1, &v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d", &v1, &v2, &v3)
#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)
#define sfstr(v) scanf("%s", v);
#define sz(v) (int)v.size()
#define ndl puts("")
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

void PLAY() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  // PLAY();
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  string s;
  cin >> s;
  for (int i = 0; i < sz(s); i++) {
    int cnt2 = 0;
    if (i + 3 <= sz(s)) {
      int idx = i;
      int cnt = 3;
      cnt2 = 0;
      while (cnt--) {
        if (idx >= sz(s)) {
          if (cnt2 == 3) {
            cout << "Yes" << endl;
            return 0;
          }
          break;
        }
        cnt2 += s[idx] == s[i];
        idx++;
      }
      if (cnt2 == 3) {
        cout << "Yes" << endl;
        return 0;
      }
    }
    if (cnt2 == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}