Problem p02691 (C++)

Buggy submission (status: Runtime Error):
/**
 *      ///----- My Info -----///
 *      Code by: Ernesto Abreu
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      CopyRight
 **/
#include <bits/stdc++.h>
#ifdef Ernest0_0Abreu
#include <debug/to_string.h>
#endif
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
///----- My Template -----///
///======================================================================================================================================
/// Red-Black Tree
// #include <ext/pb_ds/assoc_container.hpp>  // .find_of_order(x);
// .order_of_key(x); using namespace __gnu_pbds; typedef tree< int, null_type,
// less<int>, rb_tree_tag, tree_order_statistics_node_update > indexed_set;
/// Function
#define pi (acos(-1))
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x, b) log(b) / log(x)
/// Macros
#define fst first
#define scd second
#define left (node << 1)
#define right ((node << 1) + 1)
#define size(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
/// Debug
#define _end cout << "\n"
#ifdef Ernest0_0Abreu
#define db(x) cerr << "[ " << #x << " ]: " << to_string(x) << "\n"
#define dbrange(x, begin, end)                                                 \
  cerr << "[ " << #x << " ]: " << to_string(x, begin, end) << "\n"
#define dbname(x) cerr << to_string(x, #x) << "\n"
#define dbnamerange(x, begin, end) cerr << to_string(x, #x, begin, end) << "\n"
#define dbmat(x, begin_n, end_n, begin_m, end_m)                               \
  cerr << to_string(x, #x, begin_n, end_n, begin_m, end_m) << "\n"
#define dbST(x, end) cerr << to_string(x, end) << "\n";
#define dbendl cerr << "\n";
#else
#define db(x) ;
#define dbrange(x, begin, end) ;
#define dbname(x) ;
#define dbnamerange(x, begin, end) ;
#define dbmat(x, begin_n, end_n, begin_m, end_m) ;
#define dbST(x, end) ;
#define dbendl ;
#endif
/// Typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// Constant
const int MAXN = 2e5 + 7;
const int MOD = 1e9;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1 << 30) - 1);
const ll INFLL = ((1ll << 62ll) - 1ll);
const ll oo = 2e18;
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027;
/// Module Prime Numbers: 3, 998244353, 1000000007, 1000000009, 1000000021,
/// 1000000033;
///=======================================================================================================================================
#define int long long
///----- My code -----///

int ar[MAXN], cnt[MAXN];

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    cin >> ar[i];
    if (i + ar[i] < MAXN)
      cnt[i + ar[i] - 1]++;
    if (i - ar[i] - 1 >= 1)
      continue;
    ans += cnt[i - ar[i] - 1];
  }

  cout << ans;

  return 0;
}


Fixed submission:
/**
 *      ///----- My Info -----///
 *      Code by: Ernesto Abreu
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      CopyRight
 **/
#include <bits/stdc++.h>
#ifdef Ernest0_0Abreu
#include <debug/to_string.h>
#endif
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
///----- My Template -----///
///======================================================================================================================================
/// Red-Black Tree
// #include <ext/pb_ds/assoc_container.hpp>  // .find_of_order(x);
// .order_of_key(x); using namespace __gnu_pbds; typedef tree< int, null_type,
// less<int>, rb_tree_tag, tree_order_statistics_node_update > indexed_set;
/// Function
#define pi (acos(-1))
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x, b) log(b) / log(x)
/// Macros
#define fst first
#define scd second
#define left (node << 1)
#define right ((node << 1) + 1)
#define size(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
/// Debug
#define _end cout << "\n"
#ifdef Ernest0_0Abreu
#define db(x) cerr << "[ " << #x << " ]: " << to_string(x) << "\n"
#define dbrange(x, begin, end)                                                 \
  cerr << "[ " << #x << " ]: " << to_string(x, begin, end) << "\n"
#define dbname(x) cerr << to_string(x, #x) << "\n"
#define dbnamerange(x, begin, end) cerr << to_string(x, #x, begin, end) << "\n"
#define dbmat(x, begin_n, end_n, begin_m, end_m)                               \
  cerr << to_string(x, #x, begin_n, end_n, begin_m, end_m) << "\n"
#define dbST(x, end) cerr << to_string(x, end) << "\n";
#define dbendl cerr << "\n";
#else
#define db(x) ;
#define dbrange(x, begin, end) ;
#define dbname(x) ;
#define dbnamerange(x, begin, end) ;
#define dbmat(x, begin_n, end_n, begin_m, end_m) ;
#define dbST(x, end) ;
#define dbendl ;
#endif
/// Typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// Constant
const int MAXN = 2e5 + 7;
const int MOD = 1e9;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1 << 30) - 1);
const ll INFLL = ((1ll << 62ll) - 1ll);
const ll oo = 2e18;
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027;
/// Module Prime Numbers: 3, 998244353, 1000000007, 1000000009, 1000000021,
/// 1000000033;
///=======================================================================================================================================
#define int long long
///----- My code -----///

int ar[MAXN], cnt[MAXN];

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    cin >> ar[i];
    if (i + ar[i] < MAXN)
      cnt[i + ar[i] - 1]++;
    if (i - ar[i] - 1 < 1)
      continue;
    ans += cnt[i - ar[i] - 1];
  }

  cout << ans;

  return 0;
}