#include <bits/stdc++.h>
using namespace std;
long long BIT[1000003];
unordered_map<long long, long long> cnt;
long long a[1000003];
long long backwards[1000003];
unordered_map<long long, long long> two;
long long s, i, n;
long long sum(long long k) {
  k++;
  if (k < 1) return 0;
  long long s = 0;
  while (k >= 1) {
    s += BIT[k - 1];
    k -= k & (-k);
  }
  return s;
}
void add(long long k, long long x) {
  k++;
  while (k <= 1000001) {
    BIT[k - 1] += x;
    k += k & (-k);
  }
}
int main() {
  scanf("%I64d", &n);
  for (i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
    backwards[i] = a[i];
  }
  for (i = 0; i <= 1000001; i++) {
    BIT[i] = 0;
  }
  for (i = n - 1; i >= 0; i--) {
    if (two.find(a[i]) == two.end()) {
      two[a[i]] = 0;
    }
    two[a[i]]++;
    backwards[i] = two[a[i]];
  }
  s = 0;
  if (cnt.find(a[0]) == cnt.end()) {
    cnt[a[0]] = 0;
  }
  cnt[a[0]]++;
  add(cnt[a[0]], 1);
  for (i = 1; i < n; i++) {
    s += sum(1000001) - sum(backwards[i]);
    if (cnt.find(a[i]) == cnt.end()) {
      cnt[a[i]] = 0;
    }
    cnt[a[i]]++;
    add(cnt[a[i]], 1);
  }
  printf("%I64d\n", s);
  return 0;
}
