#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<long long> count(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  unordered_map<int, bool> cm;
  unordered_map<int, bool> fpm;
  int tmp = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (cm.find(a[i]) == cm.end()) {
      cm[a[i]] = 1;
      tmp++;
    }
    count[i] = tmp;
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (fpm.find(a[i]) == fpm.end()) {
      fpm[a[i]] = 1;
      ans = ans + count[i + 1];
    }
  }
  cout << ans;
  return 0;
}
