package main import ( "bufio" "fmt" "os" "strconv" ) type collection struct { index []int val []int cols []*collection } var sc = bufio.NewScanner(os.Stdin) var rdr = bufio.NewReaderSize(os.Stdin, 1000000) func main() { sc.Split(bufio.ScanWords) n := nextInt() var nums []int for i := 0; i < n; i++ { nums = append(nums, nextInt()) } c := &collection{ val: nums, } build(c) var f, s, t []*collection for _, v := range c.cols { if len(v.cols) == 0 { f = append(f, v) break } } if len(nums) < 9 { if f == nil { fmt.Println(-1) return } fmt.Println(trim(f[0].index)) return } for _, v := range c.cols { all := true for _, c := range v.cols { if len(c.cols) == 0 { all = false break } } if all { s = append(s, v) } } if len(nums) < 12 { if s == nil { fmt.Println(-1) return } fmt.Println(trim(s[0].index)) return } for _, v := range s { all := true for _, c := range v.cols { sub := false for _, r := range c.cols { if len(r.cols) == 0 { sub = true break } } if !sub { all = false break } } if all { t = append(t, v) } } if t == nil { fmt.Println(-1) return } fmt.Println(trim(t[0].index)) } func trim(a []int) string { s := fmt.Sprintf("%v", a) return s[1 : len(s)-1] } func build(c *collection) { for i := 0; i < len(c.val)-2; i++ { for j := i + 1; j < len(c.val)-1; j++ { for k := j + 1; k < len(c.val); k++ { if !check(c.val[i], c.val[j], c.val[k]) { continue } col := &collection{ index: []int{i, j, k}, } col.val = append(col.val, c.val[:i]...) col.val = append(col.val, c.val[i+1:j]...) col.val = append(col.val, c.val[j+1:k]...) col.val = append(col.val, c.val[k+1:]...) c.cols = append(c.cols, col) build(col) } } } } func check(a, b, c int) bool { if (b < a && a < c) || (c < a && a < b) { return true } if (a < c && c < b) || (b < c && c < a) { return true } return false } func nextLine() string { sc.Scan() return sc.Text() } func nextInt() int { i, _ := strconv.Atoi(nextLine()) return i } func nextInt64() int64 { i, _ := strconv.ParseInt(nextLine(), 10, 64) return i } func nextUint64() uint64 { i, _ := strconv.ParseUint(nextLine(), 10, 64) return i } func nextFloat() float64 { f, _ := strconv.ParseFloat(nextLine(), 64) return f } func readLine() string { buf := make([]byte, 0, 1000000) for { l, p, e := rdr.ReadLine() if e != nil { panic(e) } buf = append(buf, l...) if !p { break } } return string(buf) }