#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  if (v[0] == v[2]) {
    long long i = 0;
    while (v[i] == v[0]) i++;
    cout << i * (i - 1) * (i - 2) / 6 << endl;
  } else if (v[1] == v[2]) {
    long long i = 1;
    while (v[i] == v[1]) i++;
    cout << (i - 1) * (i - 2) / 2 << endl;
  } else {
    long long i = 2;
    while (v[i] == v[2]) i++;
    cout << i - 2 << endl;
  }
}
