#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
const long long int MOD = 1e9 + 696969;
const long long INF = 1e18 + 3;
const int maxn = 1000100;
int fi[maxn], la[maxn];
int tab[maxn], pref[maxn];
int n;
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
  };
  cin >> n;
  long long int res = 0;
  for (int i = (1); i <= (n); ++i) {
    pref[i] = pref[i - 1];
    cin >> tab[i];
    if (fi[tab[i]] == 0) fi[tab[i]] = i, pref[i]++;
    la[tab[i]] = i;
  }
  for (int i = (1); i <= (n); ++i) {
    if (la[tab[i]] == i) res += pref[i - 1];
  }
  cout << res;
}
