#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAX = (int)1e5 + 5;
void build() { return; }
int n;
int store[MAX];
void Init() {
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) scanf("%d", store + i);
  sort(store, store + n);
  return;
}
void sol() {
  if (n == 3)
    puts("1");
  else {
    if (store[2] != store[3])
      puts("1");
    else {
      int cnt = 1;
      for (int i = (3); i < (n); ++i) {
        if (store[i] == store[2])
          cnt++;
        else
          break;
      }
      if (store[1] == store[2]) {
        if (store[0] == store[1])
          printf("%lld", (long long)cnt * (cnt + 1) * (cnt + 2) / 6);
        else
          printf("%lld", (long long)cnt * (cnt + 1) / 2);
      } else
        printf("%d", cnt);
    }
  }
  return;
}
int main(void) {
  Init();
  build();
  sol();
  return 0;
}
