#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
struct data {
  int id, type, key;
  bool operator<(const data &X) const { return (key < X.key); }
} b[N * 2];
int a[N], n, cnt, t[N * 4];
map<int, int> ma, mb;
void update(int l, int r, int id, int u) {
  if (l == r) {
    ++t[id];
    return;
  }
  int mid = (r + l) >> 1;
  if (u <= mid)
    update(l, mid, id * 2, u);
  else
    update(mid + 1, r, id * 2 + 1, u);
  t[id] = t[id * 2] + t[id * 2 + 1];
}
int get(int l, int r, int id, int u, int v) {
  if (r < u || v < l) return 0;
  if (u <= l && r <= v) return t[id];
  int mid = (r + l) >> 1;
  return get(l, mid, id * 2, u, v) + get(mid + 1, r, id * 2 + 1, u, v);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen(".inp", "r")) freopen(".inp", "r", stdin);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ++ma[a[i]];
    b[++cnt] = {i, 0, ma[a[i]]};
  }
  for (int i = n; i; --i) {
    ++mb[a[i]];
    b[++cnt] = {i, 1, mb[a[i]]};
  }
  sort(b + 1, b + cnt + 1);
  int ptr = 1;
  long long ans = 0;
  while (ptr <= cnt) {
    int j = ptr;
    for (; j + 1 <= cnt && b[j + 1].key == b[ptr].key; ++j)
      ;
    for (int i = ptr; i <= j; ++i) {
      if (!b[i].type) {
        if (b[i].id < n) ans += get(1, n, 1, b[i].id + 1, n);
      }
    }
    for (int i = ptr; i <= j; ++i) {
      int type = b[i].type;
      if (type) {
        update(1, n, 1, b[i].id);
      }
    }
    ptr = j + 1;
  }
  cout << ans;
  return 0;
}
