#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, dist = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  map<int, int> mp, done;
  vector<int> dis(n);
  for (int i = n - 1; i >= 0; i--) {
    mp[a[i]]++;
    if (mp[a[i]] == 1) dist++;
    dis[i] = dist;
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (done[a[i]] == 0) {
      ans += dis[i + 1];
      done[a[i]] = 1;
    }
  }
  cout << ans;
}
