#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n1, long long n2) {
  if (!n1) return n2;
  if (!n2) return n1;
  if (n1 % n2 == 0) return n2;
  return gcd(n2, n1 % n2);
}
long long powmod(long long base, long long exponent) {
  base %= 1000000007;
  long long ans = 1;
  while (exponent) {
    if (exponent & 1) ans = (ans * base) % 1000000007;
    base = (base * base) % 1000000007;
    exponent /= 2;
  }
  ans %= 1000000007;
  return ans;
}
int arr[1000100 + 1];
int main() {
  int n, i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &arr[i]);
  sort(arr + 1, arr + n + 1);
  long long answer = 0;
  int freq = 0;
  for (i = 1; i <= n; i++)
    if (arr[i] == arr[1]) freq++;
  if (freq >= 3) {
    answer = 1LL * freq * (freq - 1) * (freq - 2);
    answer /= 6;
  } else if (freq == 2) {
    int freq2 = 0;
    for (i = 3; i <= n; i++)
      if (arr[i] == arr[3]) freq2++;
    answer = 1LL * freq2 * freq * (freq - 1);
    answer /= 2;
  } else if (freq == 1) {
    int freq2 = 0;
    for (i = 2; i <= n; i++)
      if (arr[i] == arr[2]) freq2++;
    if (freq2 >= 2) {
      answer = 1LL * freq * freq2 * (freq2 - 1);
      answer /= 2;
    } else {
      int freq3 = 0;
      for (i = 3; i <= n; i++)
        if (arr[i] == arr[3]) freq3++;
      answer = 1LL * freq * freq2 * freq3;
    }
  }
  printf("%lld\n", answer);
  return 0;
}
