#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int bit[N];
int lowbit(int x) { return x & -x; }
void insert(int x, int d) {
  while (x < N) {
    bit[x] += d;
    x += lowbit(x);
  }
}
int cnt(int x) {
  int ret = 0;
  while (x > 0) {
    ret += bit[x];
    x -= lowbit(x);
  }
  return ret;
}
void solve(int ncase) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> left(n), right(n);
  map<int, int> leftmap, rightmap;
  for (int i = 0; i < n; i++) {
    leftmap[a[i]]++;
    left[i] = leftmap[a[i]];
  }
  for (int i = n - 1; i >= 0; i--) {
    rightmap[a[i]]++;
    right[i] = rightmap[a[i]];
  }
  for (int i = 0; i < n; i++) {
    insert(right[i], 1);
  }
  unsigned long long ret = 0;
  for (int i = 0; i < n; i++) {
    insert(right[i], -1);
    ret += cnt(left[i] - 1);
  }
  cout << ret << endl;
}
int main() {
  ios::sync_with_stdio(false);
  int T = 1;
  int ncase = 0;
  while (T--) {
    solve(++ncase);
  }
}
