#include <bits/stdc++.h>
using namespace std;
const int N = 500023;
bool vis[N];
vector<int> adj[N];
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> v;
  for (long long int i = 0; i < n; i++) {
    long long int c;
    cin >> c;
    v.push_back(c);
  }
  sort((v).begin(), (v).end());
  long long int ans = 0;
  if (v[2] != v[1]) {
    for (int i = 2; i < n; i++) {
      if (v[i] == v[2])
        ans++;
      else
        break;
    }
  } else if ((v[2] == v[1]) && (v[1] != v[0])) {
    long long int count = 0;
    for (int i = 1; i < n; i++) {
      if (v[i] == v[1])
        count++;
      else
        break;
    }
    ans = (count * (count - 1)) / 2;
  } else {
    long long int count = 0;
    for (int i = 0; i < n; i++) {
      if (v[i] == v[0])
        count++;
      else
        break;
    }
    ans = (count * (count - 1) * (count - 2)) / 6;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  int t = 0;
  while (t++ < T) {
    solve();
  }
}
