#include <bits/stdc++.h>
using namespace std;
int32_t seed;
mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());
inline int32_t rnd(int32_t l = 0, int32_t r = numeric_limits<int32_t>::max()) {
  return uniform_int_distribution<int32_t>(l, r)(rng);
}
template <typename T, typename G>
ostream& operator<<(ostream& out, const pair<T, G>& a) {
  return out << "( " << a.first << ", " << a.second << ")";
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  out << "[ ";
  for (const auto& i : a) out << i << ", ";
  return out << "]" << endl;
}
template <typename T>
ostream& operator<<(ostream& out, const set<T>& a) {
  out << "{ ";
  for (const auto& i : a) out << i << ", ";
  return out << "}" << endl;
}
template <typename T, typename G>
ostream& operator<<(ostream& out, const map<T, G>& a) {
  out << "< ";
  for (const auto& i : a) out << i << ", ";
  return out << ">" << endl;
}
template <typename T, size_t N>
typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,
                   ostream&>::type
operator<<(ostream& out, T (&a)[N]) {
  out << "[ ";
  for (const auto& i : a) out << i << ", ";
  return out << "]" << endl;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << (H) << ' ';
  debug_out(T...);
}
long long nck(int32_t n, int32_t k) {
  long long nm = 1, dn = 1;
  for (int32_t i = 0; i < k; ++i) {
    nm *= n;
    dn *= (i + 1);
    n--;
  }
  return nm / dn;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int32_t n;
  cin >> n;
  map<int32_t, int32_t> count;
  for (int32_t i = 0, u; i < n; ++i) {
    cin >> u;
    count[u]++;
  }
  int32_t tot = 0;
  vector<int32_t> a;
  for (auto& u : count) {
    a.push_back(u.second);
    tot += u.second;
    if (tot >= 3) break;
  }
  long long ans;
  if (a.size() == 1) {
    ans = nck(a[0], 3);
  } else if (a.size() == 3) {
    ans = a[2];
  } else {
    if (a[0] == 1) {
      ans = nck(a[1], 2);
    } else {
      ans = a[1];
    }
  }
  cout << ans << '\n';
  return 0;
}
