#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
vector<int> v;
int s[N], c[N];
int n, k;
int main() {
  cin >> n;
  int l;
  for (int i = 0; i < n; i++) {
    cin >> l;
    v.push_back(l);
    s[l]++;
    if (s[l] == 1) k++;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    s[v[i]]--;
    if (s[v[i]] == 0) k--;
    if (!c[v[i]]) {
      ans += k;
      c[v[i]] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
