#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long A[n + 1], a = 1, b = 0, c = 0;
  for (int i = 0; i < n; i++) cin >> A[i];
  sort(A, A + n);
  for (int i = 1; i < n; i++) {
    if (A[i] == A[i - 1] && b == 0 && c == 0) {
      a++;
    } else if (b == 0)
      b++;
    else if (A[i] == A[i - 1] && c == 0)
      b++;
    else if (c == 0)
      c++;
    else if (A[i] == A[i - 1])
      c++;
    else
      break;
  }
  if (a >= 3) {
    cout << (a * (a - 1) * (a - 2)) / 6 << endl;
  } else if (a == 2) {
    cout << b << endl;
  } else if (a == 1) {
    if (b >= 2) {
      cout << (b * (b - 1)) / 2 << endl;
    } else if (b == 1)
      cout << c << endl;
  }
  return 0;
}
