#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  cin >> n;
  vector<long> a(n);
  for (long i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  long a1 = a[0];
  long b = a[1];
  long c = a[2];
  long long ans = 1;
  for (long i = 3; i < n; ++i) {
    if (a[i] > c) break;
    if (a[i] == c) ans++;
  }
  ans;
  if (ans > 1) {
    if (a1 == c) {
      ans += 2;
      ans = (ans * (ans - 1) * (ans - 2)) / 6;
    } else if (b == c) {
      ans++;
      ans = (ans * (ans - 1)) / 2;
    }
  }
  cout << ans;
}
