#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000;
const int SUPERN = 1000050;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9 + 7;
long long n, a[SUPERN], b[SUPERN], c[SUPERN], cl[SUPERN], cr[SUPERN], re, cnt,
    s[SUPERN];
map<long long, long long> m;
vector<long long> v;
void ad(long long ind, long long val) {
  for (long long i = ind; i <= n; i += i & -i) {
    s[i] += val;
  }
}
long long get(long long ind) {
  long long o = 0;
  for (long long i = ind; i >= 1; i -= i & -i) {
    o += s[i];
  }
  return o;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (m.find(a[i]) == m.end()) {
      cnt++;
      m[a[i]] = cnt;
      a[i] = cnt;
    } else
      a[i] = m[a[i]];
  }
  for (int i = 1; i <= n; ++i) {
    cl[a[i]]++;
    b[i] = cl[a[i]];
  }
  for (int i = n; i >= 1; --i) {
    cr[a[i]]++;
    c[i] = cr[a[i]];
    re += get(b[i] - 1);
    ad(c[i], 1);
  }
  cout << re;
  return 0;
}
