#include <bits/stdc++.h>
using namespace std;
int seq[500000];
bool chk_l[500000];
int chk_r[500000];
void clean_r() {
  for (int i = 0; i < 500000; i++) {
    chk_r[i] = 0;
  }
}
int main(int argc, const char* argv[]) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &seq[i]);
  }
  for (int i = 0; i < 500000; i++) {
    chk_l[i] = 0;
  }
  clean_r();
  long long ans = 0;
  int poss = 0;
  for (int j = 0; j < n; j++) {
    if (chk_r[seq[j]] == 0) poss++;
    chk_r[seq[j]]++;
  }
  for (int i = 0; i < n - 1; i++) {
    chk_r[seq[i]]--;
    if (chk_r[seq[i]] <= 0) poss--;
    if (chk_l[seq[i]] == 0) {
      chk_l[seq[i]] = 1;
      ans += (long long)poss;
    }
  }
  cout << ans << endl;
  return 0;
}
