#include <bits/stdc++.h>
using namespace std;
long long C(long long n, long long r) {
  if (r == 0) return 1;
  if (r == 1) return n;
  if (r == 2) return (n * (n - 1)) / 2;
  if (r == 3) return (n * (n - 1) * (n - 2)) / 6;
  assert(false);
}
void solve() {
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    m[temp]++;
  }
  int cur = 3;
  for (auto i : m) {
    if (i.second >= cur) {
      cout << C(i.second, cur);
      return;
    } else {
      cur -= i.second;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
