#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e6 + 10;
map<int, int> m, m1;
int n, fen[max_n];
int a[max_n], af[max_n], bf[max_n];
void update(int p, long long int val) {
  for (int i = p; i <= n; i += i & -i) fen[i] += val;
}
int sum(int p) {
  int ans = 0;
  for (int i = p; i; i -= i & -i) ans += fen[i];
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = (int)0; i < (int)n; ++i) {
    scanf("%d", &a[i]);
    m[a[i]]++;
    bf[i] = m[a[i]];
  }
  for (int i = (int)n - 1; i >= (int)0; --i) {
    m1[a[i]]++;
    af[i] = m1[a[i]];
  }
  long long int k = 0;
  for (int i = (int)n - 1; i >= (int)0; --i) {
    k += 1ll * sum(bf[i]);
    update(af[i] + 1, 1);
  }
  printf("%I64d\n", k);
  return 0;
}
