package main import ( "bufio" "fmt" "os" "sort" "strconv" ) func out(x ...interface{}) { fmt.Println(x...) } var sc = bufio.NewScanner(os.Stdin) func getInt() int { sc.Scan() i, e := strconv.Atoi(sc.Text()) if e != nil { panic(e) } return i } func getInts(N int) []int { ret := make([]int, N) for i := 0; i < N; i++ { ret[i] = getInt() } return ret } func getString() string { sc.Scan() return sc.Text() } // min, max, asub, absなど基本関数 func max(a, b int) int { if a > b { return a } return b } func min(a, b int) int { if a < b { return a } return b } func asub(a, b int) int { if a > b { return a - b } return b - a } func abs(a int) int { if a >= 0 { return a } return -a } func lowerBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] >= x }) return idx } func upperBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] > x }) return idx } var N int var A []int var memo [3001][3001][2]int func rec(l, r, lr int) int { // out(l, r, lr) if l < 0 || r >= N { return 0 } if memo[l][r][lr] != -1 { return memo[l][r][lr] } ret := 0 if lr == 0 { for i := r; i < N; i++ { if A[i] < A[l] { ret = max(ret, rec(l, i, 1)+1) } } } else { for i := l; i >= 0; i-- { if A[i] < A[r] { ret = max(ret, rec(i, r, 0)+1) } } } memo[l][r][lr] = ret return ret } func main() { sc.Split(bufio.ScanWords) N = getInt() A = getInts(N) for i := 0; i < 3001; i++ { for j := 0; j < 3001; j++ { for k := 0; k < 2; k++ { memo[i][j][k] = -1 } } } ret := 0 for i := 0; i < N; i++ { for j := 0; j < 2; j++ { ret = max(ret, rec(i, i, j)) } } out(ret + 1) }