#include <bits/stdc++.h>
using namespace std;
int a[100100], fr[100100];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  unordered_set<int> right, left;
  long long cnt = 0;
  for (auto i = 0; i < n; i++) {
    cin >> a[i];
    fr[a[i]]++;
  }
  for (auto i = 0; i < n; i++) right.insert(a[i]);
  int prev = 0;
  for (auto i = 0; i < n; i++) {
    fr[a[i]]--;
    if (fr[a[i]] == 0) {
      right.erase(a[i]);
    }
    left.insert(a[i]);
    if (prev != left.size()) {
      cnt += right.size();
      prev++;
    }
  }
  cout << cnt;
  return 0;
}
