#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int a[maxn], b[maxn], N, cnt[maxn], occurence[maxn][2], t[maxn];
inline int lowbit(int x) { return x & (-x); }
int sum(int x) {
  int ans = 0;
  while (x != 0) {
    ans += t[x];
    x -= lowbit(x);
  }
  return ans;
}
void update(int x, int k) {
  while (x <= N) {
    t[x] += k;
    x += lowbit(x);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b + 1, b + N + 1);
  int len = unique(b + 1, b + N + 1) - b - 1;
  for (int i = 1; i <= N; i++) a[i] = lower_bound(b + 1, b + len + 1, a[i]) - b;
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    occurence[i][0] = ++cnt[a[i]];
  }
  memset(cnt, 0, sizeof cnt);
  for (int i = N; i >= 1; i--) {
    occurence[i][1] = ++cnt[a[i]];
  }
  for (int i = N; i >= 1; i--) {
    ans += sum(occurence[i][0] - 1);
    update(occurence[i][1], 1);
  }
  cout << ans << "\n";
  return 0;
}
