#include <bits/stdc++.h>
using namespace std;
void update(vector<long long> &bit, long long i, long long n, long long val) {
  while (i <= n) bit[i] += val, i += (i & -i);
}
long long query(vector<long long> &bit, long long i) {
  long long sum = 0;
  while (i) sum += bit[i], i -= (i & -i);
  return sum;
}
void solve() {
  long long n, ans = 0, i;
  cin >> n;
  vector<long long> a(n), bit(n + 5);
  unordered_map<long long, long long> pr, sf;
  for (auto &i : a) cin >> i;
  for (i = n - 1; i >= 0; i--) sf[a[i]]++, update(bit, sf[a[i]], n, 1);
  for (auto &i : a) {
    update(bit, sf[i], n, -1);
    sf[i]--;
    ans += query(bit, pr[i]);
    pr[i]++;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  solve();
  return 0;
}
