#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, a[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  sort(a + 1, a + 1 + n);
  if (a[1] == a[2] && a[2] == a[3]) {
    int cnt = 0;
    for (int i = 1; i <= n; ++i)
      if (a[i] != a[1])
        break;
      else
        cnt++;
    printf("%I64d\n", 1ll * cnt * (cnt - 1) * (cnt - 2) / 6);
  } else if (a[1] == a[2] && a[2] != a[3]) {
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] == a[1]) cnt1++;
      if (a[i] == a[3]) cnt2++;
    }
    printf("%I64d\n", 1ll * cnt1 * (cnt1 - 1) / 2 * cnt2);
  } else if (a[1] != a[2] && a[2] == a[3]) {
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] == a[2]) cnt1++;
      if (a[i] == a[1]) cnt2++;
    }
    printf("%I64d\n", 1ll * cnt1 * (cnt1 - 1) / 2 * cnt2);
  } else {
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] == a[1]) cnt1++;
      if (a[i] == a[2]) cnt2++;
      if (a[i] == a[3]) cnt3++;
    }
    printf("%I64d\n", 1ll * cnt1 * cnt2 * cnt3);
  }
  return 0;
}
