#include <bits/stdc++.h>
using namespace std;
int arr[1000000 + 10], tree[1000000 + 10], n;
map<int, int> cnt, knt;
void update(int idx, int val) {
  for (; idx <= n; idx += (idx & -idx)) tree[idx] += val;
}
long long query(int idx) {
  long long val = 0;
  for (; idx > 0; idx -= (idx & -idx)) val += tree[idx];
  return val;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  for (int i = n; i >= 1; i--) {
    int k = ++cnt[arr[i]];
    update(k, 1);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int k = cnt[arr[i]]--;
    update(k, -1);
    k = ++knt[arr[i]];
    ans += query(k - 1);
  }
  cout << ans << endl;
  return 0;
}
