#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
  int sum;
} tree[1000006 << 2];
int a[1000006];
int pre[1000006], post[1000006];
map<int, int> m1, m2;
void build(int num, int l, int r) {
  tree[num].l = l;
  tree[num].r = r;
  tree[num].sum = 0;
  int mid = (l + r) >> 1;
  if (l == r) return;
  build(num << 1, l, mid);
  build(num << 1 | 1, mid + 1, r);
}
int query(int num, int l, int r) {
  if (tree[num].l == l && tree[num].r == r) {
    return tree[num].sum;
  }
  int mid = (tree[num].l + tree[num].r) >> 1;
  if (r <= mid) {
    return query(num << 1, l, r);
  } else if (l > mid) {
    return query(num << 1 | 1, l, r);
  } else {
    return query(num << 1, l, mid) + query(num << 1 | 1, mid + 1, r);
  }
}
void update(int num, int p) {
  if (tree[num].l == tree[num].r && tree[num].l == p) {
    tree[num].sum++;
    return;
  }
  int mid = (tree[num].l + tree[num].r) >> 1;
  if (p <= mid) {
    update(num << 1, p);
  } else {
    update(num << 1 | 1, p);
  }
  tree[num].sum = tree[num << 1].sum + tree[num << 1 | 1].sum;
}
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    m1[a[i]]++;
    pre[i] = m1[a[i]];
  }
  for (int i = n; i >= 1; i--) {
    m2[a[i]]++;
    post[i] = m2[a[i]];
  }
  build(1, 1, n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (post[i] != n) {
      ans += query(1, post[i] + 1, n);
    }
    update(1, pre[i]);
  }
  cout << ans << endl;
  return 0;
}
