#include <bits/stdc++.h>
using namespace std;
struct Couple {
  int fir, sec;
  bool operator<(const Couple& a) const {
    return fir == a.fir ? sec < a.sec : fir < a.fir;
  }
};
Couple disc[1000010];
int id[1000010], a[1000010];
class TreeArray {
  int node[1000010];
  int n;

 public:
  void set(int x) { n = x; }
  void add(int x) {
    for (int i = x; i <= n; i += i & -i) ++node[i];
  }
  int sum(int x, int f = 0) {
    for (int i = x; i; i -= i & -i) f += node[i];
    return f;
  }
} tree;
int last[1000010];
int sumN[1000010], sumP[1000010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    disc[i] = (Couple){a[i], i};
  }
  sort(disc + 1, disc + n + 1);
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (i == 1 || disc[i].fir != disc[i - 1].fir)
      id[disc[i].sec] = ++cnt;
    else
      id[disc[i].sec] = cnt;
  }
  for (int i = 1; i <= n; ++i) {
    int pre = last[id[i]];
    last[id[i]] = i;
    sumP[i] = sumP[pre] + 1;
  }
  memset(last, 0, sizeof last);
  for (int i = n; i; --i) {
    int next = last[id[i]];
    last[id[i]] = i;
    sumN[i] = sumN[next] + 1;
  }
  tree.set(n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += tree.sum(n) - tree.sum(sumN[i]);
    tree.add(sumP[i]);
  }
  cout << ans << endl;
  return 0;
}
