#include <bits/stdc++.h>
using namespace std;
int n;
long long solution;
int a[1000006], brPojava[1000006], brPojava2[1000006];
unordered_map<int, int> mapa;
int tree[1000006];
void update(int idx, int val) {
  while (idx <= n) {
    tree[idx] += val;
    idx += idx & (-idx);
  }
}
int read(int idx) {
  int ret = 0;
  while (idx > 0) {
    ret += tree[idx];
    idx -= idx & (-idx);
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int cur = 0;
  for (int i = 0; i < n; i++) {
    if (mapa.count(a[i]) == 0) mapa[a[i]] = cur++;
  }
  for (int i = 0; i < n - 1; i++) {
    brPojava2[mapa[a[i]]]++;
  }
  for (int i = n - 2; i >= 0; i--) {
    update(++brPojava[mapa[a[i + 1]]], 1);
    solution += (long long)read(brPojava2[mapa[a[i]]] - 1);
    brPojava2[mapa[a[i]]]--;
  }
  printf("%lld\n", solution);
  return 0;
}
