#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int l[N], v[N], r[N];
int seg[4 * N];
map<int, int> ls, rs;
void update(int n, int l, int r, int s, int e, int d) {
  if (r < s || l > e) return;
  if (l >= s && r <= e) {
    seg[n] += d;
    return;
  }
  int mid = (l + r) / 2;
  update(n * 2 + 1, l, mid, s, e, d);
  update(n * 2 + 2, mid + 1, r, s, e, d);
  seg[n] = seg[n * 2 + 1] + seg[n * 2 + 2];
}
int get(int n, int l, int r, int s, int e) {
  if (r < s || l > e) return 0;
  if (l >= s && r <= e) {
    return seg[n];
  }
  int mid = (l + r) / 2;
  return get(n * 2 + 1, l, mid, s, e) + get(n * 2 + 2, mid + 1, r, s, e);
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> cmp;
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
    cmp.push_back(v[i]);
  }
  sort(cmp.begin(), cmp.end());
  cmp.resize(unique(cmp.begin(), cmp.end()) - cmp.begin());
  for (int i = 0; i < n; i++) {
    v[i] = lower_bound(cmp.begin(), cmp.end(), v[i]) - cmp.begin();
  }
  for (int i = 0; i < n; i++) {
    ls[v[i]]++;
    l[i] = ls[v[i]];
  }
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans += get(0, 0, N, 0, l[i] - 1);
    rs[v[i]]++;
    r[i] = rs[v[i]];
    update(0, 0, N, r[i], r[i], 1);
  }
  cout << ans << endl;
  return 0;
}
