#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1123456, OFFSET = 3;
struct BITree {
  int a[MAXN];
  void clear() { memset(a, 0, sizeof(a)); }
  int lowbit(int i) { return (i & -i); }
  int sum(int i) {
    int ret = 0;
    for (i += OFFSET; i > 0; i -= lowbit(i)) ret += a[i];
    return ret;
  }
  void add(int i, int d) {
    for (i += OFFSET; i < MAXN; i += lowbit(i)) a[i] += d;
  }
} bt;
int f[1123456], g[1123456], a[1123456];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < int(n); i++) scanf("%d", a + i);
  unordered_map<int, int> m;
  for (int i = 0; i < int(n); i++) f[i] = ++m[a[i]];
  m.clear();
  long long ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    ans += bt.sum(f[i] - 1);
    bt.add(++m[a[i]], 1);
  }
  cout << ans << endl;
}
