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

// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>

#define int long long int
#define ld long double
#define f(i, j, n) for (int i = j; i <= n; i++)
#define r(i, n, j) for (int i = n; i >= j; i--)
#define mod 1000000007
#define speed ios_base::sync_with_stdio(false);
#define upp cin.tie(NULL), cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define T                                                                      \\
  int ttt;                                                                     \\
  cin >> ttt;                                                                  \\
  while (ttt--)
#define ff first
#define ss second
#define all(container) container.begin(), container.end()
#define sz(container) (int)container.size()
#define pii pair<int, int>
#define sp(x) setprecision(x)
#define bp(x) __builtin_popcount(x)
#define endl "\\n"
int power(int x, int y, int p) {
  int res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

int32_t main() {
  speed upp int x, n;
  cin >> n;
  f(i, 0, 1000) {
    x = n + i * i * i * i * i;
    int l = -3000, r = 3000;
    while (l <= r) {
      int y = (l + r) >> 1;
      if (y * y * y * y * y == x) {
        cout << y << " " << i;
        exit(0);
      } else if (y * y * y * y * y > x)
        r = y - 1;
      else
        l = y + 1;
    }
    x = n - i * i * i * i * i;
    l = -3000;
    r = 3000;
    while (l <= r) {
      int y = (l + r) >> 1;
      if (y * y * y * y * y == x) {
        cout << y << " " << -i;
        exit(0);
      } else if (y * y * y * y * y > x)
        r = y - 1;
      else
        l = y + 1;
    }
  }
}


Error: WA

Fixed submission:

// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>

#define int long long int
#define ld long double
#define f(i, j, n) for (int i = j; i <= n; i++)
#define r(i, n, j) for (int i = n; i >= j; i--)
#define mod 1000000007
#define speed ios_base::sync_with_stdio(false);
#define upp cin.tie(NULL), cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define T                                                                      \\
  int ttt;                                                                     \\
  cin >> ttt;                                                                  \\
  while (ttt--)
#define ff first
#define ss second
#define all(container) container.begin(), container.end()
#define sz(container) (int)container.size()
#define pii pair<int, int>
#define sp(x) setprecision(x)
#define bp(x) __builtin_popcount(x)
#define endl "\\n"
int power(int x, int y, int p) {
  int res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

int32_t main() {
  speed upp int n, ans = 0;
  cin >> n;
  int a[n + 1];
  f(i, 1, n) cin >> a[i];
  map<int, int> m;
  m[a[1] + 1] = 1;
  f(i, 2, n) {
    if (m.find(i - a[i]) != m.end())
      ans += m[i - a[i]];
    m[i + a[i]]++;
  }
  cout << ans;
}