#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long max_n = 1e6 + 10;
long long fen[max_n];
void add(long long ind) {
  for (long long i = ind; i < max_n; i |= (i + 1)) fen[i] += 1;
}
long long gett(long long ind) {
  long long ans = 0;
  for (long long i = ind; i >= 0; i = ((i + 1) & i) - 1) ans += fen[i];
  return ans;
}
long long get(long long l, long long r = max_n - 1) {
  return gett(r) - gett(l);
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  vector<long long> a(n, 0);
  for (long long i = 0; i < n; i++) cin >> a[i];
  map<long long, long long> ma;
  vector<long long> val(n, 0);
  for (long long i = 0; i < n; i++) {
    if (ma.find(a[i]) == ma.end()) ma[a[i]] = 0;
    ma[a[i]]++;
    val[i] = ma[a[i]];
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += get(ma[a[i]]);
    add(val[i]);
    ma[a[i]]--;
  }
  cout << ans;
}
