#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 22;
int n;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  int x;
  vector<int> v, w;
  for (int i = 0; i < (n); i++) cin >> x, v.push_back(x);
  sort(v.begin(), v.end());
  if (v[0] == v[1]) {
    if (v[1] == v[2]) {
      long long cnt = 0;
      for (int i = 0; i < (v.size()); i++) cnt += v[i] == v[0];
      cout << (cnt * (cnt - 1) * (cnt - 2)) / 6;
      return 0;
    } else {
      long long cnt = 0;
      for (int i = 2; i < v.size(); i++) cnt += v[i] == v[2];
      cout << cnt;
      return 0;
    }
  } else {
    if (v[1] == v[2]) {
      long long cnt = 0;
      for (int i = (1); i <= (v.size() - 1); i++) cnt += v[i] == v[1];
      cout << cnt * (cnt - 1) / 2;
      return 0;
    } else {
      long long cnt = 0;
      for (int i = 2; i < v.size(); i++) cnt += v[i] == v[2];
      cout << cnt;
      return 0;
    }
  }
  return 0;
}
