#include <bits/stdc++.h>
using namespace std;
int n, a[100003], e[100005], u[100003], d[100003], volt[100003];
long long ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (e[a[i]] == 0) e[a[i]] = i;
    u[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) d[u[a[i]]] = 1;
  for (int i = n; i >= 1; i--) d[i] = d[i] + d[i + 1];
  for (int i = 1; i <= n; i++) {
    if (volt[a[i]] == 0) {
      if (e[a[i]] != u[a[i]]) ans = ans + 1;
      ans = ans + (d[e[a[i]]] - 1);
    }
    volt[a[i]] = 1;
  }
  cout << ans;
  return 0;
}
