#include <bits/stdc++.h>
using namespace std;
const int INFint = 2147483547;
const long long INF = 9223372036854775807ll;
const long long MOD = 1000000007ll;
const long double EPS = 1e-13;
struct fenwick_tree {
  vector<int> t;
  int n;
  fenwick_tree(int n) : n(n) { t.resize(n, 0); }
  int sum(int r) {
    int res = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) res += t[r];
    return res;
  }
  void modify(int x, int val) {
    for (; x < n; x |= x + 1) t[x] += val;
  }
  int sum(int l, int r) { return sum(r) - sum(l - 1); }
};
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> compr;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    compr[a[i]] = 0;
  }
  int sz = 0;
  for (auto it : compr) compr[it.first] = sz++;
  for (int i = 0; i < n; i++) a[i] = compr[a[i]];
  vector<int> fl(n), fr(n);
  vector<int> cnt(sz);
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
    fl[i] = cnt[a[i]];
  }
  cnt.assign(sz, 0);
  for (int i = n - 1; i > -1; i--) {
    cnt[a[i]]++;
    fr[i] = cnt[a[i]];
  }
  fenwick_tree ft(n + 1);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += ft.sum(fr[i] + 1, n);
    ft.modify(fl[i], 1);
  }
  cout << ans << '\n';
  fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock() / CLOCKS_PER_SEC);
  ;
  return 0;
}
