#include <bits/stdc++.h>
using namespace std;
struct node {
  int n, p;
} a[1200000], f[1200000], g[1200000];
long long ans;
int n, cnt, s[8200000];
bool cmp(node a, node b) { return (a.n < b.n) || (a.n == b.n && a.p < b.p); }
void ins(int p, int l, int r, int a) {
  s[p]++;
  if (l == r) return;
  int m = (l + r) / 2;
  if (a <= m)
    ins(p * 2, l, m, a);
  else
    ins(p * 2 + 1, m + 1, r, a);
}
int ask(int p, int l, int r, int a, int b) {
  if (l == a && r == b) return s[p];
  int m = (l + r) / 2;
  if (b <= m) return ask(p * 2, l, m, a, b);
  if (a > m) return ask(p * 2 + 1, m + 1, r, a, b);
  return ask(p * 2, l, m, a, m) + ask(p * 2 + 1, m + 1, r, m + 1, b);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].n);
    a[i].p = i;
  }
  sort(a + 1, a + n + 1, cmp);
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i].n == a[i - 1].n)
      cnt++;
    else
      cnt = 1;
    f[a[i].p].n = cnt;
    f[i].p = i;
  }
  cnt = 0;
  for (int i = n; i >= 1; i--) {
    if (a[i].n == a[i + 1].n)
      cnt++;
    else
      cnt = 1;
    g[a[i].p].n = cnt;
    g[i].p = i;
  }
  sort(f + 1, f + n + 1, cmp);
  sort(g + 1, g + n + 1, cmp);
  int j = 1;
  for (int i = 1; i <= n; i++) {
    if (f[i].p == n) continue;
    while (j <= n && g[j].n < f[i].n) {
      ins(1, 1, n, g[j].p);
      j++;
    }
    ans += ask(1, 1, n, f[i].p + 1, n);
  }
  cout << ans;
}
