#include <bits/stdc++.h>
using namespace std;
long long n, a[1000005], init[1000005], val[1000005], cnt[1000005];
long long fen[1000005];
void add(long long x, long long val) {
  for (long long i = x + 1; i < 1000005; i += i & (-i)) fen[i] += val;
}
long long get(long long x) {
  long long ans = 0;
  for (long long i = x; i > 0; i -= i & (-i)) ans += fen[i];
  return ans;
}
long long sum(long long x, long long y) { return get(y) - get(x); }
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i], init[i] = a[i];
  sort(init, init + n);
  long long m = unique(init, init + n) - init;
  for (long long i = 0; i < n; i++)
    a[i] = lower_bound(init, init + m, a[i]) - init;
  for (long long i = n - 1; i >= 0; i--) {
    cnt[a[i]]++;
    add(cnt[a[i]], 1);
    val[i] = cnt[a[i]];
  }
  long long ans = 0;
  memset(cnt, 0, sizeof(cnt));
  for (long long i = 0; i < n; i++) {
    add(val[i], -1);
    cnt[a[i]]++;
    ans += sum(1, cnt[a[i]]);
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
