#include <bits/stdc++.h>
using namespace std;
long long pos[100000], sum[100000], temp[100000];
long long n;
void merge(long long m, long long l) {
  long long mid = (m + l) / 2;
  long long x = m, y = mid + 1, k = m;
  while (x <= mid && y <= l) {
    if (sum[x] < sum[y]) {
      temp[k++] = sum[x++];
    } else {
      temp[k++] = sum[y++];
    }
  }
  while (x <= mid) temp[k++] = sum[x++];
  while (y <= l) temp[k++] = sum[y++];
  for (long long z = m; z <= l; z++) {
    sum[z] = temp[z];
  }
}
void sort(long long m, long long l) {
  if (m == l) {
    return;
  }
  long long mid = (m + l) / 2;
  sort(m, mid);
  sort(mid + 1, l);
  merge(m, l);
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> sum[i];
  }
  sort(1, n);
  long long m[4] = {0, 0, 0, 0};
  for (long long j = 1; j <= n; j++) {
    if (sum[j] == sum[1]) {
      m[1]++;
    }
  }
  if (m[1] >= 3) {
    cout << m[1] * (m[1] - 1) * (m[1] - 2) / 6;
  } else {
    for (long long j = m[1] + 1; j <= n; j++) {
      if (sum[j] == sum[m[1] + 1]) {
        m[2]++;
      }
    }
    if (m[1] == 2)
      cout << m[2];
    else if (m[1] == 1) {
      if (m[2] >= 2)
        cout << m[2] * (m[2] - 1) / 2;
      else {
        for (long long j = m[1] + m[2] + 1; j <= n; j++) {
          if (sum[j] == sum[m[1] + m[2] + 1]) {
            m[3]++;
          }
        }
        cout << m[3];
      }
    }
  }
  return 0;
}
