#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 6, MOD = 1e9 + 7, lg = 23;
int n, arr[maxN];
int mini[maxN];
bool v[maxN];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < maxN; i++) {
    mini[i] = INT_MAX;
  }
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (mini[arr[i]] == INT_MAX) mini[arr[i]] = i;
  }
  long long ans = 0, ct = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (i == mini[arr[i]]) {
      ans += ct;
    }
    if (!v[arr[i]]) ct++, v[arr[i]] = 1;
  }
  cout << ans << '\n';
}
