#include <bits/stdc++.h>
using namespace std;
int a[100007], b[100007], c[100007], d[100007];
int main() {
  int t, n, k;
  scanf("%d", &n);
  memset(b, 0x3f, sizeof(b));
  memset(c, 0, sizeof(c));
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++)
    if (b[a[i]] > i) b[a[i]] = i;
  for (int i = 0; i < n; i++)
    if (c[a[i]] < i) c[a[i]] = i;
  for (int i = 0; i < 100007; i++)
    if (c[i] != 0) d[c[i]]++;
  for (int i = 100007 - 2; i >= 0; i--) d[i] += d[i + 1];
  long long ans = 0LL;
  for (int i = 0; i < 100007; i++)
    if (b[i] < n) ans += (long long)d[b[i] + 1];
  printf("%lld\n", ans);
  return 0;
}
