#include <bits/stdc++.h>
template <class T>
struct fenwick_tree {
  std::vector<T> x;
  fenwick_tree(size_t n) : x(n + 1) {}
  fenwick_tree(size_t n, T a) : x(n + 1, a) {
    x[0] = 0;
    for (int k = 1; k + (k & -k) <= n; ++k) x[k + (k & -k)] += x[k];
  }
  fenwick_tree(std::vector<T> y) : x(y.size() + 1) {
    for (int k = 0; k < y.size(); ++k) x[k + 1] = y[k];
    for (int k = 1; k + (k & -k) < x.size(); ++k) x[k + (k & -k)] += x[k];
  }
  void add(int k, T a) {
    for (++k; k < x.size(); k += k & -k) x[k] += a;
  }
  T sum(int k) {
    T s = 0;
    for (++k; k > 0; k &= k - 1) s += x[k];
    return s;
  }
  int lower_bound(T a) {
    if (a <= 0) return 0;
    int k = x.size() - 1;
    for (int s : {1, 2, 4, 8, 16}) k |= (k >> s);
    for (int p = ++k; p > 0; p >>= 1, k |= p)
      if (k < x.size() && x[k] < a)
        a -= x[k];
      else
        k ^= p;
    return k + 1;
  }
  int upper_bound(T a) {
    int k = x.size() - 1;
    for (int s : {1, 2, 4, 8, 16}) k |= (k >> s);
    for (int p = ++k; p > 0; p >>= 1, k |= p)
      if (k < x.size() && x[k] <= a)
        a -= x[k];
      else
        k ^= p;
    return k;
  }
};
using namespace std;
template <typename T>
vector<T> get_input_sequence(size_t n) {
  vector<T> sequence(n);
  for (size_t i = 0; i < n; ++i) cin >> sequence[i];
  return sequence;
}
template <typename T>
void remap(vector<T>& a) {
  vector<T> tmp(a.size());
  copy(a.begin(), a.end(), tmp.begin());
  sort(tmp.begin(), tmp.end());
  size_t sz = distance(tmp.begin(), unique(tmp.begin(), tmp.end()));
  tmp.resize(sz);
  for (auto& x : a)
    x = distance(tmp.begin(), lower_bound(tmp.begin(), tmp.end(), x));
}
int main() {
  size_t n;
  cin >> n;
  auto a = get_input_sequence<int>(n);
  remap<int>(a);
  fenwick_tree<int> f(n);
  vector<int> suffix_counter(n);
  vector<int> counter(n);
  for (int i = n - 1; i >= 0; --i) {
    counter[a[i]]++;
    suffix_counter[i] = counter[a[i]];
    f.add(counter[a[i]], 1);
  }
  fill(counter.begin(), counter.end(), 0);
  uint64_t res = 0;
  for (int i = 0; i < n; ++i) {
    f.add(suffix_counter[i], -1);
    counter[a[i]]++;
    res += f.sum(counter[a[i]] - 1);
  }
  cout << res << endl;
  return 0;
}
