#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> v(n), psum(n);
  for (long long int i = 0; i < n; i++) {
    cin >> v[i];
  }
  set<long long int> s;
  for (long long int i = n - 1; i > 0; i--) {
    s.insert(v[i]);
    psum[i] = s.size();
  }
  long long int res = 0;
  vector<long long int> fq(200500, 0);
  for (long long int i = 0; i < n - 1; i++) {
    if (!fq[v[i]]) {
      res += psum[i + 1];
      fq[v[i]]++;
    }
  }
  cout << res << endl;
}
