#include <bits/stdc++.h>
using namespace std;
struct FenwickTreeOneBasedIndexing {
  vector<int> bit;
  int n;
  FenwickTreeOneBasedIndexing(int n) {
    this->n = n + 1;
    bit.assign(n + 1, 0);
  }
  FenwickTreeOneBasedIndexing(vector<int> a)
      : FenwickTreeOneBasedIndexing(a.size()) {
    for (size_t i = 0; i < a.size(); i++) add(i, a[i]);
  }
  int sum(int idx) {
    int ret = 0;
    for (++idx; idx > 0; idx -= idx & -idx) ret += bit[idx];
    return ret;
  }
  int sum(int l, int r) { return sum(r) - sum(l - 1); }
  void add(int idx, int delta) {
    for (++idx; idx < n; idx += idx & -idx) bit[idx] += delta;
  }
};
int n;
int arr[1000001];
int suf[1000001];
int mark[1000001];
unordered_map<int, int> nM;
int main() {
  cin >> n;
  int i = 1;
  for (int x = 1; x <= n; x++) {
    cin >> arr[x];
    if (nM.find(arr[x]) == nM.end()) {
      nM[arr[x]] = i++;
    }
  }
  FenwickTreeOneBasedIndexing tree1(n);
  for (int x = n; x >= 1; x--) {
    mark[nM[arr[x]]]++;
    int now = mark[nM[arr[x]]];
    suf[x] = now;
    tree1.add(now, 1);
  }
  FenwickTreeOneBasedIndexing tree2(n);
  long long ans = 0;
  memset(mark, 0, sizeof mark);
  for (int x = 1; x <= n; x++) {
    mark[nM[arr[x]]]++;
    tree2.add(suf[x], 1);
    int now = mark[nM[arr[x]]];
    ans += tree1.sum(0, now - 1);
    ans -= tree2.sum(0, now - 1);
  }
  cout << ans;
}
