using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int itemCount = int.Parse(Reader.ReadLine()); this.Items = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.GetAns(1, this.Items[0]); Console.WriteLine(this.dic[itemCount - 1][true]); } private void GetAns(int idx, long subTotal) { if (idx >= this.Items.Length) { if (dic.ContainsKey(idx)) { dic[idx][true] = Math.Max(dic[idx][true], subTotal); dic[idx][false] = Math.Min(dic[idx][false], subTotal); } else { dic.Add(idx, new Dictionary()); dic[idx][true] = subTotal; dic[idx][false] = subTotal; } return; } long min = long.MaxValue; long max = long.MinValue; int num = Items[idx]; min = Math.Min(min, subTotal + num); min = Math.Min(min, subTotal - num); min = Math.Min(min, subTotal * num); max = Math.Max(max, subTotal + num); max = Math.Max(max, subTotal - num); max = Math.Max(max, subTotal * num); if (num != 0) { min = Math.Min(min, subTotal / num); max = Math.Max(max, subTotal / num); } if (!dic.ContainsKey(idx)) { dic.Add(idx, new Dictionary()); } if((!dic[idx].ContainsKey(true)) || (dic[idx][true] < max)) { dic[idx][true] = max; this.GetAns(idx + 1, max); } if ((!dic[idx].ContainsKey(false)) || dic[idx][false] > min) { dic[idx][false] = min; GetAns(idx + 1, min); } } private int[] Items; private Dictionary> dic = new Dictionary>(); public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 16 6 9 1 2 1 2 1 2 1 4 1 4 1 8 1 2 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }