#include <bits/stdc++.h>
using namespace std;
long long int BIT[1000000] = {0};
long long int n;
void update(long long int x, long long int delta) {
  for (; x <= n; x += x & -x) BIT[x] += delta;
}
long long int query(long long int x) {
  long long int sum = 0;
  for (; x > 0; x -= x & -x) sum += BIT[x];
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int i, j;
  cin >> n;
  vector<pair<long long, long long> > v;
  vector<long long int> v1;
  for (i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    v1.push_back(x);
    v.push_back(make_pair(x, i + 1));
    if (i != n - 1) v.push_back(make_pair(i + 1, -(i + 1)));
  }
  sort(v.begin(), v.end());
  long long int ans = 0;
  for (i = v.size() - 1; i >= 0; i--) {
    if (v[i].second > 0) {
      update(v[i].second, 1);
    } else {
      long long int st = abs(v[i].second) + 1, ed = min(n, v1[v[i].first - 1]);
      if (st <= ed) ans = ans + query(ed) - query(st - 1);
    }
  }
  cout << ans;
  return 0;
}
