← Home
For problem statement at 1000-1999/1700-1799/1740-1749/1741/problemD.txt this is a correct solution, but verifier at 1000-1999/1700-1799/1740-1749/1741/verifierD.go ends with All tests passed can you fix the verifier? ```go
package main

import (
	"io"
	"os"
	"strconv"
	"strings"
)

func dfs(a []int, l, r int) (int, int, int, bool) {
	if r-l == 1 {
		return a[l], a[l], 0, true
	}
	m := (l + r) >> 1
	lmin, lmax, lops, ok := dfs(a, l, m)
	if !ok {
		return 0, 0, 0, false
	}
	rmin, rmax, rops, ok := dfs(a, m, r)
	if !ok {
		return 0, 0, 0, false
	}
	minv := lmin
	if rmin < minv {
		minv = rmin
	}
	maxv := lmax
	if rmax > maxv {
		maxv = rmax
	}
	ops := lops + rops
	if lmax < rmin {
		return minv, maxv, ops, true
	}
	if rmax < lmin {
		return minv, maxv, ops + 1, true
	}
	return 0, 0, 0, false
}

func main() {
	data, _ := io.ReadAll(os.Stdin)
	idx := 0
	nextInt := func() int {
		for idx < len(data) && (data[idx] < '0' || data[idx] > '9') {
			idx++
		}
		n := 0
		for idx < len(data) && data[idx] >= '0' && data[idx] <= '9' {
			n = n*10 + int(data[idx]-'0')
			idx++
		}
		return n
	}

	t := nextInt()
	var out strings.Builder

	for i := 0; i < t; i++ {
		m := nextInt()
		a := make([]int, m)
		for j := 0; j < m; j++ {
			a[j] = nextInt()
		}
		_, _, ops, ok := dfs(a, 0, m)
		if ok {
			out.WriteString(strconv.Itoa(ops))
		} else {
			out.WriteString("-1")
		}
		if i+1 < t {
			out.WriteByte('\n')
		}
	}

	os.Stdout.WriteString(out.String())
}
```