#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<long long> a;
  map<long long, long long> m;
  long long q, times, tmp;
  cin >> q;
  times = q;
  while (q--) {
    cin >> tmp;
    m[tmp]++;
    a.emplace_back(tmp);
  }
  sort(a.begin(), a.end());
  if (a[1] != a[2]) {
    cout << m[a[2]];
  } else if (a[1] == a[2] && a[0] != a[1]) {
    cout << (m[a[2]] * (m[a[2]] - 1)) / 2;
  } else {
    cout << (m[a[0]] * (m[a[0]] - 1) * (m[a[0]] - 2)) / 6;
  }
}
