#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
ll C(int n, int r) {
  ll x = 1;
  for (int(i) = 0; (i) < (int)(r); ++(i)) x *= n - i;
  for (int(i) = 0; (i) < (int)(r); ++(i)) x /= i + 1;
  return x;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int(i) = 0; (i) < (int)(n); ++(i)) cin >> a[i];
  vector<int> s(a);
  sort((s).begin(), (s).end());
  map<int, int> ct;
  for (int(i) = 0; (i) < (int)(n); ++(i)) ++ct[a[i]];
  ll ans = ct[s[2]];
  if (s[2] == s[1] && s[2] == s[0])
    ans = C(ct[s[2]], 3);
  else if (s[2] == s[1])
    ans = C(ct[s[2]], 2);
  cout << ans << endl;
  return 0;
}
