#include <bits/stdc++.h>
using namespace std;
map<int, int> cnt;
map<int, int>::iterator it;
int arr[1000010];
int front[1000010];
int back[1000010];
int tree[1000010 * 4];
void merge(int node) { tree[node] = tree[2 * node] + tree[2 * node + 1]; }
void update(int node, int s, int e, int k) {
  if (s == e) {
    tree[node]++;
    return;
  }
  int mid = (s + (e - s) / 2);
  if (k <= mid)
    update(node * 2, s, mid, k);
  else
    update(node * 2 + 1, mid + 1, e, k);
  merge(node);
}
long long query(int node, int s, int e, int L, int R) {
  if (L <= s && e <= R) {
    return (long long)tree[node];
  }
  int mid = (s + (e - s) / 2);
  if (R <= mid)
    return query(2 * node, s, mid, L, R);
  else if (L > mid)
    return query(2 * node + 1, mid + 1, e, L, R);
  else
    return query(2 * node, s, mid, L, R) +
           query(2 * node + 1, mid + 1, e, L, R);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  memset(front, 0, sizeof(front));
  memset(back, 0, sizeof(back));
  memset(tree, 0, sizeof(tree));
  cnt.clear();
  for (int i = 1; i <= n; i++) {
    front[i] = ++cnt[arr[i]];
  }
  cnt.clear();
  for (int i = n; i >= 1; i--) {
    back[i] = ++cnt[arr[i]];
  }
  long long ans = 0;
  for (int i = n; i >= 1; i--) {
    if (front[i] >= 2) ans += query(1, 1, n, 1, front[i] - 1);
    update(1, 1, n, back[i]);
  }
  printf("%lld\n", ans);
  return 0;
}
