//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void a(){
    string s;
    cin >> s;
    if(s=="ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;
}
void b(){
    ll n,k; cin >> n >> k;
    map<ll,ll> memo;
    rep(i,k){
        ll d; cin >> d;
        rep(j,d){
            ll A; cin >> A;
            memo[A]++;
        }
    }
    cout << n-memo.size() << endl;
}

void c(){
    ll n,m; cin >> n >> m;
    auto h = v<>(n,0);
    auto ab = vv<>(n,v<>());
    rep(i,n) cin >> h[i];
    rep(i,m){
        ll A,B;
        cin >> A >> B;
        A--; B--;
        ab[A].push_back(B);
        ab[B].push_back(A);
    }
    ll cnt = 0;
    rep(i,n){
        bool chk=true;
        for(auto j:ab[i]){
            if(h[i]<=h[j]){
                chk=false;
                break;
            }
        }
        if(chk) cnt++;
    }

    cout << cnt << endl;
}

void d(){
    ll x; cin >> x;
    auto ab5 = unordered_map<ll,ll>();
    
    
    rep(i,(ll)1000){
        ll t = (ll)pow(i,5);
        ab5[t]=i;
        ab5[-t]=-i;
    }
    

    for(auto i:ab5){
        ll t = x+i.first;
        if(ab5[t]!=0){
            cout << ab5[t] << " " << i.second << endl;
            return;
        }
    }
    
}
void e(){
    ll n; cin >> n;
    unordered_map<ll,ll> memo0;
    unordered_map<ll,ll> memo1;
    for(ll i=1;i<=n;i++) {
        ll A; cin >> A;
        if(i>=A+2)memo0[abs(i-A)]++;
        memo1[abs(i+A)]++;
    }
    ll ans =0;
    for(ll i=0;i<2*n;i++){
        ans+=memo0[i]*memo1[i];
    }

    cout << ans << endl;
}
void f(){}
int main(){
    e();
    return 0;
}


Measured memory_bytes: 39252