#include <bits/stdc++.h>
using namespace std;
int vis[100005], ent[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, tk;
  cin >> n;
  set<int> num;
  int lst = 0;
  vector<int> vc;
  int un = 0;
  for (int i = 1; i <= n; i++) {
    cin >> tk;
    if (!vis[tk]) un++;
    vc.push_back(tk), vis[tk]++;
    ;
    lst = tk;
  }
  n = vc.size();
  long long cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (ent[vc[i - 1]]) {
      vis[vc[i - 1]]--;
      if (vis[vc[i - 1]] <= 0) un--;
      continue;
    }
    vis[vc[i - 1]]--;
    int res = un;
    if (vis[vc[i - 1]] < 1) res--;
    if (vis[vc[i - 1]] <= 0) un--;
    cnt += res;
    ent[vc[i - 1]] = 1;
  }
  cout << cnt;
}
