#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  map<int, int> mep;
  for (int i = 0; i < n; i++) {
    mep[ar[i]]++;
  }
  int un[n];
  map<int, int>::iterator it;
  for (int i = 0; i < n; i++) {
    it = mep.find(ar[i]);
    if (it->second == 1) {
      mep.erase(it);
    } else {
      it->second--;
    }
    un[i] = mep.size();
  }
  set<int> cpy;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (cpy.count(ar[i])) {
      continue;
    }
    cpy.insert(ar[i]);
    ans += un[i];
  }
  cout << ans << endl;
  return 0;
}
