#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N];
long long ans;
map<int, vector<int>> m;
int first[4 * N];
void add(int p, int l, int r, int i) {
  if (l > i or r < i) return;
  if (l == r and l == i) {
    first[p]++;
    return;
  }
  int m = (l + r) / 2;
  add(2 * p, l, m, i);
  add(2 * p + 1, m + 1, r, i);
  first[p] = first[2 * p] + first[2 * p + 1];
}
int query(int p, int l, int r, int i, int j) {
  if (l > j or r < i) return 0;
  if (i <= l and r <= j) return first[p];
  int m = (l + r) / 2;
  return query(2 * p, l, m, i, j) + query(2 * p + 1, m + 1, r, i, j);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), m[a[i]].push_back(i);
  int p = 0;
  for (auto& x : m) {
    int v = x.first;
    for (; p <= n and p <= v; p++)
      if (a[p] > p) ans += min(a[p], n) - p - query(1, 1, n, p, min(a[p], n));
    for (auto& y : x.second) add(1, 1, n, y);
  }
  printf("%lld\n", ans);
  return 0;
}
