#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5;
int a[MaxN + 5];
map<int, long long> cnt;
int n;
int main() {
  while (~scanf("%d", &n)) {
    int tot = 0;
    for (int i = 1; i <= n; i++) {
      int num;
      scanf("%d", &num);
      if (!cnt[num]) a[++tot] = num;
      cnt[num]++;
    }
    sort(a + 1, a + 1 + tot);
    long long ans = 0;
    if (cnt[a[1]] >= 3)
      ans = cnt[a[1]] * (cnt[a[1]] - 1LL) * (cnt[a[1]] - 2LL) / 6LL;
    else if (cnt[a[1]] == 2)
      ans = cnt[a[2]];
    else if (cnt[a[1]] == 1) {
      if (cnt[a[2]] >= 2)
        ans = cnt[a[2]] * (cnt[a[2]] - 1) / 2LL;
      else if (cnt[a[2]] == 1)
        ans = cnt[a[3]];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
