#include <bits/stdc++.h>
using namespace std;
struct FenwickTree {
  vector<int> tree;
  FenwickTree(int n) : tree(n + 1, 0) {}
  void add(int index, int value) {
    for (int i = index; i < tree.size(); i += (i & -i)) {
      tree[i] += value;
    }
  }
  int sum(int index) {
    int out = 0;
    for (int i = index - 1; i > 0; i -= (i & -i)) {
      out += tree[i];
    }
    return out;
  }
  int sum(int l, int r) { return sum(r) - sum(l); }
};
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  vector<int> left_query(n);
  map<int, int> left_counts;
  for (int i = 0; i < n; i++) {
    left_counts[a[i]]++;
    left_query[i] = left_counts[a[i]];
  }
  vector<int> right_query(n);
  map<int, int> right_counts;
  for (int i = n - 1; i >= 0; i--) {
    right_counts[a[i]]++;
    right_query[i] = right_counts[a[i]];
  }
  FenwickTree fenwickTree(n);
  long long out = 0;
  for (int i = n - 1; i >= 0; i--) {
    out += fenwickTree.sum(left_query[i]);
    fenwickTree.add(right_query[i], 1);
  }
  cout << out;
}
