#include <bits/stdc++.h>
using namespace std;
const size_t MAX = 1 << 17;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  uint32_t n;
  cin >> n;
  static uint32_t A[MAX];
  for (uint32_t i = 0; i < n; i++) cin >> A[i];
  static uint32_t L[MAX];
  fill(L, L + MAX, -1u);
  for (uint32_t i = 0; i < n; i++) {
    if (L[A[i]] == -1u) L[A[i]] = i;
  }
  static uint64_t S[MAX];
  static bitset<MAX> V;
  for (uint32_t i = n; i-- > 0;) {
    S[i] = S[i + 1];
    if (not V[A[i]]) S[i]++;
    V[A[i]] = true;
  }
  uint64_t r = 0;
  for (uint32_t a = 0; a < MAX; a++) {
    if (L[a] != -1u) r += S[L[a] + 1];
  }
  cout << r;
}
