use std::{ i64::{MAX, MIN}, io::stdin, }; fn main() { let mut stdin = stdin().lines().map(Result::unwrap); let n = stdin.next().unwrap().parse::().unwrap(); let a = stdin .next() .unwrap() .split_whitespace() .map(|x| x.parse::().unwrap()) .collect::>(); let mut dp = vec![vec![[MAX, MIN]; n + 1]; n + 1]; for i in 0..n { dp[i][i + 1] = [a[i], a[i]]; } for l in (0..=n).rev() { for c in l + 1..n { let r = c + 1; for x in dp[l][c] { assert_ne!(x, MIN); assert_ne!(x, MAX); for y in dp[c][r] { assert_ne!(y, MIN); assert_ne!(y, MAX); for &z in &[x + y, x - y, x * y] { change_min!(&mut dp[l][r][0], z); change_max!(&mut dp[l][r][1], z); } } } } } let ans = dp[0][n][1]; println!("{}", ans); } // cmpmore {{{ #[allow(dead_code)] mod cmpmore { pub fn change_min(lhs: &mut T, rhs: T) { if *lhs > rhs { *lhs = rhs; } } pub fn change_max(lhs: &mut T, rhs: T) { if *lhs < rhs { *lhs = rhs; } } #[macro_export] macro_rules! change_min { ($lhs:expr, $rhs:expr) => { let rhs = $rhs; let lhs = $lhs; $crate::cmpmore::change_min(lhs, rhs); }; } #[macro_export] macro_rules! change_max { ($lhs:expr, $rhs:expr) => { let rhs = $rhs; let lhs = $lhs; $crate::cmpmore::change_max(lhs, rhs); }; } pub trait CmpMore: PartialOrd + Sized { fn change_min(&mut self, rhs: Self) { change_min(self, rhs) } fn change_max(&mut self, rhs: Self) { change_max(self, rhs) } } impl CmpMore for T {} } // }}}