#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O2")
const int MAX = 1e5;
long long l[MAX + 1], r[MAX + 1], a[MAX + 1], n, ans = 0;
vector<long long> rr;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (l[a[i]] == 0) {
      l[a[i]] = i;
    }
    r[a[i]] = i;
  }
  for (int i = 1; i <= MAX; i++)
    if (r[i] != 0) rr.push_back(r[i]);
  sort(rr.begin(), rr.end());
  for (int i = 1; i <= MAX; i++) {
    if (l[i] != 0) {
      auto it = upper_bound(rr.begin(), rr.end(), l[i]);
      ans += (rr.end() - it);
    }
  }
  cout << ans << endl;
  return 0;
}
