#include <bits/stdc++.h>
using namespace std;
int n, cnt, arr[100009], freq[100009], freq1[100009];
long long ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    if (!freq[arr[i]]) ++cnt;
    freq[arr[i]]++;
  }
  for (int i = 0; i < n; ++i) {
    --freq[arr[i]];
    if (!freq[arr[i]]) --cnt;
    if (freq1[arr[i]]) continue;
    ans += cnt;
    freq1[arr[i]] = true;
  }
  cout << ans;
  return 0;
}
