import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int n = in.nextInt();
long[] list = new long[n];
long max = 0;
long max1 = 0;
long max2 = 0;
for(int i = 0;i<n;i++){
list[i] = in.nextInt();
}
//数组排序后无论是否有负数,最终都在最后三个或者最后一个前面2个里面中的一个选,用max判断下即可
Arrays.sort(list);
max1 = list[0]*list[1]*list[n-1];
max2 = list[n-1]*list[n-2]*list[n-3];
max = Math.max(max1,max2);
System.out.println(max);
}
}
}