package main import ( "bufio" "fmt" "os" "strconv" ) func getScanner(fp *os.File) *bufio.Scanner { scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) return scanner } func getNextString(scanner *bufio.Scanner) string { scanner.Scan() return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextUint64(scanner *bufio.Scanner) uint64 { i, _ := strconv.ParseUint(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout cnt := 0 if os.Getenv("MASPY") == "ますピ" { fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT")) cnt = 3 } if os.Getenv("MASPYPY") == "ますピッピ" { wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10")) } scanner := getScanner(fp) writer := bufio.NewWriter(wfp) solve(scanner, writer) for i := 0; i < cnt; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } writer.Flush() } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) aa := make([]cint, n) for i := 0; i < n; i++ { aa[i] = cint(getNextInt64(scanner)) } dp := make([][2]cint, n) dp[0][0] = aa[0] dp[0][1] = aa[0] for i := 1; i < n; i++ { for j := 0; j < 2; j++ { dp[i][0].min(dp[i-1][j] + aa[i]) dp[i][0].min(dp[i-1][j] - aa[i]) dp[i][0].min(dp[i-1][j] * aa[i]) if aa[i] != 0 { dp[i][0].min(dp[i-1][j] / aa[i]) } dp[i][1].max(dp[i-1][j] + aa[i]) dp[i][1].max(dp[i-1][j] - aa[i]) dp[i][1].max(dp[i-1][j] * aa[i]) if aa[i] != 0 { dp[i][1].max(dp[i-1][j] / aa[i]) } } } fmt.Fprintln(writer, dp[n-1][1]) } type cint int64 func (x *cint) min(y cint) *cint { if *x > y { *x = y } return x } func (x *cint) max(y cint) *cint { if *x < y { *x = y } return x }