#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  long long a[n];
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  sort(a, a + n);
  long long count_a = 0, count_b = 0, count_c = 0;
  long long x, y, z, ans = 0;
  x = a[0], y = a[1], z = a[2];
  for (int i = 0; i < n; i++) {
    if (x == a[i]) count_a++;
    if (y == a[i]) count_b++;
    if (z == a[i]) count_c++;
  }
  if (x != y && y != z) {
    ans = count_a * count_b * count_c;
  } else if (x == y && y != z) {
    ans = count_a * (count_a - 1) / 2 * count_c;
  } else if (y == z && x != y) {
    ans = count_b * (count_b - 1) / 2 * count_a;
  } else if (x == y && y == z) {
    ans = count_a * (count_a - 1) * (count_a - 2) / 6;
  }
  printf("%lld\n", ans);
  return 0;
}
