#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 9;
long long fen[maxn];
long long a[maxn];
long long N;
long long cnt[maxn];
long long fi[maxn];
long long fj[maxn];
long long tmp[maxn];
void add(long long x, long long dval) {
  while (x <= N) {
    fen[x] += dval;
    x += (x & (-x));
  }
}
long long sum(long long x) {
  long long ac = 0;
  while (x > 0) {
    ac += fen[x];
    x -= (x & (-x));
  }
  return ac;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> N;
  for (long long i = 1; i <= N; i++) cin >> a[i], tmp[i] = a[i];
  sort(tmp + 1, tmp + N + 1);
  for (long long i = 1; i <= N; i++)
    a[i] = lower_bound(tmp + 1, tmp + N + 1, a[i]) - tmp - 1;
  for (long long i = N; i >= 2; i--) {
    cnt[a[i]]++;
    fj[i] = cnt[a[i]];
    add(fj[i], 1);
  }
  long long ans = 0;
  memset(cnt, 0, sizeof(cnt));
  for (long long i = 1; i < N; i++) {
    cnt[a[i]]++;
    fi[i] = cnt[a[i]];
    ans += sum(fi[i] - 1);
    add(fj[i + 1], -1);
  }
  cout << ans << endl;
  return 0;
}
