#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000 + 7;
const int N = 1e6 + 5;
long long n, a[N], b[N], c, ans;
int main() {
  scanf("%I64d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    if (a[i] > a[i - 1]) c++;
    b[c]++;
  }
  if (b[1] >= 3) {
    ans = b[1] * (b[1] - 1) * (b[1] - 2) / 6;
  } else if (b[2] + b[1] >= 3) {
    if (b[1] == 1) {
      ans = b[2] * (b[2] - 1) / 2;
    } else {
      ans = b[2];
    }
  } else {
    ans = b[3];
  }
  printf("%I64d", ans);
}
