#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int unique[n];
  set<int> seen;
  for (int i = 0; i < n; i++) {
    seen.insert(a[i]);
    unique[i] = seen.size();
  }
  seen.clear();
  long long ans = 0;
  for (int i = n - 1; i > 0; i--) {
    if (seen.count(a[i]) == 0) {
      ans += (long long)unique[i - 1];
      seen.insert(a[i]);
    }
  }
  cout << ans << '\n';
}
