#include <bits/stdc++.h>
using namespace std;
int a[111111];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n == 3) {
    cout << 1 << endl;
    return 0;
  }
  sort(a + 1, a + n + 1);
  int t = 4;
  while (t <= n and a[t] == a[t - 1]) t++;
  int tp[4] = {};
  tp[1] = 1;
  int cnt = 1;
  for (int i = 2; i < t; i++) {
    if (a[i] != a[i - 1]) {
      cnt++;
    }
    tp[cnt]++;
  }
  if (cnt == 3) {
    cout << tp[3] << endl;
  }
  if (cnt == 2) {
    if (tp[1] == 1) {
      cout << 1LL * tp[2] * (tp[2] - 1) / 2 << endl;
    } else {
      cout << tp[2] << endl;
    }
  }
  if (cnt == 1) {
    cout << 1LL * tp[1] * (tp[1] - 1) * (tp[1] - 2) / 6 << endl;
  }
  return 0;
}
