#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[1000010];
int fa[1000010], fb[1000010];
int n;
int bit[1000010];
void update(int x, int value) {
  while (x < 1000010) {
    bit[x] += value;
    x += x & (-x);
  }
}
int query(int x) {
  int q = 0;
  while (x > 0) {
    q += bit[x];
    x -= x & (-x);
  }
  return q;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    a[i] = make_pair(x, i);
  }
  sort(a, a + n);
  a[n] = make_pair(a[n - 1].first + 1, n);
  for (int i = 0, cnt = 1; i < n; ++i, ++cnt) {
    fa[a[i].second] = cnt;
    if (a[i].first != a[i + 1].first) cnt = 0;
  }
  for (int i = n - 1, cnt = 1; i >= 0; --i, ++cnt) {
    if (a[i].first != a[i + 1].first) cnt = 1;
    fb[a[i].second] = cnt;
    update(fb[a[i].second], 1);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    update(fb[i], -1);
    ans += query(fa[i] - 1);
  }
  cout << ans;
}
