#include <bits/stdc++.h>
using namespace std;
unsigned long long int fact(int n) {
  if (n == 0 || n == 1)
    return 1;
  else
    return n * fact(n - 1);
}
int main() {
  long long int n;
  cin >> n;
  long long int arr[1000000];
  for (long long int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  long long int min1, min2, min3;
  sort(arr, arr + n);
  min1 = arr[0];
  min2 = arr[1];
  min3 = arr[2];
  if (min1 == min2 && min2 == min3) {
    long long int c = 0;
    for (long long int i = 0; i < n; ++i) {
      if (arr[i] == min1) c++;
    }
    unsigned long long int ans;
    ans = (((c * (c - 1)) / 2) * (c - 2)) / 3;
    cout << ans;
    return 0;
  } else if (min1 == min2 && min2 != min3) {
    long long int c = 1;
    for (long long int i = 3; i < n; ++i) {
      if (arr[i] == min3) c++;
    }
    cout << c;
  } else if (min2 == min3) {
    long long int c = 1;
    for (long long int i = 2; i < n; ++i) {
      if (arr[i] == min2) c++;
    }
    long long int ans;
    ans = (c * (c - 1)) / 2;
    cout << ans;
    return 0;
  } else {
    long long int c = 1;
    for (long long int i = 3; i < n; ++i) {
      if (arr[i] == min3) c++;
    }
    cout << c;
  }
}
