#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a;
int order[1000005];
int total[1000005];
int tree[1000005];
int arr[1000005];
int n;
int read(int idx) {
  int sum = 0;
  while (idx > 0) {
    sum += tree[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
void update(int idx, int val) {
  while (idx <= n) {
    tree[idx] += val;
    idx += (idx & -idx);
  }
}
int hashe[1000005];
int main() {
  cin >> n;
  int b;
  for (int i = 0; i < n; i++) {
    scanf("%d", &b);
    a.push_back(make_pair(b, i));
  }
  sort(a.begin(), a.end());
  int count = 1, prev;
  order[1]++;
  vector<pair<int, int> >::iterator it;
  it = a.begin();
  arr[it->second] = 1;
  prev = it->first;
  it++;
  for (; it != a.end(); it++) {
    if (it->first == prev) {
      arr[it->second] = count;
    } else {
      count++;
      arr[it->second] = count;
    }
    prev = it->first;
    order[count]++;
  }
  order[0] = 0;
  for (int i = 1; i <= n; i++) {
    total[order[i]]++;
  }
  for (int i = n - 1; i >= 1; i--) total[i] += total[i + 1];
  for (int i = 1; i <= n; i++) update(i, total[i]);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    hashe[arr[i]]++;
    update(order[arr[i]], -1);
    ans += read(hashe[arr[i]] - 1);
    order[arr[i]]--;
  }
  cout << ans;
  return 0;
}
