#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
long long ncr(long long n, long long r) {
  if (r == 3)
    return n * (n - 1) * (n - 2) / 6;
  else if (r == 2)
    return n * (n - 1) / 2;
  else
    return n;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    m[x]++;
  }
  int a[3];
  memset(a, 0, sizeof(a));
  int j = 0;
  int sum = 0;
  for (auto i = m.begin(); i != m.end(); i++) {
    a[j] = i->second;
    sum += a[j];
    if (sum >= 3) break;
    j++;
  }
  if (a[0] >= 3)
    cout << ncr(a[0], 3) << endl;
  else if (a[0] == 2)
    cout << ncr(a[1], 1) << endl;
  else if (a[0] + a[1] >= 3)
    cout << ncr(a[1], 2) << endl;
  else
    cout << ncr(a[2], 1) << endl;
  return 0;
}
