#include <bits/stdc++.h>
using namespace std;
long long n, re, a[100005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  if (a[0] == a[2]) {
    long long j = 0;
    while (j < n && a[j] == a[0]) {
      j++;
    }
    cout << j * (j - 1) * (j - 2) / 6;
  } else if (a[1] == a[2]) {
    long long j = 1;
    while (j < n && a[j] == a[1]) {
      j++;
    }
    cout << (j - 1) * (j - 2) / 2;
  } else {
    long long j = 2;
    while (j < n && a[j] == a[2]) {
      j++;
    }
    cout << j - 2;
  }
  return 0;
}
