#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... second) {
  int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), second...);
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const map<S, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
int main() {
  long long int n;
  cin >> n;
  map<long long int, long long int> M;
  for (long long int(i) = (long long int)(1); (i) <= (long long int)(n);
       (i)++) {
    long long int a;
    scanf("%lld", &a);
    if (M.find(a) == M.end())
      M[a] = 1;
    else
      M[a]++;
  }
  map<long long int, long long int>::iterator it = M.begin();
  if (it->second >= 3) {
    cout << ((it->second) * (it->second - 1) * (it->second - 2)) / 6 << endl;
    return 0;
  } else {
    map<long long int, long long int>::iterator it1 = M.begin();
    it++;
    if (it->second + it1->second >= 3) {
      if (it1->second > 1)
        cout << ((it1->second) * (it1->second - 1) * (it->second)) / 2 << endl;
      else
        cout << ((it->second) * (it->second - 1) * (it1->second)) / 2 << endl;
      return 0;
    }
    it++;
    cout << (it->second) << endl;
    return 0;
  }
  return 0;
}
