#[macro_use] mod io { use std::io::*; pub trait Scan { fn scan(sc: &mut Scanner) -> T; } macro_rules! scan_primitive { ($t: ty) => { impl Scan<$t> for $t { fn scan(sc: &mut Scanner) -> $t { sc.next_token().expect("EOF?").parse() .unwrap_or_else(|e| panic!("Cannot parse {}", e)) } } }; ($t: ty, $($u: ty),+) => { scan_primitive!($t); scan_primitive!($($u),+); }; } macro_rules! scan_tuple { ($($t: ident),*) => { impl< $($t: Scan<$t>),* > Scan< ( $($t),* ) > for ( $($t),* ) { fn scan(sc: &mut Scanner) -> ( $($t),* ) { ( $( $t::scan(sc)),* ) } } }; } scan_primitive!(u8, u16, u32, u64, i8, i16, i32, i64, f32, f64, usize, isize, bool, String); scan_tuple!(T, U); scan_tuple!(T, U, V); scan_tuple!(T, U, V, W); #[allow(dead_code)] pub fn cin() -> Scanner { Scanner::new(stdin()) } #[allow(dead_code)] pub struct Scanner { buf: Vec, len: usize, idx: usize, reader: T, } #[allow(dead_code)] impl Scanner { pub fn new(r: Reader) -> Scanner { Scanner { buf: vec![0; 8192], len: 0, idx: 0, reader: r, } } pub fn next>(&mut self) -> T { T::scan::(self) } fn next_token(&mut self) -> Option { let mut res = String::with_capacity(16); while let Some(c) = self.get_u8() { let d = c as char; if !d.is_whitespace() { res.push(d); } else if res.len() != 0 { self.unget_u8(c); break; } } if res.len() == 0 { None } else { Some(res) } } pub fn next_line(&mut self) -> String { self.next_line_wrapped().unwrap() } pub fn next_line_wrapped(&mut self) -> Option { let c = self.get_u8(); if c.is_none() { return None; } let mut line = String::with_capacity(20); line.push(c.unwrap() as char); loop { let c = self.get_u8(); if c.is_none() || c.unwrap() == b'\n' { // コメントはC++等での仕様 // if c.is_some() { // self.unget_u8(b'\n'); // } return Some(line); } line.push(c.unwrap() as char); } } pub fn has_next(&mut self) -> bool { loop { let c = self.get_u8(); if c.is_none() { return false; } let c = c.unwrap(); if !(c as char).is_whitespace() { self.unget_u8(c); return true; } } } fn get_u8(&mut self) -> Option { if self.idx == self.len { match self.reader.read(&mut self.buf[..]) { Ok(l) if l > 0 => { self.idx = 0; self.len = l; } _ => return None, } } self.idx += 1; Some(self.buf[self.idx - 1]) } fn unget_u8(&mut self, c: u8) { self.idx = self.idx - 1; self.buf[self.idx] = c; } } // Output macro_rules! dump { ($($a: expr),+) => {{ use std::io::*; write!(stderr(), "{}:{}\t", file!(), line!()).unwrap(); dump!(A $($a),+); write!(stderr(), " = ").unwrap(); dump!(B $($a),+); writeln!(stderr(), "").unwrap(); }}; (A $x: expr) => { write!(stderr(), "{}", stringify!($x)).unwrap(); }; (A $x: expr, $($y: expr),+) => { write!(stderr(), "{}, ", stringify!($x)).unwrap(); dump!(A $($y),+); }; (B $x: expr) => { write!(stderr(), "{:?}", $x).unwrap(); }; (B $x: expr, $($y: expr),+) => { write!(stderr(), "{:?}, ", $x).unwrap(); dump!(B $($y),+); }; } macro_rules! p { ($x:expr) => { println!("{:.10}", $x); }; ($x:expr, $($y:expr),+) => { print!("{:.10} ", $x); p!($($y),+); }; } } #[allow(unused_imports)] use io::*; use std::*; fn main() { let mut sc = cin(); while sc.has_next() { let n = sc.next(); let (mut min, mut max) = (0, 0); for i in 0..n { let a: i64 = sc.next(); if i == 0 { min = a; max = a; } else { //dump!(a); let (mut mi, mut ma) = (i64::max_value() / 10, i64::min_value() / 10); mi = cmp::min(mi, min*a); mi = cmp::min(mi, min+a); mi = cmp::min(mi, min-a); if a != 0 { mi = cmp::min(mi, min/a); } ma = cmp::max(ma, max*a); ma = cmp::max(ma, max+a); ma = cmp::max(ma, max-a); if a != 0 { ma = cmp::max(ma, max/a); } mi = cmp::min(mi, max*a); mi = cmp::min(mi, max+a); mi = cmp::min(mi, max-a); if a != 0 { mi = cmp::min(mi, max/a); } ma = cmp::max(ma, min*a); ma = cmp::max(ma, min+a); ma = cmp::max(ma, min-a); if a != 0 { ma = cmp::max(ma, min/a); } min = mi; max = ma; //dump!(min, max); } } p!(max); } }