#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int modulo = 1e9 + 7;
map<int, int> pref;
int c[1000 * 1000 + 5];
int bits[1000 * 1000 + 5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    int b;
    cin >> b;
    a.push_back(b);
  }
  for (int i = n - 1; i >= 0; --i) {
    pref[a[i]]++;
    c[i] = pref[a[i]];
    for (int j = c[i]; j <= n; j += j & (-j)) bits[j]++;
  }
  pref.clear();
  long long result = 0;
  for (int i = 0; i < n; ++i) {
    pref[a[i]]++;
    int curr = pref[a[i]];
    for (int j = c[i]; j <= n; j += j & (-j)) bits[j]--;
    for (int j = curr - 1; j; j -= j & (-j)) result += bits[j];
  }
  cout << result << "\n";
  return 0;
}
