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

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

type FastReader struct {
	r *bufio.Reader
}

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

func (fr *FastReader) NextInt64() int64 {
	sign := int64(1)
	val := int64(0)
	c, err := fr.r.ReadByte()
	for (c < '0' || c > '9') && c != '-' {
		if err != nil {
			return 0
		}
		c, err = fr.r.ReadByte()
	}
	if c == '-' {
		sign = -1
		c, err = fr.r.ReadByte()
	}
	for c >= '0' && c <= '9' {
		val = val*10 + int64(c-'0')
		c, err = fr.r.ReadByte()
		if err != nil {
			break
		}
	}
	return val * sign
}

func prefixFunc(p []int64) []int {
	n := len(p)
	pi := make([]int, n)
	for i := 1; i < n; i++ {
		j := pi[i-1]
		for j > 0 && p[i] != p[j] {
			j = pi[j-1]
		}
		if p[i] == p[j] {
			j++
		}
		pi[i] = j
	}
	return pi
}

func kmpSearch(t, p []int64) []int {
	pi := prefixFunc(p)
	res := []int{}
	j := 0
	for i := 0; i < len(t); i++ {
		for j > 0 && t[i] != p[j] {
			j = pi[j-1]
		}
		if t[i] == p[j] {
			j++
		}
		if j == len(p) {
			res = append(res, i-len(p)+1)
			j = pi[j-1]
		}
	}
	return res
}

func main() {
	fr := NewFastReader()
	N64 := fr.NextInt64()
	M := fr.NextInt64()
	N := int(N64)
	a := make([]int64, N)
	for i := 0; i < N; i++ {
		a[i] = fr.NextInt64()
	}
	g := make([]int64, N)
	for i := 0; i < N-1; i++ {
		g[i] = a[i+1] - a[i]
	}
	g[N-1] = a[0] + M - a[N-1]
	p := make([]int64, N)
	for i := 0; i < N; i++ {
		p[i] = g[N-1-i]
	}
	t := make([]int64, 2*N)
	copy(t, g)
	copy(t[N:], g)
	matches := kmpSearch(t, p)
	resMap := make(map[int64]struct{})
	for _, s := range matches {
		if s < N {
			i1 := s
			i2 := (s + 1) % N
			r := (a[i1] + a[i2]) % M
			resMap[r] = struct{}{}
		}
	}
	res := make([]int64, 0, len(resMap))
	for v := range resMap {
		res = append(res, v)
	}
	sort.Slice(res, func(i, j int) bool { return res[i] < res[j] })
	w := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer w.Flush()
	fmt.Fprintln(w, len(res))
	if len(res) > 0 {
		for i, v := range res {
			if i > 0 {
				fmt.Fprint(w, " ")
			}
			fmt.Fprint(w, v)
		}
		fmt.Fprintln(w)
	}
}
```