#include <bits/stdc++.h>
using namespace std;
const int intN = 3e5 + 10;
const int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int cmp(int a, int b) { return a > b; }
int main() {
  long long int n, i, out = 0;
  long long int ans[200000 + 10], s[200000 + 10], ha[200000 + 10] = {0};
  set<long long int> p;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) scanf("%lld", &s[i]);
  for (i = n - 1; i >= 0; i--) {
    p.insert(s[i]);
    ans[i] = p.size();
  }
  for (i = 0; i < n - 1; i++) {
    if (ha[s[i]] == 0) {
      out += ans[i + 1];
      ha[s[i]] = 1;
    }
  }
  printf("%lld\n", out);
  return 0;
}
