← Home
For problem statement at 0-999/600-699/650-659/652/problemC.txt this is a correct solution, but verifier at 0-999/600-699/650-659/652/verifierC.go ends with All tests passed! can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	next := func() int {
		scanner.Scan()
		val, _ := strconv.Atoi(scanner.Text())
		return val
	}

	n := next()
	m := next()

	pos := make([]int, n+1)
	for i := 0; i < n; i++ {
		val := next()
		pos[val] = i
	}

	// maxStart[j] stores the maximum index i such that (i, j) corresponds to a foe pair with i < j.
	// This means if an interval ends at j, it cannot start at or before maxStart[j].
	maxStart := make([]int, n)
	for i := range maxStart {
		maxStart[i] = -1
	}

	for i := 0; i < m; i++ {
		u := next()
		v := next()
		idx1 := pos[u]
		idx2 := pos[v]

		if idx1 > idx2 {
			idx1, idx2 = idx2, idx1
		}

		if idx1 > maxStart[idx2] {
			maxStart[idx2] = idx1
		}
	}

	var ans int64
	// leftBound represents the rightmost index that is invalid as a start point for the current range.
	// Valid start indices x are in the range (leftBound, right].
	leftBound := -1

	for right := 0; right < n; right++ {
		if maxStart[right] > leftBound {
			leftBound = maxStart[right]
		}
		ans += int64(right - leftBound)
	}

	fmt.Println(ans)
}
```