#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793;
const int SZ = 1000005, mod = 1000000007;
int ara[SZ];
long long x;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ara[i];
  sort(ara, ara + n);
  long long a = 1, b = 1, c = 1;
  x = ara[0];
  for (int i = 1; i < n; i++) {
    if (ara[i] == x)
      a++;
    else
      break;
  }
  if (a >= 3) {
    cout << a * (a - 1) * (a - 2) / 6 << endl;
    return 0;
  }
  x = ara[a];
  for (int i = a + 1; i < n; i++) {
    if (ara[i] == x)
      b++;
    else
      break;
  }
  if (a + b >= 3) {
    if (a == 1) {
      cout << b * (b - 1) / 2 << endl;
    } else
      cout << b << endl;
    return 0;
  }
  x = ara[a + b];
  for (int i = a + b + 1; i < n; i++) {
    if (ara[i] == x)
      c++;
    else
      break;
  }
  cout << c << endl;
  return 0;
}
