#include <bits/stdc++.h>
using namespace std;
struct FenwickTree {
  vector<int> bit;
  int n;
  FenwickTree() {}
  FenwickTree(int n) {
    this->n = n;
    bit.assign(n + 1, 0);
  }
  void updateRange(int l, int r, int x) {
    update(l, x);
    update(r + 1, -x);
  }
  int point_query(int r) { return sum(r); }
  int sum(int r) {
    int ret = 0;
    for (int i = r; i; i -= i & -i) ret += bit[i];
    return ret;
  }
  void update(int p, int val) {
    for (int i = p; i <= n; i += i & -i) bit[i] += val;
  }
};
int n;
int a[1000005];
int b[1000005];
int c[1000005];
map<int, int> m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    m[a[i]]++;
    b[i] = m[a[i]];
  }
  m.clear();
  for (int i = n; i > 0; i--) {
    m[a[i]]++;
    c[i] = m[a[i]];
  }
  long long sol = 0LL;
  FenwickTree f(n);
  for (int i = n; i > 0; i--) {
    sol = sol + (long long)f.sum(b[i] - 1);
    f.update(c[i], 1);
  }
  cout << sol;
  return 0;
}
