#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int MAX = 550;
const double dinf = 1235678;
const long long mod = 1e9 + 7;
int n, v[maxn];
int main() {
  cin >> n;
  map<int, bool> novo;
  map<int, int> dif;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    novo[v[i]] = 1;
    dif[v[i]]++;
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (novo[v[i]]) {
      novo[v[i]] = 0;
      dif[v[i]]--;
      if (!dif[v[i]]) {
        auto it = dif.find(v[i]);
        dif.erase(it);
      }
      ans += (int)dif.size();
    } else {
      dif[v[i]]--;
      if (!dif[v[i]]) {
        auto it = dif.find(v[i]);
        dif.erase(it);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
