#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (T i : v) os << i << ' ';
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (T i : v) os << i << ' ';
  return os;
}
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << v.first << ' ' << v.second;
  return os;
}
template <class T, class S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v) {
  for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' ';
  return os;
}
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
    "avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const long long N = 2e6 + 4;
long long arr[N];
long long pre[N];
long long suff[N];
long long n;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
clock_t time_p = clock();
void starboy1299() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
long long BIT[N];
void update(long long idx, long long val) {
  for (long long i = idx; i <= n; i += i & -i) {
    BIT[i] += val;
  }
}
long long query(long long idx) {
  long long sum = 0;
  for (long long i = idx; i > 0; i -= i & -i) {
    sum += BIT[i];
  }
  return sum;
}
void solve() {
  cin >> n;
  for (long long i = 1; i < n + 1; i++) {
    cin >> arr[i];
  }
  map<long long, long long> mp;
  for (long long i = 1; i <= n; i++) {
    mp[arr[i]]++;
    pre[i] = mp[arr[i]];
  }
  map<long long, long long> mp1;
  for (long long i = n; i > 0; i--) {
    mp1[arr[i]]++;
    suff[i] = mp1[arr[i]];
  }
  long long ans = 0;
  for (long long i = n; i > 0; i--) {
    ans += query(pre[i] - 1);
    update(suff[i], 1);
  }
  cout << ans << '\n';
}
int32_t main() {
  fast();
  long long t = 1;
  while (t--) solve();
  starboy1299();
}
