#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T read() {
  static T x;
  static char c;
  static int _;
  x = 0;
  _ = 1;
  while (!isdigit(c = getchar()))
    if (c == '-') _ = -1;
  while (x = (x << 1) + (x << 3) + (c & 15), isdigit(c = getchar()))
    ;
  return x * _;
}
template <class T>
void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 ^ 48);
}
template <class T>
inline bool chikmin(T &a, T b) {
  return a > b ? (a = b, 1) : 0;
}
template <class T>
inline bool chikmax(T &a, T b) {
  return a < b ? (a = b, 1) : 0;
}
int f[1000006], re[1000006];
map<int, int> M1, M2;
int n;
int a[1000006];
int hash[1000006], size;
struct Fenwik {
  long long t[1000006];
  void insert(int x, int v) {
    for (; x <= n; x += ((x) & (-x))) {
      t[x] += v;
    }
  }
  long long query(int x) {
    long long res = 0;
    for (; x; x -= ((x) & (-x))) res += t[x];
    return res;
  }
} T;
int main() {
  n = read<int>();
  for (register int i = 1; i <= n; ++i) {
    a[i] = read<int>();
  }
  for (register int i = 1; i <= n; ++i) {
    f[i] += (++M1[a[i]]);
  }
  for (register int i = n; i >= 1; --i) {
    re[i] += (++M2[a[i]]);
  }
  long long ans = 0;
  for (register int i = n - 1; i >= 1; --i) {
    T.insert(re[i + 1], 1);
    ans += T.query(f[i] - 1);
  }
  cout << ans << endl;
  return 0;
}
