#include <bits/stdc++.h>
using namespace std;
long long n, pos, t, a[100001], ans, c[3];
void solve(long long ind) {
  t = a[pos++];
  c[ind] = 1;
  while (pos < n && a[pos] == t) ++c[ind], ++pos;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  pos = 0;
  for (int i = 0; i < 3; ++i) {
    if (pos < n) solve(i);
  }
  if (c[0] >= 3)
    ans = (c[0] * (c[0] - 1) * (c[0] - 2)) / 6;
  else if (c[0] + c[1] >= 3) {
    if (c[0] > 1)
      ans = c[1];
    else
      ans = (c[1] * (c[1] - 1)) / 2;
  } else
    ans = c[2];
  cout << ans << endl;
  return 0;
}
