#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e18;
const long long int mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  long long int t, n, i, sum = 0, p, l;
  cin >> n;
  set<long long int> st;
  map<long long int, long long int> mp, mp1;
  vector<long long int> v;
  map<long long int, long long int> prev, cnt;
  for (long long int i = 0; i < n; i++) {
    cin >> p;
    v.push_back(p);
    mp[p] = mp1[p] = 0;
    cnt[p] = -1;
  }
  sum += ((n - 1) * n) / 2;
  for (long long int i = 0; i < n; i++) {
    if (mp[v[i]] > 0) {
      sum -= (n - (i + 1));
    }
    mp[v[i]]++;
  }
  long long int arr[n];
  for (long long int i = 0; i < n; i++) {
    arr[i] = st.size();
    st.insert(v[i]);
  }
  for (long long int i = 0; i < n; i++) {
    if (mp1[v[i]] > 0) {
      sum -= arr[prev[v[i]]];
      prev[v[i]] = i;
      mp1[v[i]]++;
    }
    mp1[v[i]]++;
    prev[v[i]] = i;
  }
  cout << sum << endl;
}
