#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
const long long linf = 1000000000000000007;
void solution() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<int> sd(n);
  sd[n - 1] = 1;
  map<int, int> used;
  used[a[n - 1]] = 1;
  for (int i = n - 2; i >= 0; i--) {
    sd[i] = sd[i + 1];
    if (!used[a[i]]) {
      used[a[i]] = 1;
      sd[i]++;
    }
  }
  long long an = 0LL;
  used.clear();
  for (int i = 0; i < n - 1; ++i) {
    if (!used[a[i]]) {
      an += sd[i + 1];
      used[a[i]] = true;
    }
  }
  cout << an << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solution();
  return 0;
}
