#include <stdio.h>
#define INT_MIN (-2147483647)
#define INT_MAX (2147483647)

int main() {
  int i, n, num;
  long long max_mul;
  long long max1 = INT_MIN, max2 = INT_MIN, max3 = INT_MIN;
  long long min1 = INT_MAX, min2 = INT_MAX;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &num);
    if (num < min1) {
      min2 = min1;
      min1 = num;
    } else if (num < min2) {
      min2 = num;
    }

    if (num > max1) {
      max3 = max2;
      max2 = max1;
      max1 = num;
    } else if (num > max2) {
      max3 = max2;
      max2 = num;
    } else if (num > max3) {
      max3 = num;
    }
  }
  max_mul = max1 * max2 * max3 > max1 * min1 * min2 ? max1 * max2 * max3 : max1 *
            min1 * min2;
  printf("%lld\n", max_mul);
  return 0;
}