#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i;
  cin >> n;
  long long int a[n], p, b[100000], sum = 0, r = 0, c[n];
  for (i = 0; i < n; i = i + 1) {
    cin >> a[i];
    p = a[i];
    b[p] = 0;
    c[i] = 1;
  }
  for (i = 0; i < n; i = i + 1) {
    p = a[i];
    b[p] = b[p] + 1;
    if (b[p] > 1) {
      c[i] = 0;
    } else {
      r = r + 1;
    }
  }
  for (i = 0; i < n; i = i + 1) {
    p = a[i];
    if (c[i] != 0) {
      p = a[i];
      if (b[p] > 1) {
        sum = sum + r;
        b[p] = b[p] - 1;
      } else if (b[p] > 0) {
        r = r - 1;
        sum = sum + r;
        b[p] = b[p] - 1;
      }
    } else {
      b[p] = b[p] - 1;
      if (b[p] == 0) {
        r = r - 1;
      }
    }
  }
  printf("%lld\n", sum);
}
