#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 1LL << 62;
const long long mx = 100005;
const double eps = 1e-10;
long long dx[10] = {1, 0, -1, 0};
long long dy[10] = {0, -1, 0, 1};
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long x = power(a, b / 2);
  x = x * x;
  if (b % 2) x = x * a;
  return x;
}
long long bigmod(long long a, long long b) {
  if (b == 0) return 1;
  long long x = bigmod(a, b / 2) % mod;
  x = (x * x) % mod;
  if (b % 2) x = (x * a) % mod;
  return x;
}
long long Set(long long N, long long pos) { return N = N | (1LL << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1LL << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1LL << pos)); }
long long arr[10 * mx], n;
int tree[4 * 10 * mx];
long long read(long long idx) {
  long long sum = 0;
  while (idx > 0) {
    sum += tree[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
void update(long long idx, long long val) {
  while (idx <= n) {
    tree[idx] += val;
    idx += (idx & -idx);
  }
}
int main() {
  long long tst, a, b, c, k, m, res = 0, ans = 0, t = 0;
  map<long long, long long> age, pore;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
    age[arr[i]]++;
    update(age[arr[i]], 1);
  }
  for (long long i = n; i > 0; i--) {
    pore[arr[i]]++;
    update(age[arr[i]]--, -1);
    a = read(n) - read(pore[arr[i]]);
    res += a;
  }
  cout << res << "\n";
  return 0;
}
