#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const string nl = "\n";
template <class T>
struct fenwick {
  long long n;
  vector<T> tree;
  fenwick(const long long _n) {
    n = _n;
    tree.assign(n + 2, 0LL);
  }
  void add(long long pos, T dif) {
    ++pos;
    for (long long i = pos; i <= n; i += (i & -i)) {
      tree[i] += dif;
    }
  }
  void set(long long pos, T val) { add(pos, val - query(pos, pos)); }
  T query(long long l) {
    ++l;
    T sum = 0;
    for (long long i = l; i > 0; i -= (i & -i)) {
      sum += tree[i];
    }
    return sum;
  }
  T query(long long l, long long r) { return query(r) - query(l - 1); }
};
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (auto& i : a) {
    cin >> i;
  }
  vector<long long> b = a;
  sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  for (long long i = 0; i < n; ++i) {
    a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
  }
  map<long long, long long> cnt;
  vector<long long> hld, hld1;
  for (long long i = 0; i < n; ++i) {
    hld.push_back(++cnt[a[i]]);
  }
  reverse(a.begin(), a.end());
  cnt.clear();
  for (long long i = 0; i < n; ++i) {
    hld1.push_back(++cnt[a[i]]);
  }
  reverse(a.begin(), a.end());
  fenwick<long long> ft((long long)1e6 + 100);
  long long ans = 0;
  for (long long i = n - 2; i >= 0; --i) {
    ft.add(hld1[n - i - 2], 1);
    ans += ft.query(hld[i] - 1);
  }
  cout << ans << nl;
}
