#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
map<int, int>::iterator it;
int a1[1000000], a2[1000000], st[1000001];
int main() {
  int n;
  long long o = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a1 + i);
    a2[i] = ++m[a1[i]];
  }
  for (int i = 0; i < n; ++i) {
    o += i;
    for (int j = m[a1[i]] - a2[i] + 1; j; j -= j & (-j)) o -= st[j];
    for (int j = a2[i]; j < 1000001; j += j & (-j)) ++st[j];
  }
  printf("%I64d\n", o);
}
