#include <bits/stdc++.h>
using namespace std;
const int __n = 1e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
template <typename tp>
inline void in(tp &__ult) {
  tp x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48, ch = getchar();
  }
  __ult = x * f;
}
int n;
int lowbit(int x) { return (x) & (-x); }
int tree[__n] = {0};
void updata(int x, int val) {
  for (int i = x; i <= n; i += lowbit(i)) {
    tree[i] += val;
  }
}
int getsum(int x) {
  int ans = 0;
  for (int i = x; i; i -= lowbit(i)) {
    ans += tree[i];
  }
  return ans;
}
int main() {
  int a[__n];
  in(n);
  for (int i = 1; i <= n; i++) {
    in(a[i]);
  }
  bool vis[__n];
  memset((vis), (0), sizeof((vis)));
  for (int i = 1; i <= n; i++) {
    if (!vis[a[i]]) {
      updata(i, 1);
      vis[a[i]] = 1;
    }
  }
  memset((vis), (0), sizeof((vis)));
  long long ans = 0;
  for (int i = n; i >= 1; i--) {
    if (!vis[a[i]]) {
      ans += (long long)getsum(i - 1);
      vis[a[i]] = 1;
    }
  }
  printf("%lld", ans);
}
