#include <iostream>
#include <optional>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define int long long
struct fenwick_tree {
vector<int> fwt;
vector<int> base;
fenwick_tree(vector<int>& input) {
base = input;
vector<int> prefixSum(input.size()+1);
prefixSum[0] = 0;
for (size_t i = 1; i < input.size()+1; i++)
{
prefixSum[i] = prefixSum[i - 1] + input[i-1];
}
fwt.push_back(prefixSum[0]);
for (size_t i = 1; i < input.size()+1; i++)
{
int range = i - (i & (i - 1));
fwt.push_back(prefixSum[i] - prefixSum[i - range]);
}
}
int sumRange(int beg, int end) {
end++;
return sumFromBeginning(end) - sumFromBeginning(beg);
}
int sumFromBeginning(int end) {
int sum = 0;
while (end != 0) {
sum += fwt[end];
end = (end & (end - 1));
}
return sum;
}
void update(int idx, int newVal) {
int dif = newVal - base[idx];
base[idx] = newVal;
idx++;
while (idx < fwt.size()) {
fwt[idx] += dif;
int range = idx - (idx & (idx - 1));
idx = (idx & (idx - 1)) + 2*range;
}
}
};
signed main()
{
int n;
cin >> n;
vector<int> inp(n,1);
vector<pair<int, int>> sVec(n);
for (size_t i = 0; i < n; i++)
{
int a;
cin >> a;
sVec[i] = { a,i };
}
sort(sVec.begin(), sVec.end());
fenwick_tree fw = fenwick_tree(inp);
int ans = 0;
for (size_t i = 0; i < n; i++)
{
fw.update(sVec[i].second, 0);
int beg = max(0ll, sVec[i].second - sVec[i].first);
int end = min(n-1, sVec[i].second + sVec[i].first);
ans += fw.sumRange(beg, end);
}
cout << ans << "\n";
}