#include <bits/stdc++.h>
using namespace std;
bool compare(long long int a, long long int b) { return a < b; }
struct cmp {
  bool operator()(const pair<long long int, long long int> &a,
                  const pair<long long int, long long int> &b) const {
    long long int lena = a.second - a.first + 1;
    long long int lenb = b.second - b.first + 1;
    if (lena == lenb) return a.first < b.first;
    return lena > lenb;
  }
};
long long int fact(long long int n) {
  long long int res = 1;
  for (long long int i = n; i >= 1; i++) {
    res = (res * i);
  }
  return res;
}
long long int comb(long long int n, long long int r) {
  return (fact(n) / (fact(r) * fact(n - r)));
}
bool checkPower(long long int x) { return x && (!(x & (x - 1))); }
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
void dfs(long long int i, vector<long long int> &c, vector<long long int> g[]) {
  long long int cycles = 0;
  c[i] = 2;
  for (long long int x : g[i]) {
    if (c[x] == 2) {
      cycles++;
      continue;
    }
    if (c[x] == 0) dfs(x, c, g);
  }
  c[i] = 1;
}
int32_t main() {
  long long int n, cnt = 3;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (long long int i = 3; i < n; i++) {
    if (a[i] == a[2]) cnt++;
  }
  if (a[2] == a[0])
    cout << ((cnt * (cnt - 2) * (cnt - 1)) / 6);
  else if (a[2] == a[1])
    cout << ((cnt - 2) * (cnt - 1) / 2);
  else
    cout << (cnt - 2);
  return 0;
}
