#include <bits/stdc++.h>
using namespace std;
const long long N = 5e3 + 1, mod = 998244353, bit = 19;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long n;
  cin >> n;
  map<long long, long long> mp;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  sort(a, a + n);
  long long ans;
  if (a[0] == a[2]) {
    ans = (mp[a[0]] * (mp[a[0]] - 1) * (mp[a[0]] - 2)) / 6;
  } else if (a[1] == a[2]) {
    ans = (mp[a[1]] * (mp[a[1]] - 1)) >> 1;
  } else {
    ans = mp[a[2]];
  }
  cout << ans << '\n';
  return 0;
}
