#include <bits/stdc++.h>
using namespace std;
long long readint() {
  long long x = 0, y = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') y = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * y;
}
long long n;
long long a[100010];
signed main() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long ans = 0;
  for (long long i = 0; i < n; i++)
    if (a[i] == a[2]) ans++;
  if (a[2] == a[0])
    ans = ans * (ans - 1) * (ans - 2) / 6;
  else if (a[1] == a[2])
    ans = ans * (ans - 1) / 2;
  cout << ans << '\n';
  return 0;
}
