#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  set<long int> s;
  long int n, i;
  cin >> n;
  long long a[n], b[n], c[n], ans = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s.insert(a[i]);
    b[i] = s.size();
  }
  if (n == 1)
    cout << "0";
  else {
    reverse(a, a + n);
    s.clear();
    for (i = 0; i < n; i++) {
      s.insert(a[i]);
      c[i] = s.size();
    }
    reverse(c, c + n);
    ans = c[1];
    for (i = 1; i < n - 1; i++) {
      if (b[i] != b[i - 1]) ans += c[i + 1];
    }
    cout << ans;
  }
}
