#include <bits/stdc++.h>
using namespace std;
long long ncr(long long n, int r) {
  long long ans = 1;
  int i;
  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }
  return ans;
}
int main() {
  int n, c[3], i, j, ind;
  long long x;
  vector<long long> a;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  for (i = 0; i < 3; i++) c[i] = 0;
  for (i = 0, j = 0, ind = 0; i < n; i++) {
    if (a[i] == a[ind])
      c[j]++;
    else {
      if (c[0] + c[1] + c[2] >= 3) break;
      j++;
      ind = i;
      i--;
    }
  }
  long long ans;
  if (c[2])
    ans = c[2];
  else if (c[1])
    ans = ncr(c[1], 3 - c[0]);
  else
    ans = ncr(c[0], 3);
  cout << ans;
  return 0;
}
