#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 1;
int cnt[MAXN], cnt2[MAXN], t[MAXN], L[MAXN];
struct fenwick {
  int arr[MAXN];
  fenwick() { memset(arr, 0, sizeof arr); }
  void incr(int x, int by) {
    for (; x < MAXN; x += (x & (-x))) {
      arr[x] += by;
    }
  }
  int sum(int x) {
    int sum = 0;
    for (; x > 0; x -= (x & (-x))) {
      sum += arr[x];
    }
    return sum;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> s;
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
    s.push_back({t[i], i});
  }
  sort(s.begin(), s.end());
  int x = 1;
  t[s[0].second] = x;
  for (int i = 1; i < n; ++i) {
    if (s[i].first != s[i - 1].first) {
      x++;
    }
    t[s[i].second] = x;
  }
  for (int i = 0; i < n; i++) {
    cnt2[t[i]]++;
    L[i] = cnt2[t[i]];
  }
  fenwick fw;
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    cnt[t[i]]++;
    ans += fw.sum(L[i] - 1);
    fw.incr(cnt[t[i]], 1);
  }
  cout << ans << "\n";
  return 0;
}
