#include <bits/stdc++.h>
using namespace std;
int main() {
  int nb;
  scanf("%d", &nb);
  int arr[nb];
  for (int i = 0; i < nb; i++) scanf("%d", arr + i);
  sort(arr, arr + nb);
  int occ[3] = {0};
  for (int i = 0; i < nb; i++) {
    for (int j = 0; j < 3; j++)
      if (arr[i] == arr[j]) occ[j]++;
  }
  if ((occ[0] == 1 && occ[1] == 1) || (occ[0] == 2)) {
    printf("%d", occ[2]);
    return 0;
  }
  if (occ[0] == 1 && occ[1] >= 2) {
    long long res = (occ[1] * (long long)(occ[1] - 1)) / 2;
    printf("%lld", res);
    return 0;
  }
  long long res = (occ[0] * (long long)(occ[0] - 1) * (occ[0] - 2)) / 6;
  printf("%lld", res);
  return 0;
}
