#include <bits/stdc++.h>
using namespace std;
long long int somantor(long long int a) { return a * (a + 1) / 2; }
int main() {
  long long int n;
  scanf("%lld", &n);
  vector<long long int> v;
  map<long long int, long long int> mp;
  for (long long int i = 0; i < n; i++) {
    long long int a;
    scanf("%lld", &a);
    v.push_back(a);
    mp[a]++;
  }
  sort(v.begin(), v.end());
  long long int ans = 0;
  if (v[0] == v[2]) {
    long long int a = mp[v[2]];
    ans = a * (a - 1) * (a - 2);
    ans /= 6;
  } else if (v[1] == v[2]) {
    long long int a = mp[v[2]];
    ans = a * (a - 1) / 2;
  } else {
    long long int a = mp[v[2]];
    if (a >= 0) ans += a;
  }
  cout << ans << endl;
}
