#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n;
int a[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  if (a[1] == a[2] && a[2] == a[3]) {
    int d = 3;
    while (a[d + 1] == a[1]) ++d;
    printf("%I64d", (1ll * d * (d - 1) * (d - 2)) / 6);
  } else if (a[2] == a[3]) {
    int d = 3;
    while (a[d + 1] == a[3]) ++d;
    --d;
    printf("%I64d", (1ll * d * (d - 1)) / 2);
  } else {
    int d = 3;
    while (a[d + 1] == a[3]) ++d;
    printf("%d", d - 2);
  }
  return 0;
}
