#include <bits/stdc++.h>
using namespace std;
int main() {
  int res[100005];
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &res[i]);
  }
  sort(res, res + n);
  long long num = 1;
  for (int i = 3; i < n; i++) {
    if (res[i] == res[2])
      num++;
    else if (res[i] > res[2])
      break;
  }
  if (num == 1) {
    cout << 1 << endl;
    return 0;
  } else {
    if (res[1] == res[2] && res[0] != res[1]) {
      num++;
      cout << (long long)num * (num - 1) / 2 << endl;
      return 0;
    }
    if (res[1] == res[2] && res[0] == res[1]) {
      num += 2;
      cout << (long long)num * (num - 1) * (num - 2) / 6 << endl;
      return 0;
    }
    if (res[1] != res[2] && res[0] != res[1]) {
      cout << num << endl;
      return 0;
    }
    if (res[1] != res[2] && res[0] == res[1]) {
      cout << num << endl;
      return 0;
    }
  }
}
