#include <bits/stdc++.h>
using namespace std;
long long int cal(long long int x) {
  if (x <= 3) {
    return 1;
  }
  return (x * (x - 1) * (x - 2)) / 6;
}
long long int cal1(long long int x) {
  if (x <= 2) {
    return 1;
  }
  return (x * (x - 1)) / 2;
}
int main() {
  long long int n, i;
  cin >> n;
  long long int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long int c1 = 0, c2 = 0, c3 = 0;
  for (i = 0; i < n; i++) {
    if (a[i] == a[0]) {
      c1++;
    }
    if (a[i] == a[1]) {
      c2++;
    }
    if (a[i] == a[2]) {
      c3++;
    }
  }
  if (a[0] == a[1] && a[1] == a[2]) {
    cout << cal(c1);
    return 0;
  }
  if (a[0] != a[1] && a[1] == a[2]) {
    cout << cal1(c2) * c1;
    return 0;
  }
  if (a[0] == a[1] && a[1] != a[2]) {
    cout << cal1(c1) * c3;
    return 0;
  }
  if (a[0] != a[1] && a[1] != a[2]) {
    cout << c1 * c2 * c3;
  }
}
