#include <bits/stdc++.h>
using namespace std;
map<long long, long long> x;
long long a[100000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (!x[a[i]]) {
      x[a[i]] = 1;
    } else {
      x[a[i]]++;
    }
  }
  sort(a, a + n);
  if (x[a[0]] >= 3) {
    cout << x[a[0]] * (x[a[0]] - 1) * (x[a[0]] - 2) / 6;
  } else if (x[a[0]] == 2 || x[a[1]] == 1) {
    cout << x[a[2]];
  } else {
    cout << x[a[1]] * (x[a[1]] - 1) / 2;
  }
}
