#include <bits/stdc++.h>
using namespace std;
int long long n, i, d, ans, a[100005], b[100005];
bool us[100005];
set<int> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    v.insert(a[i]);
    b[a[i]]++;
  }
  for (i = 1; i <= n; i++) {
    if (!us[a[i]]) {
      us[a[i]] = 1;
      b[a[i]]--;
      if (b[a[i]] == 0) v.erase(a[i]);
      ans += v.size();
    } else {
      b[a[i]]--;
      if (b[a[i]] == 0) v.erase(a[i]);
    }
  }
  cout << ans;
}
