#include <bits/stdc++.h>
using namespace std;
const long long Mx = 1e6 + 100;
long long bit[Mx];
void update(long long tt, long long val) {
  while (tt <= Mx) {
    bit[tt] += val;
    tt += tt & -tt;
  }
}
long long pref(long long tt) {
  long long ans = 0;
  while (tt > 0) {
    ans += bit[tt];
    tt -= tt & -tt;
  }
  return ans;
}
signed main() {
  long long n;
  scanf("%lld", &n);
  long long arr[n + 1];
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", arr + i);
  }
  long long frt[n + 1];
  long long bac[n + 1];
  map<long long, long long> fr, ba;
  for (long long i = 1; i <= n; i++) {
    fr[arr[i]] += 1;
    frt[i] = fr[arr[i]];
  }
  for (long long i = n; i >= 1; i--) {
    ba[arr[i]] += 1;
    bac[i] = ba[arr[i]];
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long a = frt[i];
    ans += pref(bac[i]);
    update(1, 1);
    update(a, -1);
  }
  printf("%lld\n", ans);
  return 0;
}
