import std;

long calc(long[] a) {
    long ans = 0;
    long[long] d;
    for (int i = 0; i < a.length; i++) {
        if (i + 1 >= a[i]) {
            ans += d.get(i + 1 - a[i], 0);
        }
        d[i + 1 + a[i]]++;
    }
    return ans;
}

void main() {
    readint;
    auto a = reads!long;
    writeln(calc(a));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
