#include <bits/stdc++.h>
using vi = std::vector<long long int>;
using vvi = std::vector<vi>;
using pii = std::pair<long long int, long long int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
using namespace std;
const long long int N = 1e6 + 10;
const long long int inf = 1e9 + 10;
const long double Pi = 3.14159265;
long long int a[N], t[N], n, ma;
map<long long int, long long int> f, g;
void add(long long int idx, long long int delta) {
  for (; idx < n; idx = idx | (idx + 1)) t[idx] += delta;
}
long long int sum(long long int r) {
  long long int ret = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) ret += t[r];
  return ret;
}
void solve() {
  cin >> n;
  long long int ans = 0;
  ma = -inf;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  for (long long int i = 1; i <= n; i++) {
    f[a[i]]++;
    add(f[a[i]], 1);
  }
  for (long long int i = 1; i <= n; i++) {
    g[a[i]]++;
    add(f[a[i]], -1);
    f[a[i]]--;
    ans += sum(g[a[i]] - 1);
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  long long int xx = 0;
  return 0;
}
