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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define drep(i, n, m) for (int i = n; i >= m; i--)
#define rrep(i, n) REP(i, 1, n + 1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x, y) make_pair(x, y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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

ll ans;
int n;
ll a[200005];
map<ll, ll> mp[2];

int main() {

  cin >> n;

  rrep(i, n) {
    cin >> a[i];
    mp[1][i - a[i]]++;
    mp[0][i + a[i]]++;
  }

  for (const auto &x : mp[0]) {
    ans += mp[0][x.fi] * mp[1][x.fi];
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define drep(i, n, m) for (int i = n; i >= m; i--)
#define rrep(i, n) REP(i, 1, n + 1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x, y) make_pair(x, y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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

ll ans;
int n;
ll a[100005];
map<ll, ll> mp[2];

int main() {

  cin >> n;

  rrep(i, n) {
    cin >> a[i];
    mp[1][i - a[i]]++;
    mp[0][i + a[i]]++;
  }

  for (const auto &x : mp[0]) {
    ans += mp[0][x.fi] * mp[1][x.fi];
  }

  cout << ans << endl;

  return 0;
}