#include <bits/stdc++.h>
using namespace std;
const int N = 1010101;
const int LOGN = (int)log2(N) + 2;
int SQRTN = (int)sqrt(N) + 7;
const long long infi = 1ll << 60;
long long n, a, ans;
vector<long long> vec;
map<long long, long long> rep;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n;
  for (int(i) = (0); (i) <= (int)(n - 1); ++(i)) {
    cin >> a;
    vec.push_back(a);
    ++rep[a];
  }
  sort(vec.begin(), vec.end());
  if (vec[0] == vec[2])
    ans = rep[vec[0]] * (rep[vec[0]] - 1) * (rep[vec[0]] - 2) / 6;
  else if ((vec[0] == vec[1] && vec[1] != vec[2]) ||
           (vec[1] == vec[2] && vec[0] != vec[2])) {
    if (rep[vec[0]] == 1)
      ans = rep[vec[2]] * (rep[vec[2]] - 1) / 2;
    else
      ans = rep[vec[2]];
  } else
    ans = rep[vec[2]];
  cout << ans << endl;
  return 0;
}
