#include <bits/stdc++.h>
using namespace std;
long long mins[3];
long long freqs[3];
void move(int i) {
  for (int j = 2; j > i; j--) {
    mins[j] = mins[j - 1];
    freqs[j] = freqs[j - 1];
  }
}
void insert(long long n) {
  for (int i = 0; i < 3; i++) {
    if (n == mins[i]) {
      move(i);
      freqs[i]++;
      return;
    }
    if (n < mins[i]) {
      move(i);
      freqs[i] = 1;
      mins[i] = n;
      return;
    }
  }
}
using namespace std;
int main() {
  mins[0] = 2000000000;
  mins[1] = 2000000000 + 1;
  mins[2] = 2000000000 + 2;
  freqs[0] = 0;
  freqs[1] = 0;
  freqs[2] = 0;
  int amt;
  cin >> amt;
  for (int i = 0; i < amt; i++) {
    long long n;
    cin >> n;
    insert(n);
  }
  if (mins[0] < mins[1] && mins[1] < mins[2]) {
    cout << freqs[0] * freqs[1] * freqs[2];
  }
  if (mins[0] == mins[1] && mins[1] < mins[2]) {
    cout << freqs[0] * (freqs[0] - 1) / 2 * freqs[2];
  }
  if (mins[0] < mins[1] && mins[1] == mins[2]) {
    cout << freqs[1] * (freqs[1] - 1) / 2 * freqs[0];
  }
  if (mins[0] == mins[1] && mins[1] == mins[2]) {
    cout << freqs[0] * (freqs[0] - 1) * (freqs[0] - 2) / 6;
  }
  cout << endl;
}
