#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
double lg(double a) { return (log(a) / log(10.0)); }
const long long N = 111111;
long long n, ans = 0, x;
vector<long long> cnt(N, 0), d(N, 0), a;
set<long long> b;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i <= n - 1; i++) {
    cin >> x;
    a.push_back(x);
    cnt[x]++;
    b.insert(x);
  }
  for (auto i : a) {
    cnt[i]--;
    if (!cnt[i]) b.erase(i);
    if (!d[i]) {
      d[i] = 1;
      ans += ((int)(b).size());
    }
  }
  cout << ans << endl;
}
