#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 3;
long long prime[4];
long long exp(long long a, long long b);
void sieve(long long n);
long long gcd(long long a, long long b);
long long countdigit(long long n);
long long sod(long long x);
vector<long long> ft;
long long tree[4000006];
long long a[1000006];
long long flag[1000006];
map<long long, long long> mi;
map<long long, long long> mj;
long long ai[1000006];
long long aj[1000006];
void build(long long idx, long long left, long long right) {
  if (left == right) {
    tree[idx] = flag[left];
    return;
  }
  long long mid = (left + right) / 2;
  build(2 * idx, left, mid);
  build(2 * idx + 1, mid + 1, right);
  tree[idx] = tree[2 * idx] + tree[2 * idx + 1];
}
void update(long long i, long long val, long long idx, long long left,
            long long right) {
  if (left == right && left == i) {
    tree[idx] = val;
    flag[i] = val;
    return;
  }
  if (i < left || i > right) {
    return;
  }
  long long mid = left + (right - left) / 2;
  update(i, val, 2 * idx, left, mid);
  update(i, val, 2 * idx + 1, mid + 1, right);
  tree[idx] = tree[2 * idx] + tree[2 * idx + 1];
  return;
}
long long query(long long idx, long long left, long long right, long long s,
                long long e) {
  if (e < left || s > right) {
    return 0;
  }
  if (s <= left && e >= right) {
    return tree[idx];
  }
  long long mid = (left + right) / 2;
  return query(2 * idx, left, mid, s, e) +
         query(2 * idx + 1, mid + 1, right, s, e);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long tt = 1;
  while (tt--) {
    long long n, q;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      mi[a[i]]++;
      ai[i] = mi[a[i]];
    }
    for (long long i = n - 1; i >= 0; i--) {
      mj[a[i]]++;
      aj[i] = mj[a[i]];
    }
    build(1, 0, n);
    long long ans = 0;
    for (long long i = n - 1; i >= 0; i--) {
      ans += query(1, 0, n, 1, ai[i] - 1);
      long long var = query(1, 0, n, aj[i], aj[i]);
      update(aj[i], var + 1, 1, 0, n);
    }
    cout << ans << '\n';
  }
}
long long exp(long long a, long long b) {
  int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res % mod;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void sieve(long long n) {
  for (long long i = 0; i <= n; i++) {
    prime[i] = 1;
  }
  prime[0] = 0;
  prime[1] = 0;
  for (long long i = 2; i <= n; i++) {
    if (prime[i] == 1) {
      for (long long j = 2; i * j <= n; j++) {
        prime[i * j] = 0;
      }
    }
  }
}
long long countdigit(long long n) { return floor(log10(n) + 1); }
long long sod(long long x) {
  long long s = 0;
  while (x != 0) {
    s = s + x % 10;
    x = x / 10;
  }
  return s;
}
