#include <bits/stdc++.h>
using namespace std;
long long n, a[100005], conn[100005], last, p = 0;
long long C(long long n, long long r) {
  long long sum = 1;
  for (long long i = 1; i <= r; i++) sum = sum * (n + 1 - i) / i;
  return sum;
}
int main() {
  scanf("%lld", &n);
  for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
  sort(a, a + n);
  int con = 1;
  a[n] = -1;
  last = a[0];
  for (int i = 1; i <= n; ++i) {
    if (a[i] != last) {
      conn[p++] = con;
      last = a[i];
      con = 1;
    } else
      ++con;
  }
  if (conn[0] >= 3)
    printf("%lld\n", C(conn[0], 3));
  else if (conn[0] + conn[1] >= 3)
    printf("%lld\n", C(conn[1], 3 - conn[0]));
  else
    printf("%lld\n", conn[2]);
  return 0;
}
