//事前知識：vectorは必須。(仕組みが知りたければ、エイリアステンプレート、auto型、範囲for文を調べることを推奨）


//macの場合は準備が必要。
//既存のXcodeに付属しているg++は古いケースも多いので、https://qiita.com/wawawa/items/50c2c612b0937f28d92b　の通りにやって最新版を使えるようにする。
//5行目はmacには標準装備されてないので、自分で用意する必要がある。https://qiita.com/flowerrr__lily/items/28a20062e957fa10b7a7　の通りにやろう。

//標準ライブラリの一括インストール
#include <bits/stdc++.h>
using namespace std;

//int系宣言（long long型はよく使うので省略して書けるようにしてる）
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

//多次元配列宣言
template<typename T> using vec2d = vector<vector<T>>;
template<typename T> using vec3d = vector<vector<vector<T>>>;
template<typename T> using vec4d = vector<vector<vector<vector<T>>>>;
template<typename T> using vec5d = vector<vector<vector<vector<vector<T>>>>>;

//?
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

//for文
#define for00(i, n) for(lint i=0,i##_end_=(n);i<i##_end_;i++)
#define for10(i, n) for(lint i=1,i##_end_=(n);i<i##_end_;i++)
#define for01(i, n) for(lint i=0,i##_end_=(n);i<=i##_end_;i++)
#define for11(i, n) for(lint i=1,i##_end_=(n);i<=i##_end_;i++)
#define formn(i, m, n) for(lint i=(m),i##_end_=(n);i<=i##_end_;i++)

#define forin(x, vec) for(auto (x) : (vec))

//cin, coutでvector等を一括で入出力
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto it=vec.begin();it!=vec.end();it++){ os << *it; auto it2 = it;it2++;if(it2 != vec.end()){cout << ",";}} os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }

//多次元vectorのコンストラクタ
template<typename T> vec2d<T> make2d(lint L, lint M, T value){ vec2d<T> ans(M, vector<T>(L, value)); return ans;}
template<typename T> vec3d<T> make3d(lint L, lint M, lint N, T value){ vec3d<T> ans(N,vec2d<T>(M, vector<T>(L, value))); return ans;}
template<typename T> vec4d<T> make4d(lint L, lint M, lint N, lint O, T value){ vec4d<T> ans(O, vec3d<T>(N,vec2d<T>(M, vector<T>(L, value)))); return ans;}
template<typename T> vec5d<T> make5d(lint L, lint M, lint N, lint O, lint P, T value){vec5d<T> ans(O,vec4d<T>(O, vec3d<T>(N,vec2d<T>(M, vector<T>(L, value))))); return ans;}

//vectorの要素を一括設定
template<typename T> void setAll1d(vector<T>& vec, T value){for(auto& v : vec){v = value;}}
template<typename T> void setAll2d(vec2d<T>& vec, T value){for(auto& v1 : vec){for(auto& v2 : v1){v2 = value;}}}
template<typename T> void setAll3d(vec3d<T>& vec, T value){for(auto& v3 : vec){for(auto& v2 : v3){for(auto& v1 : v2){v1 = value;}}}}
template<typename T> void setAll4d(vec4d<T>& vec, T value){for(auto& v4 : vec){for(auto& v3 : v4){for(auto& v2 : v3){for(auto& v1 : v2){v1 = value;}}}}}
template<typename T> void setAll5d(vec5d<T>& vec, T value){for(auto& v5 : vec){for(auto& v4 : v5){for(auto& v3 : v4){for(auto& v2 : v3){for(auto& v1 : v2){v1 = value;}}}}}}

//2,3次元vectorを綺麗にcout
template<typename T>void vout2d(vec2d<T> vec){cout << "[" << endl;forin(v, vec){cout << "  " << v << endl;}cout << "]" << endl;}
template<typename T>void vout3d(vec2d<T> vec){cout << "[" << endl;forin(v,vec){cout << "  [" << endl;forin(x,v){cout << "    " << x << endl;}cout << "  ]" << endl;}cout << "]" << endl;}

//最大公約数
lint gcp(lint a, lint b){if (a > b) return (gcp(b,a));if (a ==0) return (0);lint r = 1;while(1){r = b % a;if (r == 0) break;b = a;a = r;}return (a);}

//lintの階乗と累乗（modで割った余り。mod=0とするとそのまま）
lint factorial(lint n, lint mod){if(n <= 1) return 1;if(mod == 0) return (n*factorial(n-1,0));return (n * factorial(n-1,mod)%mod);}
lint power(lint a, lint b, lint p) {if (b == 0) {return 1;} else if (b % 2 == 0) {lint d = power(a, b / 2, p);if(p==0) return (d * d);else return (d * d) % p;} else {if(p==0)return (a * power(a,b-1,0));else return (a * power(a, b - 1, p)) % p;}}

//lintのn桁目の数字を返す
lint nget(lint num, lint n){return (num%power(10,n,0)/power(10,n-1,0));}

//nの%mod における逆元
lint modinv(lint n, lint mod){return (power(n,mod-2,mod));}

//n!の %mod における逆元
lint factorialinv(lint n, lint mod){if (n==1)return 1;else return modinv(n,mod) * factorialinv(n-1,mod);}

//nCm % mod (modはnより大きい素数)
lint comb(lint n, lint m, lint mod){return factorial(n,mod) * factorialinv(m,mod) % mod * factorialinv(n-m,mod) % mod;}

lint max1(lint a,lint b){
  if(a>b)
    return a;
  else
    return b;
}

int main(){
/*
  //for文を効率的に書く。
  cout << "for00(i,10)" << endl; //0 <= i < 10
  for00(i,10){
    cout << i;
  }
  cout << endl << endl;
  
  cout << "for10(i,10)" << endl; //1 <= i < 10
  for10(i,10){
    cout << i;
  }
  cout << endl << endl;

  cout << "for01(i,10)" << endl; //0 <= i <=10
  for01(i,10){
    cout << i;
  }
  cout << endl << endl;
  
  cout << "for11(i,10)" << endl; //1 <= i <= 10
  for11(i,10){
    cout << i;
  }
  cout << endl << endl;
  
  cout << "formn(i,5,10)" << endl;
  formn(i,5,10){
    cout << i;
  }
  cout << endl << endl;
  
  vector<int> v(5,0);
  cout << "forin(x, vector<int> v(5,0))" << endl;
  forin(x, v){
    cout << x;
  }
  cout << endl << endl << endl;

  

  //多次元配列の宣言と標準入出力
  
  //1次元
  vector<int> v1(3,0);
  cout << "intを３つ入力してください。" << endl;
  cin >> v1;
  cout << v1 << endl << endl;

  //2次元
  vec2d<int> v2 = make2d(2,3,0);
  cout << "intを2×3個入力して下さい。" << endl;
  cin >> v2;
  cout << v2 << endl;
  vout2d(v2); //綺麗に出力
  cout << endl << endl;

  //3次元
  vec3d<int> v3 = make3d(2,3,2,0);
  cout << "intを2×3×2個入力して下さい。" << endl;
  cin >> v3;
  cout << v3 << endl;
  vout3d(v3); //綺麗に出力
  cout << endl << endl;

  //4次元
  vec4d<int> v4 = make4d(1,1,2,2,0);
  cout << "intを1×1×2×2個入力してください。"<< endl;
  cin >> v4;
  cout << v4 << endl << endl;

  //5次元
  vec5d<int> v5 = make5d(1,1,2,2,2,0);
  cout << "intを1×1×2×2×2つ入力してください。" << endl;
  cin >> v5;
  cout << v5 << endl << endl;
  
  //すべてのvectorの全ての要素の値を入力値に一括変更
  cout << "intを一つ入力してください" << endl;
  int x;
  cin >> x;
  setAll1d(v1,x);
  setAll2d(v2,x);
  setAll3d(v3,x);
  setAll4d(v4,x);
  setAll5d(v5,x);
  cout << v1 << endl << endl;
  cout << v2 << endl << endl;
  cout << v3 << endl << endl;
  cout << v4 << endl << endl;
  cout << v5 << endl << endl;

  //最大公約数
  cout << "数字を２つ入力してください。最大公約数を計算します。" << endl;
  lint a,b;
  cin >> a >> b;
  cout << gcp(a,b) << endl;

  //階乗
  cout << "数字を2つ(num,mod)入力してください。num!%modを計算します。" << endl;
  lint num;
  lint mod;
  cin >> num >> mod;
  cout << num << "!%" << mod << "=" << factorial(num,mod) << endl;

  //累乗
  cout << "数字を３つ(num,n,mod)入力してください。num^n%modを計算します。" << endl;
  int n;
  cin >> num >> n >> mod;
  cout << num << "^" << n << "%" << mod << "=" << power(num,n,mod) << endl;

  //n桁目の数字をゲット
  cout << "数字を２つ(num,n)入力してください。numのn桁目の数字を返します。" << endl;
  cin >> num >> n;
  cout << nget(num,n) << endl;


  //組み合わせ
  cout << "数字を３つ（n,m,mod)入力してください。nCm % mod を計算します。" << endl;
  lint n1, m1, mod1;
  cin >> n1 >> m1 >> mod1;
  cout << comb(n1, m1, mod1) << endl;
*/
  lint n;
  cin >> n;
  vector<lint> a(n+1);
  for11(i,n){
    cin >> a[i];
  }
  vector<lint> dp(2*n,0);
  lint ans = 0;  
  for11(i,n-1){
    if(a[i]+i < 2*n)
      dp[a[i]+i] += 1;
    if (i+1 - a[i+1] >= 0 && i+1 - a[i+1]<2*n)
      ans += dp[i+1 - a[i+1]];
  }

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



Measured memory_bytes: 7920