#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100005;
int a[NMAX], n;
unordered_map<int, int> M;
int main() {
  int x;
  long long sol;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    x = a[i];
    ++M[x];
  }
  sort(a + 1, a + n + 1);
  if (a[1] == a[2]) {
    if (a[1] == a[2] && a[2] == a[3]) {
      x = a[1];
      sol = (1LL * M[x] * (M[x] - 1) * (M[x] - 2)) / 6;
      cout << sol << "\n";
    } else {
      x = a[1];
      sol = (1LL * M[x] * (M[x] - 1)) / 2;
      x = a[3];
      sol *= M[x];
      cout << sol << "\n";
    }
  } else if (a[2] == a[3]) {
    if (a[1] == a[2] && a[2] == a[3]) {
      x = a[1];
      sol = (1LL * M[x] * (M[x] - 1) * (M[x] - 2)) / 6;
      cout << sol << "\n";
    } else {
      x = a[2];
      sol = (1LL * M[x] * (M[x] - 1)) / 2;
      x = a[1];
      sol *= M[x];
      cout << sol << "\n";
    }
  } else {
    sol = M[a[1]] * M[a[2]] * M[a[3]];
    cout << sol << "\n";
  }
  return 0;
}
