import java.util.*;
public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); if (n < 3) return;
in.nextLine();
String[] str = in.nextLine().split(" ");
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = Long.valueOf(str[i]);
}
System.out.println(getMaxProduct(arr, n));
}
public static long getMaxProduct(long[] arr, int n) {
if (n == 3) {
return arr[0] * arr[1] * arr[2];
}
long max1 = Integer.MIN_VALUE, max2 = Integer.MIN_VALUE,
max3 = Integer.MIN_VALUE, min1 = Integer.MAX_VALUE, min2 = Integer.MAX_VALUE;
long res = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
if (arr[i] > max1) {
max3 = max2;
max2 = max1;
max1 = arr[i];
} else if (arr[i] > max2) {
max3 = max2;
max2 = arr[i];
} else if (arr[i] > max3) {
max3 = arr[i];
}
if (arr[i] < min1) {
min2 = min1;
min1 = arr[i];
} else if (arr[i] < min2) {
min2 = arr[i];
}
}
res = Math.max(max1 * max2 * max3, min1 * min2 * max1);
return res ;
}
}