#include <bits/stdc++.h>
using namespace std;
int visit[100001];
int main() {
  int N;
  scanf("%d", &N);
  vector<long long> arr(N);
  vector<long long> left(N);
  vector<long long> right(N);
  long long temp = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d", &arr[i]);
    if (visit[arr[i]] == 1) continue;
    temp++;
    left[i] = temp;
    visit[arr[i]] = 1;
  }
  temp = 0;
  memset(visit, 0, sizeof(visit));
  for (int i = N - 1; i >= 0; i--) {
    if (visit[arr[i]] == 1) {
      right[i] = temp;
      continue;
    }
    visit[arr[i]] = 1;
    temp++;
    right[i] = temp;
  }
  memset(visit, 0, sizeof(visit));
  temp = 0;
  for (int i = 0; i < N - 1; i++) {
    if (visit[arr[i]] == 1) continue;
    visit[arr[i]] = 1;
    temp += right[i + 1];
  }
  cout << temp;
}
