alexjercan/bugnet huggingface dataset:
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>  //sort,二分探索,など
#include <bitset>     //固定長bit集合
#include <cmath>      //pow,logなど
#include <complex>    //複素数
#include <deque>      //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip>    //setprecision(浮動小数点の出力の誤差)
#include <iostream>
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> before(n);
  vector<ll> after(n);
  rep(i, n) cin >> a[i];

  rep(i, n) {
    if (0 <= i - a[i]) {
      before[i - a[i]]++;
    }
    if (i + a[i] <= n - 1) {
      after[i + a[i]]++;
    }
  }
  ll ans = 0;
  rep(i, n) { ans += before[i] * after[i]; }
  cout << ans << endl;
}

Error: -6
malloc(): corrupted top size


Fixed submission:

#include <algorithm>  //sort,二分探索,など
#include <bitset>     //固定長bit集合
#include <cmath>      //pow,logなど
#include <complex>    //複素数
#include <deque>      //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip>    //setprecision(浮動小数点の出力の誤差)
#include <iostream>
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> before(n);
  vector<int> after(n);
  rep(i, n) cin >> a[i];

  rep(i, n) {
    if (0 <= i - a[i] <= n - 1) {
      before[i - a[i]]++;
    }
    if (0 <= i + a[i] <= n - 1) {
      after[i + a[i]]++;
    }
  }
  int ans = 0;
  rep(i, n) { ans += before[i] * after[i]; }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<ll, ll>
#define endl "\\n"
#define MAXN 200005
using namespace std;

ll n, arr[MAXN];
map<ll, ll> m, m1;

void solve() {
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> arr[i];
    m[i + arr[i]]++;
    m1[i - arr[i]]++;
  }
  ll cnt = 0;
  for (auto it = m.begin(); it != m.end(); it++) {
    ll p = it->ss;
    ll q = m1[it->ff];
    cnt += (p * q);
  }
  cout << cnt << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<ll, ll>
#define endl "\\n"
#define MAXN 100005
using namespace std;

ll n, arr[MAXN];
map<ll, ll> m, m1;

void solve() {
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> arr[i];
    m[i + arr[i]]++;
    m1[i - arr[i]]++;
  }
  ll cnt = 0;
  for (auto it = m.begin(); it != m.end(); it++) {
    ll p = it->ss;
    ll q = m1[it->ff];
    cnt += (p * q);
  }
  cout << cnt << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main() {
  int n;
  cin >> n;

  ll ans = 0;
  ll a;
  map<ll, ll> m;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    ll x = i + a;
    m[x]++;
    ll y = i - a;
    ans += m[y];
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main() {
  int n;
  cin >> n;

  ll ans = 0;
  ll a;
  multiset<ll> c;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    ll x = i + a;
    c.insert(x);
    ll y = i - a;
    ans += c.count(y);
  }

  cout << ans << endl;

  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define in freopen("in.txt","r",stdin)
// #define out freopen("out.txt","w",stdout)
ll n, m, k, t, l, r;
ll a, b, c, d;
char A, B, C, X, Y, Z;
ll ans, MAX, MIN, sum;
ll ax[1000000];
char str[100000];
ll dx[12];
ll bx[2000500];

int main() {
  ll i, j;
  sum = 0;
  t = 1;
  // scanf("lld",&t);
  while (t--) {
    memset(ax, 0, sizeof(ax));
    memset(bx, 0, sizeof(bx));
    ll flag = 0;
    cin >> n;
    for (i = 1; i <= n; i++) {
      scanf("%lld", &a);
      if (i - a >= 0)
        ax[i - a]++;
      if (i + a <= n)
        bx[i + a]++;
    }
    for (i = 0; i <= n; i++) {
      sum += ax[i] * bx[i];
    }
    printf("%lld\\n", sum);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define in freopen("in.txt","r",stdin)
// #define out freopen("out.txt","w",stdout)
ll n, m, k, t, l, r;
ll a, b, c, d;
char A, B, C, X, Y, Z;
ll ans, MAX, MIN, sum;
ll ax[1000000];
char str[100000];
ll dx[12];
ll bx[2000500];

int main() {
  ll i, j;
  sum = 0;
  t = 1;
  // scanf("lld",&t);
  while (t--) {
    memset(ax, 0, sizeof(ax));
    memset(bx, 0, sizeof(bx));
    ll flag = 0;
    cin >> n;
    for (i = 1; i <= n; i++) {
      scanf("%lld", &a);
      ax[i - a]++;
      if (i + a <= n) {
        bx[i + a]++;
      }
    }
    for (i = 0; i <= n; i++) {
      sum += ax[i] * bx[i];
    }
    printf("%lld\\n", sum);
  }
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long

int main() {
  ll n;
  cin >> n;

  map<ll, ll> a, b;

  REP(i, n) {
    ll h;
    cin >> h;
    a[i + h + 1]++;
    b[i - h + 1]++;
  }
  ll ans = 0;
  for (auto itr : a) {
    ans += b[itr.first] * itr.second;
  }

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define pow5(x) x *x *x *x *x

int main() {
  int n;
  cin >> n;

  vector<long long> a, b;

  REP(i, n) {
    int h;
    cin >> h;
    a.push_back(h + i);
    b.push_back(h - i);
  }

  int ans = 0;
  REP(i, n) { ans += count(a.begin(), a.end(), -b[i]); }

  cout << ans << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>    // assert
#include <cmath>      // abs など
#include <functional> // greater など
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric> // accumulate, gcd など
#include <queue>
#include <set>
#include <stdexcept>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// ////////////////
///////////////////
//////////////// //////////////// //////////////// ////////////////
///////////////////

// constexpr inline ll mod = 1'000'000'007;
constexpr int max_n = 200'000 + 5;

int n;
vector<int> as(max_n);
map<int, int> bs;
ll res;

int main() {
  // 高速な入出力
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(15); // 浮動小数の表示の精度

  cin >> n;
  as.resize(n);
  rep(i, n) { cin >> as[i]; }

  rep(j, n) {
    res += bs[j - as[j]];
    bs[j + as[j]]++;
  }
  cout << res << '\\n';

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>    // assert
#include <cmath>      // abs など
#include <functional> // greater など
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric> // accumulate, gcd など
#include <queue>
#include <set>
#include <stdexcept>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// ////////////////
///////////////////
//////////////// //////////////// //////////////// ////////////////
///////////////////

// constexpr inline ll mod = 1'000'000'007;
constexpr int max_n = 200'000 + 5;

int n;
vector<int> as(max_n);
multiset<int> bs;
int res;

int main() {
  // 高速な入出力
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(15); // 浮動小数の表示の精度

  cin >> n;
  as.resize(n);
  rep(i, n) { cin >> as[i]; }

  rep(j, n) {
    res += bs.count(j - as[j]);
    bs.insert(j + as[j]);
  }
  cout << res << '\\n';

  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define rep(N) for (int i = 0; i < N; i++)
#define rep2(N1, N2)                                                           \\
  for (int i = 0; i < N1; i++)                                                 \\
    for (int j = 0; j < N2; j++)
#define rep3(N1, N2, N3)                                                       \\
  for (int i = 0; i < N1; i++)                                                 \\
    for (int j = 0; j < N2; j++)                                               \\
      for (int k = 0; k < N3; k++)
#define For(i, N) for (int i = 0; i < N; i++)
#define ll long long int
void yn(bool b) {
  if (b)
    printf("yes\\n");
  else
    printf("no\\n");
}

void Yn(bool b) {
  if (b)
    printf("Yes\\n");
  else
    printf("No\\n");
}

void YN(bool b) {
  if (b)
    printf("YES\\n");
  else
    printf("NO\\n");
}

int ctoi(char c) { return c - '0'; }

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(N) cin >> A[i];
  vector<ll> WA(N, 0);
  vector<ll> SA(N, 0);
  map<ll, ll> M, K;
  ll ans = 0;
  ll mi = 1000000000000;
  ll ma = 0;
  for (int i = 0; i < N; i++) {
    WA[i] = A[i] + i + 1;
    SA[i] = -A[i] + i + 1;
    M[WA[i]]++;
    K[SA[i]]++;
    ma = max(SA[i], ma);
    mi = min(SA[i], mi);
  }
  for (auto it = M.begin(); it != M.end(); it++)
    ans += it->second * K[it->first];
  cout << ans;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define rep(N) for (int i = 0; i < N; i++)
#define rep2(N1, N2)                                                           \\
  for (int i = 0; i < N1; i++)                                                 \\
    for (int j = 0; j < N2; j++)
#define rep3(N1, N2, N3)                                                       \\
  for (int i = 0; i < N1; i++)                                                 \\
    for (int j = 0; j < N2; j++)                                               \\
      for (int k = 0; k < N3; k++)
#define For(i, N) for (int i = 0; i < N; i++)
#define ll long long int
void yn(bool b) {
  if (b)
    printf("yes\\n");
  else
    printf("no\\n");
}

void Yn(bool b) {
  if (b)
    printf("Yes\\n");
  else
    printf("No\\n");
}

void YN(bool b) {
  if (b)
    printf("YES\\n");
  else
    printf("NO\\n");
}

int ctoi(char c) { return c - '0'; }

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(N) cin >> A[i];
  vector<ll> WA(N, 0);
  vector<ll> SA(N, 0);
  map<ll, ll> M, K;
  ll ans = 0;
  ll mi = 1000000000000;
  ll ma = 0;
  for (int i = 0; i < N; i++) {
    WA[i] = A[i] + i + 1;
    SA[i] = -A[i] + i + 1;
    M[WA[i]]++;
    K[SA[i]]++;
    ma = max(SA[i], ma);
    mi = min(SA[i], mi);
  }
  for (ll i = mi; i <= ma; i++)
    ans += M[i] * K[i];
  cout << ans;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  map<int, int> Nums;
  long long ans = 0;
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  for (int i = 1; i <= N; i++)
    Nums[A[i] + i]++;
  for (int i = 1; i <= N; i++)
    ans += Nums[i - A[i]];
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  long long ans = 0;
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  for (int i = 1; i <= N; i++)
    for (int j = i + A[i] + 1; j <= N; j++)
      ans += (j - i == A[i] + A[j]);
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\\n'
#define PII pair<int, int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout << "debug" << endl;
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define ULL unsigned long long
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define mem(x, a) memset(x, a, sizeof(x))
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn];
int main() {
  int n;
  cin >> n;
  ll sum = 0;
  map<int, int> mp;
  fo(i, 1, n) {
    cin >> a[i];
    sum += mp[i - a[i]];
    mp[a[i] + i]++;
  }
  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\\n'
#define PII pair<int, int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout << "debug" << endl;
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define ULL unsigned long long
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define mem(x, a) memset(x, a, sizeof(x))
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn];
int main() {
  int n;
  cin >> n;
  ll sum = 0;
  map<int, int> mp;
  fo(i, 1, n) {
    cin >> a[i];
    sum += mp[i - a[i]];
    mp[a[i] + i]++;
  }
  cout << sum << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> l;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    l[i + A.at(i)]++;
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += l[i - A.at(i)];
  }
  cout << ans << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  map::at


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> l;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    l.at(i + A.at(i))++;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += l[i - A.at(i)];
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;

#define MAX_N 200000

ll lst_a[MAX_N];
int lst_count[MAX_N];

int main() {
  int N;
  cin >> N;
  rep(i, N) cin >> lst_a[i];
  rep(i, N) lst_count[i] = 0;

  ll ans = 0;
  rep(i, N) {
    ll sub, add;
    sub = ll(i) - lst_a[i];
    add = ll(i) + lst_a[i];

    if (sub > 0)
      ans += lst_count[int(sub)];
    if (add < N)
      lst_count[int(add)]++;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;

#define MAX_N 200000

int lst_a[MAX_N];
int lst_add[MAX_N];
int lst_sub[MAX_N];

int main() {
  int N;
  cin >> N;
  rep(i, N) cin >> lst_a[i];

  rep(i, N) lst_add[i] = i + lst_a[i];
  rep(i, N) lst_sub[i] = i - lst_a[i];

  int ans = 0;
  rep(i, N) {
    rep(j, i) {
      if (lst_sub[i] == lst_add[j])
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long n, cnt, jumlah, selisih;
map<long long, long long> sum, idx;
long long a[200003], b[200003];

int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = i;
  }
  for (long long i = 1; i <= n; i++) {
    jumlah = a[i] + b[i];
    selisih = b[i] - a[i];
    sum[jumlah]++;
    idx[selisih]++;
  }
  for (long long i = 1; i <= n; i++) {
    jumlah = a[i] + b[i];
    selisih = b[i] - a[i];
    sum[jumlah]--;
    idx[selisih]--;
    cnt = cnt + sum[selisih] + idx[jumlah];
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

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

long long n, a[200005], cnt;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j + i + a[i] <= n; j++) {
      if (a[i + a[i] + j] == j)
        cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()
#define endl "\\n"

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ll res = 0;
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    if (A[i] + i < N)
      ans[A[i] + i]++;
    if (i - A[i] >= 0)
      res += ans[i - A[i]];
  }
  cout << res << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()
#define endl "\\n"

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  vector<int> ans(N);
  ll res = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] < N)
      ans[A[i] + i]++;
    if (i - A[i] >= 0)
      res += ans[i - A[i]];
  }
  cout << res << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef __int128 _int;
const int maxn = 2e5 + 6;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
int n, k;
int a[maxn];
map<int, int> num;
int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
  return;
}
signed main() {
  cin >> n;
  int ans = 0;
  num.clear();
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans += num[i - a[i]];
    num[i + a[i]] += 1;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef __int128 _int;
const int maxn = 1e5 + 6;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
int n, k;
int a[maxn];
map<int, int> num;
int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
  return;
}
signed main() {
  cin >> n;
  int ans = 0;
  num.clear();
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans += num[i - a[i]];
    num[i + a[i]] += 1;
  }
  cout << ans << endl;
  return 0;
}