#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, temp;
  long long cou = 0;
  cin >> n;
  multiset<int> b;
  set<int> a;
  set<int> d;
  map<int, int> t;
  vector<int> r;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    a.insert(temp);
    b.insert(temp);
    r.push_back(temp);
  }
  for (auto now : a) {
    int c = 0;
    for (auto now2 = b.lower_bound(now); now2 != b.upper_bound(now); now2++) {
      c++;
    }
    t[now] = c;
  }
  for (auto now : r) {
    t[now]--;
    if (t[now] == 0) a.erase(now);
    if (d.find(now) == d.end()) {
      cou += a.size();
      d.insert(now);
    }
  }
  cout << cou;
  return 0;
}
