#include <bits/stdc++.h>
template <class T>
struct fenwick_tree {
  std::vector<T> A;
  fenwick_tree(int64_t N) : A(N) {}
  void add(int64_t i, T v) {
    for (i++; i <= A.size(); i += i & -i) A[i - 1] += v;
  }
  T sum(int64_t r) {
    T s{};
    for (r++; r > 0; r -= r & -r) s += A[r - 1];
    return s;
  }
  T sum(int64_t l, int64_t r) { return sum(r) - sum(l - 1); }
};
void remap(std::vector<int> &A) {
  std::unordered_map<int, int> map;
  std::vector<int> B;
  B.reserve(A.size());
  for (int i = 0; i < A.size(); i++) {
    B.push_back(A[i]);
  }
  std::sort(B.begin(), B.end());
  int curr_value = B[0];
  int curr_count = 0;
  map.insert({curr_value, curr_count++});
  for (size_t i = 1; i < B.size(); i++) {
    if (B[i] != curr_value) {
      curr_value = B[i];
      map.insert({curr_value, curr_count++});
    }
  }
  for (size_t i = 0; i < A.size(); i++) {
    A[i] = map[A[i]];
  }
}
int max_repetitions(std::vector<int> A) {
  std::sort(A.begin(), A.end());
  int max_repts = 0;
  int curr_value = A[0];
  int curr_rept = 1;
  for (int i = 1; i < A.size(); i++) {
    if (A[i] == curr_value) {
      curr_rept++;
    } else {
      curr_value = A[i];
      curr_rept = 1;
    }
    max_repts = std::max(max_repts, curr_rept);
  }
  return max_repts;
}
struct S {
  int k;
  int v;
  S operator-(const S &rhs) const { return {k - rhs.k, v - rhs.v}; }
  void operator+=(const S &rhs) {
    k += rhs.k;
    v += rhs.v;
  }
};
void solve(std::vector<int> &line) {
  remap(line);
  int max_value = 0;
  for (int e : line) max_value = std::max(max_value, e);
  std::vector<int> L(max_value + 1, 0);
  std::vector<int> R(max_value + 1, 0);
  for (auto &e : line) R[e]++;
  int max_repts = max_repetitions(line);
  fenwick_tree<S> ft(max_repts + 1);
  for (int i = 0; i < R.size(); i++) ft.add(R[i], {1, R[i]});
  int64_t counter = 0;
  for (int i = 0; i < line.size() - 1; i++) {
    int l = ++L[line[i]];
    int &r = R[line[i]];
    ft.add(r, {-1, -r});
    r--;
    ft.add(r, {+1, +r});
    counter += ft.sum(1, l - 1).v + ft.sum(l, max_repts).k * (l - 1);
  }
  printf("%lld\n", counter);
}
int main() {
  int N;
  scanf("%d", &N);
  std::vector<int> line;
  line.reserve(N);
  for (int i = 0; i < N; i++) {
    int value;
    scanf("%d", &value);
    line.push_back(value);
  }
  solve(line);
  return 0;
}
