#include <bits/stdc++.h>
using namespace std;
class SegTree {
 private:
  vector<int> segt, a;
  int n;
  int left(int si) { return si * 2; }
  int right(int si) { return si * 2 + 1; }
  int getMid(int ss, int se) { return (ss + (se - ss) / 2); }
  void build(int ss, int se, int si) {
    if (ss == se) {
      segt[si] = a[ss];
      return;
    }
    int mid = getMid(ss, se);
    build(ss, mid, left(si));
    build(mid + 1, se, right(si));
    segt[si] = segt[left(si)] + segt[right(si)];
  }
  int query(int ss, int se, int qs, int qe, int si) {
    if (se < qs || qe < ss) return 0;
    if (qs <= ss && qe >= se) return segt[si];
    int mid = getMid(ss, se);
    return query(ss, mid, qs, qe, left(si)) +
           query(mid + 1, se, qs, qe, right(si));
  }
  void update(int ss, int se, int key, int si) {
    if (ss == se) {
      segt[si] = a[ss];
      return;
    }
    int mid = getMid(ss, se);
    if (key > mid)
      update(mid + 1, se, key, right(si));
    else
      update(ss, mid, key, left(si));
    segt[si] = segt[left(si)] + segt[right(si)];
  }

 public:
  SegTree(int sz) {
    a.resize(sz + 5);
    segt.resize(sz * 4 + 5);
  }
  void init(int n) {
    this->n = n;
    for (int i = 0; i <= n; i++) a[i] = 0;
    build(0, n, 1);
  }
  int get(int qs, int qe) { return query(0, n, qs, qe, 1); }
  void set(int key, int val) {
    a[key] += val;
    update(0, n, key, 1);
  }
};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  vector<int> a(n), suff(n);
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  SegTree st(1e6 + 6);
  st.init(n);
  for (int i = n - 1; i >= 0; i--) {
    suff[i] = ++mp[a[i]];
    st.set(suff[i], 1);
  }
  mp.clear();
  for (int i = 0; i < n; i++) {
    st.set(suff[i], -1);
    mp[a[i]]++;
    cnt += st.get(1, mp[a[i]] - 1);
  }
  cout << cnt << "\n";
  return 0;
}
