#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000 + 10;
map<int, int> cnt;
int n;
int a[MAXN], fen[MAXN], ad[MAXN], rem[MAXN];
int get(int idx) {
  int ans = 0;
  for (int i = idx; i > 0; i -= (i & -i)) ans += fen[i];
  return ans;
}
int sum(int a, int b) { return get(b) - get(a); }
void add(int idx, int val) {
  for (int i = idx + 1; i < MAXN; i += (i & -i)) fen[i] += val;
}
int main() {
  long long ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cnt.clear();
  for (int i = n - 1; i >= 0; i--) {
    int v = ++cnt[a[i]];
    add(v, 1);
    rem[i] = v;
  }
  for (int i = 0; i < n; i++) ad[i] = cnt[a[i]] - rem[i] + 1;
  cnt.clear();
  for (int i = 0; i < n; i++) {
    add(rem[i], -1);
    ans += sum(1, ad[i]);
  }
  cout << ans;
}
