#include <bits/stdc++.h>
using namespace std;
int main() {
  long long res = 0;
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i += 1) cin >> a[i];
  vector<int> b(n);
  vector<bool> Sx(100000);
  int c = 0;
  for (int i = n - 1; i >= 1; i -= 1) {
    if (!Sx[a[i] - 1]) {
      Sx[a[i] - 1] = true;
      b[i] = ++c;
    } else {
      b[i] = b[i + 1];
    }
  }
  vector<bool> Sy(100000);
  for (int i = 0; i < n - 1; i += 1) {
    if (!Sy[a[i] - 1]) {
      res += b[i + 1];
      Sy[a[i] - 1] = true;
    }
  }
  cout << res << '\n';
}
