#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int sz = 3e5 + 10;
const int inf = 1 << 12;
int n;
int ar[sz];
set<int> st;
int br[sz];
ll ans, cnt;
map<int, int> mp;
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    st.clear();
    br[n] = 0;
    for (int i = n - 1; i >= 0; i--) {
      st.insert(ar[i]);
      br[i] = (int)st.size();
    }
    mp.clear();
    ans = 0;
    for (int i = 0; i < n; i++) {
      mp[ar[i]]++;
      if (mp[ar[i]] == 1) ans += br[i + 1];
    }
    cout << ans << "\n";
    cerr << "-----\n";
  }
  return 0;
}
