#include <bits/stdc++.h>
using namespace std;
void build(unsigned int *A, vector<unsigned int> tree[], unsigned int index,
           unsigned int s, unsigned int e) {
  if (s == e)
    tree[index].push_back(A[s]);
  else {
    unsigned int mid = (s + e) / 2;
    build(A, tree, 2 * index, s, mid);
    build(A, tree, 2 * index + 1, mid + 1, e);
    unsigned int l = 0;
    while (l != tree[2 * index].size())
      tree[index].push_back(tree[2 * index][l++]);
    l = 0;
    while (l != tree[2 * index + 1].size())
      tree[index].push_back(tree[2 * index + 1][l++]);
    sort(tree[index].begin(), tree[index].end());
  }
}
unsigned int query(vector<unsigned int> tree[], unsigned int index,
                   unsigned int s, unsigned int e, unsigned int l,
                   unsigned int r, unsigned int val) {
  if (r < s || e < l)
    return 0;
  else if (l <= s && e <= r) {
    unsigned int pos =
        lower_bound(tree[index].begin(), tree[index].end(), val) -
        tree[index].begin();
    return pos;
  } else {
    unsigned int mid = (s + e) / 2;
    unsigned int left = query(tree, 2 * index, s, mid, l, r, val);
    unsigned int right = query(tree, 2 * index + 1, mid + 1, e, l, r, val);
    return left + right;
  }
}
void solve(unsigned int *C, unsigned int *D, unsigned int n) {
  unsigned int l, r, val;
  vector<unsigned int> tree[4 * n + 1];
  build(D, tree, 1, 1, n);
  long long int s = 0;
  for (unsigned int i = 1; i < n; i++)
    s += query(tree, 1, 1, n, i + 1, n, C[i]);
  cout << s << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  unsigned int n;
  cin >> n;
  unsigned int A[n + 1];
  unsigned int y;
  map<unsigned int, unsigned int> m;
  unsigned int C[n + 1], D[n + 1];
  for (unsigned int i = 1; i <= n; i++) {
    cin >> A[i];
    auto it = m.find(A[i]);
    if (it != m.end()) {
      y = it->second;
      y++;
      m.erase(it);
      m.insert(make_pair(A[i], y));
    } else {
      y = 1;
      m.insert(make_pair(A[i], y));
    }
    C[i] = y;
  }
  for (unsigned int i = 1; i <= n; i++) D[i] = m.find(A[i])->second - C[i] + 1;
  solve(C, D, n);
}
