void main() {
  problem();
}

void problem() {
  const N = scan!int;
  const H = scan!long(N);

  void solve2() {
    auto LH = N.iota.map!(i => i + H[i]);
    auto RH = N.iota.map!(i => i - H[i]);
    
    int[long] LHM;
    foreach(x; LH) LHM[x]++;

    int[long] RHM;
    foreach(x; RH) RHM[x]++;

    LHM.deb;
    RHM.deb;

    long answer;
    foreach(x; 2..N+1) {
      if (x in LHM && x in RHM) answer += LHM[x] * RHM[x];
    }

    answer.writeln;
  }

  void solve() {
    long answer;
    long count;

    bool[long][long] byHeight;
    foreach(i; 0..N) {
      if (H[i] >= N) continue;

      byHeight[H[i]][i] = true;
    }
    
    foreach(i; 0..N-1) {
      foreach(h; byHeight.keys) {
        byHeight[h].remove(i);
        if (byHeight[h].length == 0) {
          byHeight.remove(h);
          continue;
        }
        if (h + H[i] > N) continue;

        deb([i, h, H[i] + h]);
        deb(byHeight[h]);
        if ((H[i] + h + i) in byHeight[h]) {
          answer++;
          deb("PLUS!!");
          byHeight.deb;
        }
      }
    }

    deb(count);
    writeln(answer);
  }

  // solve();
  solve2();
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------
