#include <bits/stdc++.h>
using namespace std;
class Fenwick {
 private:
  vector<int> t;

 public:
  Fenwick(int n) { t.resize(n + 1); }
  void update(int idx, int v) {
    for (int i = idx; i < t.size(); i += i & -i) {
      t[i] += v;
    }
  }
  int get(int idx) {
    int sum = 0;
    for (int i = idx; i > 0; i -= i & -i) {
      sum += t[i];
    }
    return sum;
  }
  void reset() {
    for (int i = 0; i < t.size(); i++) t[i] = 0;
  }
};
int compress(vector<int>& nums) {
  map<int, int> mp;
  for (int v : nums) mp[v] = 0;
  int m = 1;
  for (pair<const int, int>& it : mp) it.second = m++;
  for (int& v : nums) v = mp[v];
  return m;
}
void printVec(const vector<int>& nums) {
  for (int v : nums) cout << v << " ";
  cout << endl;
}
long long calcNumOfPairs(vector<int> nums) {
  int n = nums.size();
  compress(nums);
  Fenwick fw(n);
  vector<int> g1(n);
  fw.reset();
  for (int i = 0; i < n; i++) {
    fw.update(nums[i], 1);
    g1[i] = fw.get(nums[i]) - fw.get(nums[i] - 1);
  }
  vector<int> g2(n);
  fw.reset();
  for (int i = n - 1; i >= 0; i--) {
    fw.update(nums[i], 1);
    g2[i] = fw.get(nums[i]) - fw.get(nums[i] - 1);
  }
  long long answer = 0;
  fw.reset();
  for (int i = n - 1; i >= 0; i--) {
    answer += fw.get(g1[i] - 1);
    fw.update(g2[i], 1);
  }
  return answer;
}
int main() {
  int n;
  cin >> n;
  vector<int> nums(n);
  for (int i = 0; i < n; i++) cin >> nums[i];
  cout << calcNumOfPairs(nums) << endl;
  return 0;
}
