#include <bits/stdc++.h>
using namespace std;
struct A {
  int loc, num;
} arr[1000005];
int a[1000005];
bool cmp(A a, A b) { return a.num < b.num; }
int ct1[1000005], n, ct2[1000005], c[1000005];
void updata(int x, int val) {
  int i;
  for (i = x; i <= n; i += (i) & (-i)) {
    c[i] += val;
  }
}
int getsum(int x) {
  int i, ans = 0;
  for (i = x; i > 0; i -= (i) & (-i)) {
    ans += c[i];
  }
  return ans;
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", a + i), arr[i].loc = i, arr[i].num = a[i];
  sort(arr + 1, arr + n + 1, cmp);
  int tmp = -1, number = 0;
  for (i = 1; i <= n; i++) {
    if (arr[i].num != tmp) {
      number++;
      tmp = arr[i].num;
    }
    a[arr[i].loc] = number;
  }
  for (i = 1; i < n; i++) {
    ct1[a[i]]++;
  }
  long long ans = 0;
  for (i = n - 1; i >= 1; i--) {
    updata(++ct2[a[i + 1]], 1);
    ans += getsum(--ct1[a[i]]);
  }
  printf("%I64d\n", ans);
  return 0;
}
