package main import ( "bufio" "fmt" "math" "os" "strconv" ) func configure(scanner *bufio.Scanner) { scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) } func getNextString(scanner *bufio.Scanner) string { scanned := scanner.Scan() if !scanned { panic("scan failed") } 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 getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout extra := 0 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) extra = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() solve(scanner, writer) for i := 0; i < extra; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) aa := make([]int, n) for i := 0; i < n; i++ { aa[i] = getNextInt(scanner) } ll := make([]int, n) rr := make([]int, n) lll := make([]int, n) rrr := make([]int, n) yokubalis := make([]int, n) yokubalisugi := make([]int, n) yokubalisugiya := make([]int, n) yokubalisugiyaro := make([]int, n) for i := 0; i < n; i++ { yokubalis[i] = math.MaxInt32 yokubalisugi[i] = math.MaxInt32 } for i := 0; i < n; i++ { r := lower(n, aa[i], yokubalis, func(a, b int) bool { return a <= b }) ll[i] = r } for i := 0; i < n; i++ { r := lower(n, aa[i], yokubalisugiya, func(a, b int) bool { return a >= b }) lll[i] = r } for i := n - 1; i >= 0; i-- { r := lower(n, aa[i], yokubalisugi, func(a, b int) bool { return a <= b }) rr[i] = r } for i := n - 1; i >= 0; i-- { r := lower(n, aa[i], yokubalisugiyaro, func(a, b int) bool { return a >= b }) rrr[i] = r } var ans int for i := 0; i < n; i++ { ans = max(ans, min(ll[i], rr[i])) ans = max(ans, min(lll[i], rrr[i])) } fmt.Fprintln(writer, ans) } func min(a, b int) int { if a < b { return a } return b } func max(a, b int) int { return -min(-a, -b) } func lower(n, a int, yokubalis []int, less func(int, int) bool) int { l := -1 r := n for l+1 < r { m := (l + r) >> 1 if less(a, yokubalis[m]) { r = m continue } l = m } yokubalis[r] = a return r }