#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1123456;
const int MAXINT = 2147483098;
const long long MAXLL = 9223372036854775258LL;
const long long MOD = 1e9 + 7;
int a[MAXN];
int pos[MAXN];
bool used[MAXN];
int cnt[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  long long ans = 0, uniq = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (cnt[a[i]] == 0) uniq++;
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; ++i) {
    cnt[a[i]]--;
    if (cnt[a[i]] == 0) uniq--;
    if (!used[a[i]]) {
      ans += uniq;
      used[a[i]] = 1;
    }
  }
  cout << ans << '\n';
  return 0;
}
