#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
long long a[MAX];
map<long long, long long> b;
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  sort(a, a + n);
  if (a[2] != a[1])
    cout << b[a[2]] << endl;
  else if (a[1] != a[0] && a[1] == a[2])
    cout << (b[a[2]] * (b[a[2]] - 1) / 2) << endl;
  else {
    cout << (b[a[1]] * (b[a[1]] - 1) * (b[a[1]] - 2) / 6) << endl;
  }
  return 0;
}
