#include <bits/stdc++.h>
using namespace std;
long long int n;
vector<long long int> v, cumSum, result;
map<long long int, long long int> mp;
int main() {
  cin >> n;
  v.resize(n);
  cumSum.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]]++;
    if (mp[v[i]] == 1) result.push_back(i);
  }
  set<long long int> s;
  for (int i = n - 1; i >= 0; i--) {
    s.insert(v[i]);
    cumSum[i] = s.size();
  }
  long long int res = 0;
  for (int i = 0; i < result.size(); i++)
    if (result[i] != n - 1) res += cumSum[result[i] + 1];
  cout << res;
  return 0;
}
