Problem p02547 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
typedef long long int lli;
#define optimize                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < n; i++)
#define forab(i, a, b) for (int i = a; i < b; i++)
#define forll(i, a, b) for (lli i = a; i < b; i++)
#define mp make_pair
#define pb push_back
#define sortv(v) sort(v.begin(), v.end())
#define debug(x) cout << #x << " : " << x << endl
#define all(x) x.begin(), x.end()
#define printv(v)                                                              \\
  for (auto it : v)                                                            \\
    cout << it << " ";                                                         \\
  cout << endl;
#define prec(n) fixed << setprecision(n)
const lli mod = 1000000007;
const int mod2 = 998244353;
const int N = 1e5;

template <typename T> T power(T base, T exp) {
  T res = 1;
  while (exp > 0) {
    if (exp & 1)
      res = (res % mod * base % mod) % mod;

    base = (base % mod * base % mod) % mod;
    exp >>= 1;
  }
  return res;
}

int main() {
  optimize

#ifndef ONLINE_JUDGE
      freopen("inputf.in", "r", stdin);
  freopen("outputf.in", "w", stdout);
#endif

  int n;
  cin >> n;
  vi d;
  int u, v;
  forn(i, n) {
    cin >> u >> v;
    if (u == v)
      d.pb(i);
  }

  int ans = 0;
  if (d.size() >= 3) {
    for (int i = 1; i < d.size() - 1; i++) {
      if (d[i - 1] == d[i] - 1 && d[i] + 1 == d[i + 1])
        ans = 1;
    }
  }

  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
typedef long long int lli;
#define optimize                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < n; i++)
#define forab(i, a, b) for (int i = a; i < b; i++)
#define forll(i, a, b) for (lli i = a; i < b; i++)
#define mp make_pair
#define pb push_back
#define sortv(v) sort(v.begin(), v.end())
#define debug(x) cout << #x << " : " << x << endl
#define all(x) x.begin(), x.end()
#define printv(v)                                                              \\
  for (auto it : v)                                                            \\
    cout << it << " ";                                                         \\
  cout << endl;
#define prec(n) fixed << setprecision(n)
const lli mod = 1000000007;
const int mod2 = 998244353;
const int N = 1e5;

template <typename T> T power(T base, T exp) {
  T res = 1;
  while (exp > 0) {
    if (exp & 1)
      res = (res % mod * base % mod) % mod;

    base = (base % mod * base % mod) % mod;
    exp >>= 1;
  }
  return res;
}

int main() {
  optimize

#ifndef ONLINE_JUDGE
      freopen("inputf.in", "r", stdin);
  freopen("outputf.in", "w", stdout);
#endif

  int n;
  cin >> n;
  vi d;
  int u, v;
  forn(i, n) {
    cin >> u >> v;
    if (u == v)
      d.pb(i);
  }

  int ans = 0;
  for (int i = 1; i < d.size() - 1; i++) {
    if (d[i - 1] == d[i] - 1 && d[i] + 1 == d[i + 1])
      ans = 1;
  }

  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}