#include <bits/stdc++.h>
using namespace std;
long long int n, inp;
vector<long long int> arr;
long long int choose3(long long int n) { return (n * (n - 1) * (n - 2)) / 6; }
long long int choose2(long long int n) { return (n * (n - 1)) / 2; }
long long int binary_count(long long int num) {
  return upper_bound(arr.begin(), arr.end(), num) -
         lower_bound(arr.begin(), arr.end(), num);
}
int main() {
  cin >> n;
  for (long long int i = 0; i != n; i++) {
    cin >> inp;
    arr.push_back(inp);
  }
  sort(arr.begin(), arr.end());
  long long int lo1 = arr[0];
  long long int lo2 = -1;
  long long int lo3 = -1;
  long long int lo1_c = 1;
  long long int lo2_c = 1;
  long long int lo3_c = 1;
  for (long long int i = 1; i != n; i++) {
    if (arr[i] != arr[i - 1]) {
      if (lo2 == -1) {
        lo2 = arr[i];
      } else if (lo3 == -1) {
        lo3 = arr[i];
      } else {
        break;
      }
    } else if (lo2 == -1) {
      lo1_c++;
    } else if (lo3 == -1) {
      lo2_c++;
    } else {
      lo3_c++;
    }
  }
  if (lo1_c >= 3) {
    cout << choose3(lo1_c) << endl;
  } else if (lo1_c + lo2_c >= 3) {
    if (lo1_c == 1) {
      cout << choose2(lo2_c) << endl;
    } else {
      cout << lo2_c << endl;
    }
  } else if (lo1_c + lo2_c + lo3_c >= 3) {
    cout << lo3_c << endl;
  }
}
