#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long powm(long long base, long long exp, long long mod = 10000000079) {
  base %= mod;
  long long ans = 1;
  while (exp) {
    if (exp & 1LL) ans = (ans * base) % mod;
    exp >>= 1LL, base = (base * base) % mod;
  }
  return ans;
}
long long freq[100005];
vector<long long> a;
long long v[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    freq[x]++;
    a.push_back(x);
  }
  long long c = 0;
  for (int i = 1; i <= 100000; i++) {
    c += (freq[i] != 0);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (v[a[i]]) {
      freq[a[i]]--;
      if (freq[a[i]] == 0) c--;
      continue;
    }
    v[a[i]] = 1;
    freq[a[i]]--;
    if (freq[a[i]] == 0) c--;
    ans += (c);
  }
  cout << ans << '\n';
}
