#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6, M = 4e6 + 6;
map<long long int, int> m;
long long int n, ans, repeated[M];
pair<long long int, int> a[N];
void update(int ind, int s, int e, int pos, int val) {
  if (pos < s || pos > e) return;
  if (s == e) {
    repeated[ind] += val;
    return;
  }
  int mid = (s + e) >> 1;
  update(ind << 1, s, mid, pos, val);
  update(ind << 1 | 1, mid + 1, e, pos, val);
  repeated[ind] = repeated[ind << 1] + repeated[ind << 1 | 1];
}
int sum(int ind, int s, int e, int x, int y) {
  if (x > e || y < s) return 0;
  if (s >= x && e <= y) return repeated[ind];
  int mid = (s + e) >> 1;
  int left = sum(ind << 1, s, mid, x, y);
  int right = sum(ind << 1 | 1, mid + 1, e, x, y);
  return right + left;
}
int main() {
  cin >> n;
  memset(repeated, 0, sizeof repeated);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &a[i].first);
    if (m.count(a[i].first) == 0) {
      m[a[i].first] = 1;
      a[i].second = 1;
    } else {
      m[a[i].first]++;
      a[i].second = m[a[i].first];
    }
    update(1, 1, n, a[i].second, 1);
  }
  m.clear();
  for (int i = n - 1; i >= 0; i--) {
    m[a[i].first]++;
    update(1, 1, n, a[i].second, -1);
    ans += sum(1, 1, n, m[a[i].first] + 1, n);
  }
  cout << ans << endl;
}
