#include <bits/stdc++.h>
const int N = 1e5 + 7;
using namespace std;
const int M = 100000;
int c[N], a[N], fir[N], vis[N], last[N];
int n;
int lowbit(int x) { return (x & (-x)); }
void updata(int x, int y) {
  while (x <= n) {
    c[x] += y;
    x += lowbit(x);
  }
}
int query(int x) {
  int ans = 0;
  while (x) {
    ans += c[x];
    x -= lowbit(x);
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = n; i >= 1; i--) {
    fir[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) last[a[i]] = i;
  sort(fir + 1, fir + M + 1);
  sort(last + 1, last + M + 1);
  int p, q;
  p = q = 0;
  long long ans = 0;
  while (fir[p] == 0) p++;
  while (last[q] == 0) q++;
  while (p <= M) {
    while (last[q] <= fir[p] && q <= M) q++;
    ans += (long long)(M - q + 1);
    if (q == M + 1) break;
    p++;
  }
  printf("%I64d\n", ans);
}
