#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 5;
int n;
long long int a[MAX], BIT[MAX];
void update(int idx, long long int val) {
  for (; idx <= n; idx += (idx & (-idx))) {
    BIT[idx] += val;
  }
}
long long int sum(int idx) {
  idx--;
  long long int sumi = 0;
  for (; idx > 0; idx -= (idx & (-idx))) {
    sumi += BIT[idx];
  }
  return sumi;
}
int main() {
  scanf("%d", &n);
  int l[n], r[n];
  map<long long int, int> make_pair;
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
    make_pair[a[i]]++;
    l[i] = make_pair[a[i]];
  }
  make_pair.clear();
  for (int i = n - 1; i >= 0; i--) {
    make_pair[a[i]]++;
    r[i] = make_pair[a[i]];
  }
  long long int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans += sum(l[i]);
    update(r[i], 1);
  }
  cout << ans << endl;
  return 0;
}
