#include <bits/stdc++.h>
using namespace std;
pair<long long int, pair<long long int, long long int>> arr[3000000];
long long int c_f[1000000];
long long int tree[3000000];
map<long long int, unsigned long long int> freq;
long long int buildTree(long long int node, long long int s, long long int e) {
  if (s > e) return 0;
  long long int mid = (s + e) / 2;
  if (s == e)
    tree[node] = c_f[s];
  else
    tree[node] =
        buildTree(2 * node, s, mid) + buildTree(2 * node + 1, mid + 1, e);
  return tree[node];
}
void updateTree(long long int node, long long int s, long long int e,
                long long int index) {
  if (s > e) return;
  if (index >= s && index <= e) {
    tree[node]--;
    if (s < e) {
      long long int mid = (s + e) / 2;
      if (index <= mid)
        updateTree(2 * node, s, mid, index);
      else
        updateTree(2 * node + 1, mid + 1, e, index);
    }
  }
  return;
}
long long int queryTree(long long int node, long long int s, long long int e,
                        long long int l, long long int r) {
  if (s > e) return 0;
  if (r < s || l > e) return 0;
  if (s == e) return tree[node];
  if (s >= l && e <= r) return tree[node];
  long long int mid = (s + e) / 2;
  return queryTree(2 * node, s, mid, l, r) +
         queryTree(2 * node + 1, mid + 1, e, l, r);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  scanf("%lld", &n);
  for (long long int i = 0; i < n; i++) scanf("%lld", &arr[i].first);
  freq.clear();
  for (long long int i = 0; i < n; i++) {
    freq[arr[i].first]++;
    arr[i].second.first = freq[arr[i].first];
  }
  freq.clear();
  for (long long int i = 0; i < 1000001; i++) c_f[i] = 0;
  for (long long int i = n - 1; i >= 0; i--) {
    freq[arr[i].first]++;
    c_f[freq[arr[i].first]]++;
    arr[i].second.second = freq[arr[i].first];
  }
  buildTree(1, 0, 1000000);
  long long int r = n - 1, count = 0;
  for (long long int l = 0; l < n - 1; l++) {
    updateTree(1, 0, 1000000, arr[l].second.second);
    count += queryTree(1, 0, 1000000, 0, arr[l].second.first - 1);
  }
  cout << count << endl;
  return 0;
}
