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

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

type FastScanner struct {
	r *bufio.Reader
}

func NewFastScanner() *FastScanner {
	return &FastScanner{r: bufio.NewReaderSize(os.Stdin, 1<<20)}
}

func (fs *FastScanner) nextInt() int {
	sign := 1
	val := 0
	c, _ := fs.r.ReadByte()
	for (c < '0' || c > '9') && c != '-' {
		c, _ = fs.r.ReadByte()
	}
	if c == '-' {
		sign = -1
		c, _ = fs.r.ReadByte()
	}
	for c >= '0' && c <= '9' {
		val = val*10 + int(c-'0')
		c, _ = fs.r.ReadByte()
	}
	return val * sign
}

func main() {
	fs := NewFastScanner()
	outw := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer outw.Flush()

	n := fs.nextInt()
	m := fs.nextInt()

	nexts := make([][]int, m)
	for i := 0; i < m; i++ {
		nexts[i] = make([]int, n+1)
		arr := make([]int, n)
		for j := 0; j < n; j++ {
			arr[j] = fs.nextInt()
		}
		for j := 0; j < n-1; j++ {
			x := arr[j]
			y := arr[j+1]
			nexts[i][x] = y
		}
		last := arr[n-1]
		nexts[i][last] = 0
	}

	out := make([]int, n+1)
	indeg := make([]int, n+1)

	for x := 1; x <= n; x++ {
		y := nexts[0][x]
		if y == 0 {
			continue
		}
		ok := true
		for i := 1; i < m; i++ {
			if nexts[i][x] != y {
				ok = false
				break
			}
		}
		if ok {
			out[x] = y
			indeg[y]++
		}
	}

	visited := make([]bool, n+1)
	var ans int64 = 0

	for x := 1; x <= n; x++ {
		if indeg[x] == 0 {
			cur := x
			length := 0
			for cur != 0 && !visited[cur] {
				visited[cur] = true
				length++
				cur = out[cur]
			}
			ans += int64(length*(length+1)) / 2
		}
	}

	for x := 1; x <= n; x++ {
		if !visited[x] {
			// Should not happen with valid construction; included for completeness (isolated nodes).
			ans += 1
			visited[x] = true
		}
	}

	fmt.Fprintln(outw, ans)
}
```