#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  unordered_map<int, int> right;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    right[a[i]] += 1;
  }
  unordered_set<int> seen;
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    --right[a[i]];
    if (right[a[i]] == 0) right.erase(a[i]);
    if (seen.find(a[i]) == seen.end()) {
      res += right.size();
    }
    seen.insert(a[i]);
  }
  cout << res << endl;
  return 0;
}
