#include <bits/stdc++.h>
using namespace std;
long long n, a[100010], b, i, fr[100010], ans, x, ok[100010];
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (fr[a[i]] == 0) ans++;
    fr[a[i]]++;
  }
  for (i = 1; i <= n; i++) {
    if (fr[a[i]] > 1 && ok[a[i]] == 0) x = x + ans, ok[a[i]] = 1;
    if (fr[a[i]] == 1 && ok[a[i]] == 0)
      x = x + max((long long)0, ans - 1), ok[a[i]] = 1;
    fr[a[i]]--;
    if (fr[a[i]] == 0) ans--;
  }
  cout << x;
  return 0;
}
