#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  map<long long int, vector<long long int> > M;
  set<long long int> st;
  vector<long long int> v(n, 0), v1(n, 0);
  for (long long int i = 0; i <= n - 1; i++) {
    cin >> a[i];
    st.insert(a[i]);
    v1[i] = st.size();
  }
  st.clear();
  for (long long int i = n - 1; i >= 0; i--) {
    if (M[a[i]].size() == 0) {
      M[a[i]] = {i, i};
    } else
      M[a[i]][0] = i;
    v[i] = M.size();
  }
  long long int ans = 0;
  for (auto i : M) {
    vector<long long int> vec = i.second;
    ans += v[vec[0]] - 1;
    if (vec[0] != vec[1]) {
      ans++;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1, test = 0;
  while (t--) {
    solve();
  }
}
