#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000,100000000000")
const long long INF = 1000000007;
const long double cp = 2 * asin(1.0);
const long double eps = 1e-9;
const long long mod = 1000000007;
using namespace std;
map<long long, long long> p, s;
long long a[1000001], b[1000001], t[1000001], k = 0, n;
long long sum(long long x) {
  long long ans = 0;
  for (; x > 0; x -= x & -x) ans += t[x];
  return ans;
}
void ifyoureadthisyouareloser(int i, long long delta) {
  for (; i < n; i += i & -i) t[i] += delta;
}
long long sum(int l, int r) { return sum(r) - sum(l - 1); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int(i) = (1); (i) <= (n); i++) {
    cin >> a[i];
    p[a[i]]++;
    b[i] = p[a[i]];
  }
  for (int(i) = (n - 1); (i) >= (1); i--) {
    s[a[i + 1]]++;
    ifyoureadthisyouareloser(s[a[i + 1]], 1);
    k += sum(1, b[i] - 1);
  }
  cout << k;
  return 0;
}
