#include <bits/stdc++.h>
using namespace std;
long long arr[1000005], pref[1000005], suff[1000005], fenw[1000005];
unordered_map<long long, long long> mp, mp2, mp3;
void upd(long long x, long long val) {
  for (; x < 1000005; x += x & -x) fenw[x] += val;
}
long long que(long long x) {
  long long sum = 0;
  for (; x > 0; x -= x & -x) sum += fenw[x];
  return sum;
}
signed main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    arr[i] = x;
  }
  for (long long i = 0; i < n; i++) {
    mp2[arr[i]]++;
    pref[i] = mp2[arr[i]];
  }
  for (long long i = n - 1; i >= 0; i--) {
    mp3[arr[i]]++;
    upd(mp3[arr[i]], 1);
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    upd(mp3[arr[i]], -1);
    mp3[arr[i]]--;
    ans += que(pref[i] - 1);
  }
  cout << ans << endl;
}
