#include <bits/stdc++.h>
using namespace std;
int n, a[1000005], l[1000005], r[1000005], cnt1[1000005], cnt2[1000005];
long long bit[1000005], ans;
vector<int> tmp;
void update(int x) {
  while (x < 1000005 - 5) {
    bit[x]++;
    x += (x & (-x));
  }
}
long long get(int x) {
  long long res = 0;
  while (x > 0) {
    res += bit[x];
    x -= (x & (-x));
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = (1); i <= (n); ++i) {
    cin >> a[i];
    tmp.push_back(a[i]);
  }
  sort(tmp.begin(), tmp.end());
  tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
  for (int i = (1); i <= (n); ++i)
    a[i] = lower_bound(tmp.begin(), tmp.end(), a[i]) - tmp.begin() + 1;
  for (int i = (1); i <= (n); ++i) {
    cnt1[a[i]]++;
    l[i] = cnt1[a[i]];
  }
  for (int i = (n); i >= (1); --i) {
    cnt2[a[i]]++;
    r[i] = cnt2[a[i]];
  }
  for (int i = (n); i >= (1); --i) {
    ans += get(l[i] - 1);
    update(r[i]);
  }
  cout << ans;
  return 0;
}
