#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
int t[N];
void inc(int x, int y) {
  for (int i = x; i < N; i = i | (i + 1)) t[i] += y;
}
int get(int x) {
  int res = 0;
  for (int i = x; i >= 0; i = (i & (i + 1)) - 1) res += t[i];
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i <= n; ++i) cin >> a[i];
  long long ans = 0;
  set<pair<int, int> > kek;
  for (int i = 1; i <= n; ++i) {
    while (!kek.empty() && kek.begin()->first < i) {
      pair<int, int> nxt = *kek.begin();
      kek.erase(nxt);
      inc(nxt.second, -1);
    }
    ans += get(min(n, a[i]));
    inc(i, 1);
    kek.insert({a[i], i});
  }
  cout << ans;
  return 0;
}
