#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, k;
  cin >> n;
  long long a[n + 1];
  map<long long, long long> mp1;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    mp1[a[i]]++;
  }
  map<long long, long long> mp;
  long long ans = 0;
  for (i = 1; i <= n; ++i) {
    mp1[a[i]]--;
    if (mp1[a[i]] == 0) mp1.erase(a[i]);
    if (mp.find(a[i]) == mp.end()) {
      ans += mp1.size();
    }
    mp[a[i]]++;
  }
  cout << ans;
  return 0;
}
