#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
void fast() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
}
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b != 0) {
    if (b % 2 == 1) {
      ans *= a;
    }
    b /= 2;
    a *= a;
  }
  return ans;
}
long long int invmod(long long int a) { return pow(a, mod - 2); }
void print(int a[], int n) {
  for (int i = 0; i < n; i++) cout << a[i] << " ";
}
long long int a[100005];
vector<long long int> v;
pair<long long int, long long int> mnl[100005];
pair<long long int, long long int> mnr[100005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  sort(a, a + n);
  long long int mn = INT_MAX, ct = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < mn) {
      mnl[i].first = a[i];
      mnl[i].second = 1;
      mn = a[i];
      ct = mnl[i].second;
    } else if (a[i] == mn) {
      mnl[i].first = a[i];
      mnl[i].second = ++ct;
    } else {
      mnl[i].first = mnl[i - 1].first;
      mnl[i].second = mnl[i - 1].second;
    }
  }
  mn = INT_MAX, ct = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] < mn) {
      mnr[i].first = a[i];
      mnr[i].second = 1;
      mn = a[i];
      ct = mnr[i].second;
    } else if (a[i] == mn) {
      mnr[i].first = a[i];
      mnr[i].second = ++ct;
    } else {
      mnr[i].first = mnr[i + 1].first;
      mnr[i].second = mnr[i + 1].second;
    }
  }
  v.push_back(a[0]), v.push_back(a[1]), v.push_back(a[2]);
  long long int ans = 0;
  for (int i = 1; i <= n - 2; i++) {
    if (a[i] == v[1] && mnl[i - 1].first == v[0] && mnr[i + 1].first == v[2]) {
      ans += (mnl[i - 1].second * mnr[i + 1].second * 1LL);
    }
  }
  cout << ans << endl;
  return 0;
}
