#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> calcMin(const vector<long long> &v,
                                           bool l2r) {
  pair<long long, long long> min = {2e9, 0};
  vector<pair<long long, long long>> res;
  auto f = [&min](long long x) -> pair<long long, long long> {
    if (x < min.first) {
      min.first = x;
      min.second = 1;
    } else if (x == min.first) {
      min.second++;
    }
    return min;
  };
  if (!l2r)
    std::transform(v.begin(), v.end(), std::back_inserter(res), f);
  else {
    std::transform(v.rbegin(), v.rend(), std::back_inserter(res), f);
    std::reverse(res.begin(), res.end());
  }
  return res;
}
multiset<long long> findMinProd(vector<long long> v) {
  sort(v.begin(), v.end());
  multiset<long long> s = {v[0], v[1], v[2]};
  return s;
}
int main() {
  int n;
  cin >> n;
  vector<long long> v(n, 0);
  for (auto &e : v) {
    cin >> e;
  }
  vector<pair<long long, long long>> l = calcMin(v, 0), r = calcMin(v, 1);
  auto prodMin = findMinProd(v);
  long long res = 0;
  for (int j = 1; j < n - 1; j++) {
    multiset<long long> s{v[j], l[j - 1].first, r[j + 1].first};
    if (s == prodMin) {
      res += l[j - 1].second * r[j + 1].second;
    }
  }
  cout << res;
  return 0;
}
