#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> unique(n);
  set<int> seen;
  for (int i = n - 1; i >= 0; i--) {
    unique[i] = seen.size();
    seen.insert(a[i]);
  }
  long long cnt = 0;
  set<int> first_used;
  for (int i = 0; i < n - 1; i++) {
    if (!first_used.count(a[i])) {
      first_used.insert(a[i]);
      cnt += unique[i];
    }
  }
  cout << cnt << endl;
  return 0;
}
