#include <bits/stdc++.h>
using namespace std;
int ara[100005];
int frs[100005];
int lst[100005];
vector<int> v;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    ara[i] = x;
    if (!frs[x]) {
      frs[x] = i;
    }
  }
  for (int i = n; i > 0; i--) {
    if (!lst[ara[i]]) {
      lst[ara[i]] = i;
      v.push_back(i);
    }
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  for (int i = 1; i <= 100000; i++) {
    if (!frs[i]) continue;
    int x = frs[i];
    int y = upper_bound(v.begin(), v.end(), x) - v.begin();
    ans += (long long)(v.size() - y);
  }
  cout << ans << endl;
  return 0;
}
