#include <bits/stdc++.h>
using namespace std;
const long long mod = 2;
long long n, k;
long long a[100001];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  unordered_map<long long, long long> L, R;
  long long ans = 0;
  for (int i = 0; i < n; i++) R[a[i]]++;
  for (int i = 0; i < n; i++) {
    if (L.find(a[i]) == L.end()) {
      if (R[a[i]] == 1)
        R.erase(a[i]);
      else
        R[a[i]]--;
      ans += R.size();
      L[a[i]]++;
    } else {
      L[a[i]]++;
      if (R[a[i]] == 1)
        R.erase(a[i]);
      else
        R[a[i]]--;
    }
  }
  cout << ans;
  return 0;
}
