#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  long long a, b, c;
  long long flag = 0;
  a = arr[0];
  b = arr[1];
  c = arr[2];
  long long ca = 1;
  long long cb, cc = 1;
  for (long long i = 3; i < n; i++) {
    if (arr[i] == c)
      cc++;
    else
      break;
  }
  if (a == b && b == c) {
    cout << ((cc + 2) * (cc + 1) * cc) / 6;
  } else if (b == c) {
    cout << ((cc + 1) * cc) / 2;
  } else {
    cout << cc;
  }
  return 0;
}
