#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
long long m1, m2, m3;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (a[i] == a[0]) m1++;
    if (a[i] == a[1]) m2++;
    if (a[i] == a[2]) m3++;
  }
  if (a[0] == a[1] && a[1] == a[2])
    cout << ((m1) * ((m1)-1) * ((m1)-2) / 6) << endl;
  else if (a[0] == a[1])
    cout << ((m2) * ((m2)-1) / 2) * m3 << endl;
  else if (a[1] == a[2])
    cout << ((m2) * ((m2)-1) / 2) * m1 << endl;
  else
    cout << m1 * m2 * m3 << endl;
  return 0;
}
