#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bool vis[N];
bool freq[N];
int a[N];
int sum[N];
int n, cnt = 0;
long long ans = 0ll;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = n - 1; i >= 0; i--) {
    if (!freq[a[i]]) cnt++;
    freq[a[i]] = 1;
    sum[i] = cnt;
  }
  for (int i = 0; i < n; i++) {
    if (vis[a[i]]) continue;
    vis[a[i]] = 1;
    ans += sum[i + 1] * 1ll;
  }
  printf("%lld\n", ans);
}
