#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9;
long long BIT[N], a[N], n, ans, pref[N], suff[N];
void update(long long x, long long val) {
  for (; x <= n; x += x & -x) BIT[x] += val;
}
long long query(long long x) {
  long long sum = 0;
  for (; x > 0; x -= x & -x) sum += BIT[x];
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  map<long long, long long> p, s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    p[a[i]]++;
    pref[i] = p[a[i]];
  }
  for (int i = n - 1; i >= 0; i--) {
    s[a[i]]++;
    suff[i] = s[a[i]];
  }
  for (int i = 1; i < n; i++) {
    update(pref[i - 1], 1);
    ans = ans + query(n) - query(suff[i]);
  }
  cout << ans;
  return 0;
}
