#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, aux;
  scanf("%d", &n);
  vector<int> vec(n);
  vector<bool> control(100001, false);
  vector<int> diff(n);
  for (int i = 0; i < n; i++) scanf("%d", &vec[i]);
  control[vec[n - 1]] = true;
  diff[n - 1] = 1;
  int cnt = 1;
  for (int i = n - 2; i >= 1; i--) {
    if (control[vec[i]] == false) {
      control[vec[i]] = true;
      cnt++;
    }
    diff[i] = cnt;
  }
  control.clear();
  control.resize(100001, false);
  long long resp = 0;
  for (int i = 0; i < n - 1; i++) {
    if (control[vec[i]] == false) {
      control[vec[i]] = true;
      resp += diff[i + 1];
    }
  }
  printf("%lld\n", resp);
  return 0;
}
