#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const string nl = "\n";
template <class T>
struct fenwick {
  long long n;
  vector<T> tree;
  fenwick(const long long _n) {
    n = _n;
    tree.assign(n + 2, 0LL);
  }
  void add(long long pos, T dif) {
    ++pos;
    for (long long i = pos; i <= n; i += (i & -i)) {
      tree[i] += dif;
    }
  }
  void set(long long pos, T val) { add(pos, val - query(pos, pos)); }
  T query(long long l) {
    ++l;
    T sum = 0;
    for (long long i = l; i > 0; i -= (i & -i)) {
      sum += tree[i];
    }
    return sum;
  }
  T query(long long l, long long r) { return query(r) - query(l - 1); }
};
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t a) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(a + FIXED_RANDOM);
  }
  template <class T>
  size_t operator()(T a) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    hash<T> x;
    return splitmix64(x(a) + FIXED_RANDOM);
  }
  template <class T, class H>
  size_t operator()(pair<T, H> a) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    hash<T> x;
    hash<H> y;
    return splitmix64(x(a.first) * 37 + y(a.second) + FIXED_RANDOM);
  }
};
template <class T, class H>
using umap = unordered_map<T, H, custom_hash>;
template <class T>
using uset = unordered_set<T, custom_hash>;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  vector<long long> a(n);
  set<long long> se;
  umap<long long, long long> make_pair;
  for (auto& i : a) {
    cin >> i;
    se.insert(i);
  }
  long long timer = -1;
  for (auto& i : se) {
    make_pair[i] = ++timer;
  }
  for (auto& i : a) {
    i = make_pair[i];
  }
  umap<long long, long long> cnt;
  vector<long long> hld, hld1;
  for (long long i = 0; i < n; ++i) {
    hld.push_back(++cnt[a[i]]);
  }
  reverse(a.begin(), a.end());
  cnt.clear();
  for (long long i = 0; i < n; ++i) {
    hld1.push_back(++cnt[a[i]]);
  }
  reverse(a.begin(), a.end());
  fenwick<long long> ft((long long)1e6 + 100);
  long long ans = 0;
  for (long long i = n - 2; i >= 0; --i) {
    ft.add(hld1[n - i - 2], 1);
    ans += ft.query(hld[i] - 1);
  }
  cout << ans << nl;
}
