#include <bits/stdc++.h>
using namespace std;
const int OO = 1e9 + 7;
const int MOD = 1e9 + 7;
const int N = 1e6 + 7;
int a[N];
unordered_map<int, int> h;
int c[N];
int f1[N];
int f2[N];
int BIT[N];
void update(int i) {
  while (i < N) {
    BIT[i]++;
    i += (-i) & i;
  }
}
int query(int i) {
  int sum = 0;
  while (i > 0) {
    sum += BIT[i];
    i -= (-i) & i;
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  int cnt = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int ai;
    cin >> ai;
    if (h.find(ai) == h.end()) h[ai] = cnt++;
    a[i] = h[ai];
  }
  for (int i = 1; i <= n; i++) {
    c[a[i]]++;
    f1[i] = c[a[i]];
  }
  memset(c, 0, sizeof c);
  for (int i = n; i >= 1; i--) {
    c[a[i]]++;
    f2[i] = c[a[i]];
  }
  vector<pair<int, int> > queries;
  for (int i = 1; i <= n - 1; i++) {
    queries.push_back({f2[i + 1], f1[i]});
  }
  reverse(queries.begin(), queries.end());
  long long ans = 0;
  for (int i = 0; i <= n - 2; i++) {
    update(queries[i].first);
    ans += query(queries[i].second - 1);
  }
  cout << ans << endl;
  return 0;
}
