#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;
queue<int> q;
deque<int> dq;
int vec[100000];
int lcnt[100001];
int rcnt[100001];
int main() {
  int n;
  scanf("%d", &n);
  long long cnt = 0;
  long long now = 0;
  for (int i = 0; i < n; i++) scanf("%d", &vec[i]);
  for (int j = 0; j < n; j++) {
    if (rcnt[vec[j]]) now++;
    rcnt[vec[j]]++;
  }
  for (int i = 0; i < n; i++) {
    rcnt[vec[i]]--;
    if (rcnt[vec[i]] >= 1) now--;
    if (lcnt[vec[i]]) continue;
    lcnt[vec[i]]++;
    cnt += ((n - i - 1) - now);
  }
  printf("%lld", cnt);
}
