import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main { public static long MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); long[] as = new long[N]; for(int i = 0; i < N; i++){ as[i] = sc.nextLong(); } long min = as[0], max = as[0]; for(int i = 1; i < N; i++){ long curr_min = min + as[i]; long curr_max = max + as[i]; // + { curr_min = Math.min(curr_min, min + as[i]); curr_min = Math.min(curr_min, max + as[i]); curr_max = Math.max(curr_max, min + as[i]); curr_max = Math.max(curr_max, max + as[i]); } // - { curr_min = Math.min(curr_min, min - as[i]); curr_min = Math.min(curr_min, max - as[i]); curr_max = Math.max(curr_max, min - as[i]); curr_max = Math.max(curr_max, max - as[i]); } // * { curr_min = Math.min(curr_min, min * as[i]); curr_min = Math.min(curr_min, max * as[i]); curr_max = Math.max(curr_max, min * as[i]); curr_max = Math.max(curr_max, max * as[i]); } min = curr_min; max = curr_max; } System.out.println(max); } }