#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned n;
  vector<unsigned> a;
  map<unsigned, unsigned> r_bound;
  vector<unsigned> l_bound;
  cin >> n;
  a.resize(n);
  for (unsigned i(0); i < n; ++i) {
    cin >> a[i];
    if (!r_bound.count(a[i])) {
      l_bound.push_back(i);
    }
    r_bound[a[i]] = i;
  }
  unsigned long long res(0);
  for (const auto& x : r_bound) {
    unsigned r = x.second;
    res += lower_bound(l_bound.begin(), l_bound.end(), r) - l_bound.begin();
  }
  cout << res;
}
