#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
  return n | (1LL << i);
  ;
}
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long &a) {
  a %= 1000000007;
  (a < 0) && (a += 1000000007);
}
inline long long modMul(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a * b) % 1000000007;
}
inline long long modAdd(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  return (a + b) % 1000000007;
}
inline long long modSub(long long a, long long b) {
  a %= 1000000007, b %= 1000000007;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long modPow(long long b, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); }
inline long long modDiv(long long a, long long b) {
  return modMul(a, modInverse(b));
}
long long b[100001][4];
long long nCr(long long n, long long r) {
  if (b[n][r] == 0) {
    if (n == r) return 1;
    if (r == n - 1) return n;
    if (r == 1) return n;
    if (r == 0) return 1;
    b[n][r] = nCr(n - 1, r) + nCr(n - 1, r - 1);
  }
  return b[n][r];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  int a[n];
  int c = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  int p = 1;
  if (a[0] == a[2]) {
    for (p = 1; p < n; ++p) {
      if (a[p] == a[p - 1])
        ++c;
      else
        break;
    }
    long long temp = c;
    cout << nCr(temp, 3);
  } else if (a[1] == a[2]) {
    for (p = 2; p < n; ++p) {
      if (a[p] == a[p - 1])
        ++c;
      else
        break;
    }
    long long temp = c;
    cout << nCr(temp, 2);
  } else {
    for (p = 3; p < n; ++p) {
      if (a[p] == a[p - 1])
        ++c;
      else
        break;
    }
    long long temp = c;
    cout << nCr(temp, 1);
  }
}
