#include <bits/stdc++.h>
using namespace std;
int a[100005];
int f[100005];
int s[100005];
int c[100005];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (c[a[i]] == 0) f[i] = 1;
    c[a[i]]++;
  }
  memset(c, 0, sizeof c);
  for (int i = n - 1; i >= 0; i--) {
    if (c[a[i]] == 0) s[i] = 1;
    c[a[i]]++;
  }
  int cnt = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i]) cnt++;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i]) cnt--;
    if (f[i] == 0) continue;
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}
