#include <bits/stdc++.h>
using namespace std;
mt19937 Random(int(time(0)));
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int P = 239017;
const long long BINF = 1e18 + 10;
const long double EPS = 1e-6;
const int N = 2e5 + 10;
int t[8 * N];
void relax(int v) { t[v] = t[2 * v] + t[2 * v + 1]; }
void upd(int v, int l, int r, int need) {
  if (l == r) {
    t[v]++;
    return;
  }
  int mid = (l + r) / 2;
  if (need <= mid) {
    upd(2 * v, l, mid, need);
  } else {
    upd(2 * v + 1, mid + 1, r, need);
  }
  relax(v);
}
inline int get_sum(int v, int l, int r, int a, int b) {
  if (l > b || r < a) {
    return 0;
  }
  if (l >= a && r <= b) {
    return t[v];
  }
  int mid = (l + r) / 2;
  return get_sum(2 * v, l, mid, a, b) + get_sum(2 * v + 1, mid + 1, r, a, b);
}
inline void source() {
  int n;
  cin >> n;
  vector<int> st, arr(n + 1);
  map<int, int> val;
  for (int i = 1; i <= n; i++) {
    st.push_back(i);
    cin >> arr[i];
    st.push_back(arr[i]);
  }
  sort((st).begin(), (st).end());
  st.resize(unique((st).begin(), (st).end()) - st.begin());
  int mx = st.size();
  for (int i = 0; i < st.size(); i++) {
    val[st[i]] = i + 1;
  }
  vector<pair<int, int> > query;
  for (int i = 1; i <= n; i++) {
    query.push_back({min(val[arr[i]], val[i] - 1), val[i]});
  }
  sort((query).begin(), (query).end());
  int cur = 1;
  long long ans = 0;
  for (auto it : query) {
    while (cur <= it.first) {
      upd(1, 1, mx, val[arr[cur]]);
      cur++;
    }
    ans += get_sum(1, 1, mx, it.second, mx);
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  source();
  return 0;
}
