#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int x[maxn];
map<int, int> mp;
int l[maxn], r[maxn];
int n;
int bit[maxn];
int sum(int i) {
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}
void add(int i, int x) {
  while (i <= n) {
    bit[i] += x;
    i += i & -i;
  }
}
int MAIN() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x[i]);
  }
  for (int i = 1; i <= n; ++i) {
    if (mp.count(x[i])) {
      mp[x[i]]++;
    } else {
      mp[x[i]] = 1;
    }
    l[i] = mp[x[i]];
  }
  mp.clear();
  for (int i = n; i >= 1; --i) {
    if (mp.count(x[i])) {
      mp[x[i]]++;
    } else {
      mp[x[i]] = 1;
    }
    r[i] = mp[x[i]];
  }
  long long tot = 0;
  for (int i = n; i >= 1; --i) {
    tot = tot + sum(l[i] - 1);
    add(r[i], 1);
  }
  cout << tot << endl;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  int ret = MAIN();
  return ret;
}
