#include <bits/stdc++.h>
using namespace std;
int n, a[1000006], s[1000006], p[1000006], f[1000006], aib[1000006];
long long int rez = 0;
vector<int> v;
void normalizare() {
  int i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  unique(v.begin(), v.end());
  for (i = 1; i <= n; i++)
    a[i] =
        abs(std::distance(lower_bound(v.begin(), v.end(), a[i]), v.begin())) +
        1;
}
long long query(int x) {
  long long sum = 0;
  while (x) {
    sum += aib[x];
    x = (x & (x - 1));
  }
  return sum;
}
void update(int x) {
  while (x <= n) {
    aib[x]++;
    x = 2 * x - (x & (x - 1));
  }
}
void solutie() {
  int i;
  for (i = 1; i <= n; i++) {
    f[a[i]]++;
    s[i] = f[a[i]];
  }
  memset(f, 0, sizeof(f));
  for (i = n; i >= 1; i--) {
    f[a[i]]++;
    p[i] = f[a[i]];
  }
  for (i = n; i >= 1; i--) {
    rez += query(s[i] - 1);
    update(p[i]);
  }
  cout << rez;
}
int main() {
  normalizare();
  solutie();
  return 0;
}
