#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
long long tree_sum[3 * MAX];
void update(int node, int lower, int upper, int pos) {
  if (pos < lower || pos > upper) return;
  if (lower == upper) {
    tree_sum[node]++;
    return;
  }
  int mid = (lower + upper) >> 1;
  update((2 * node), lower, mid, pos);
  update((2 * node + 1), mid + 1, upper, pos);
  tree_sum[node] = tree_sum[(2 * node)] + tree_sum[(2 * node + 1)];
}
long long getans(int node, int lower, int upper, int l, int r) {
  if (r < lower || l > upper) return 0;
  if (l <= lower && upper <= r) return tree_sum[node];
  int mid = (lower + upper) >> 1;
  long long temp = getans((2 * node), lower, mid, l, r);
  temp += getans((2 * node + 1), mid + 1, upper, l, r);
  return temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  int arrlen;
  cin >> arrlen;
  vector<int> arr(arrlen + 1);
  for (int i = 0; i < arrlen; i++) cin >> arr[i];
  map<int, int> left_f;
  vector<int> left(arrlen + 1, 0);
  for (int i = 0; i < arrlen; i++) {
    left_f[arr[i]]++;
    left[i] = left_f[arr[i]];
  }
  map<int, int> right_f;
  vector<int> right(arrlen + 1, 0);
  for (int i = arrlen - 1; i >= 0; i--) {
    right_f[arr[i]]++;
    right[i] = right_f[arr[i]];
  }
  long long ans = 0;
  for (int i = arrlen - 1; i >= 0; i--) {
    ans += getans(1, 1, arrlen, 1, left[i] - 1);
    update(1, 1, arrlen, right[i]);
  }
  cout << ans << "\n";
}
