#include <bits/stdc++.h>
using namespace std;
long long int n, x;
vector<int> a;
long long int tarkib(long long int r, long long int n) {
  long long int a = 1;
  for (long long int i = n; i > (n - r); i--) a = a * i;
  for (long long int i = 2; i < r + 1; i++) a = a / i;
  return a;
}
int main() {
  long long int r;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  long long int i;
  for (i = 3; i < n; i++) {
    if (a[i] > a[i - 1]) break;
  }
  i--;
  i--;
  if (a[0] == a[1]) {
    if (a[1] == a[2]) {
      r = 3;
      i += 2;
    } else {
      r = 1;
    }
  } else {
    if (a[1] == a[2]) {
      i++;
      r = 2;
    } else {
      r = 1;
    }
  }
  cout << tarkib(r, i);
  return 0;
}
