← Home
For problem statement at 1000-1999/1400-1499/1460-1469/1466/problemG.txt this is a correct solution, but verifier at 1000-1999/1400-1499/1460-1469/1466/verifierG.go ends with All 100 tests passed can you fix the verifier? ```go
package main

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

var scanner *bufio.Scanner

func nextToken() string {
	scanner.Scan()
	return scanner.Text()
}

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

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

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1024*1024), 10*1024*1024)
	scanner.Split(bufio.ScanWords)

	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	n := nextInt()
	q := nextInt()

	s0 := nextToken()
	t := nextToken()

	MOD := int64(1e9 + 7)

	S_arr := make([]string, 0)
	S_arr = append(S_arr, s0)
	for len(S_arr[len(S_arr)-1]) < 1000000 && len(S_arr)-1 < n {
		prev := S_arr[len(S_arr)-1]
		i := len(S_arr) - 1
		next := prev + string(t[i]) + prev
		S_arr = append(S_arr, next)
	}
	M := len(S_arr) - 1

	p2 := make([]int64, n+1)
	p2[0] = 1
	for i := 1; i <= n; i++ {
		p2[i] = (p2[i-1] * 2) % MOD
	}

	C := make([][26]int64, n+1)
	for i := 1; i <= n; i++ {
		for c := 0; c < 26; c++ {
			C[i][c] = (C[i-1][c] * 2) % MOD
			if int(t[i-1]-'a') == c {
				C[i][c] = (C[i][c] + 1) % MOD
			}
		}
	}

	for i := 0; i < q; i++ {
		k := nextInt()
		w := nextToken()

		m := 0
		for m <= M && len(S_arr[m]) < len(w)-1 {
			m++
		}

		if k < m {
			fmt.Fprintln(out, 0)
			continue
		}

		pi := getPi(w)
		ans := int64(0)

		s_m := S_arr[m]
		j := 0
		for x := 0; x < len(s_m); x++ {
			for j > 0 && s_m[x] != w[j] {
				j = pi[j-1]
			}
			if s_m[x] == w[j] {
				j++
			}
			if j == len(w) {
				ans++
				j = pi[j-1]
			}
		}

		ans = (ans * p2[k-m]) % MOD

		if k > m {
			S_str := s_m[len(s_m)-(len(w)-1):]
			P_str := s_m[:len(w)-1]

			j_after_S := 0
			for x := 0; x < len(S_str); x++ {
				for j_after_S > 0 && S_str[x] != w[j_after_S] {
					j_after_S = pi[j_after_S-1]
				}
				if S_str[x] == w[j_after_S] {
					j_after_S++
				}
			}

			for c := 0; c < 26; c++ {
				W := (C[k][c] - C[m][c]*p2[k-m]) % MOD
				if W < 0 {
					W += MOD
				}
				if W == 0 {
					continue
				}

				count := int64(0)
				curr_j := j_after_S

				char_c := byte('a' + c)
				for curr_j > 0 && char_c != w[curr_j] {
					curr_j = pi[curr_j-1]
				}
				if char_c == w[curr_j] {
					curr_j++
				}
				if curr_j == len(w) {
					count++
					curr_j = pi[curr_j-1]
				}

				for x := 0; x < len(P_str); x++ {
					for curr_j > 0 && P_str[x] != w[curr_j] {
						curr_j = pi[curr_j-1]
					}
					if P_str[x] == w[curr_j] {
						curr_j++
					}
					if curr_j == len(w) {
						count++
						curr_j = pi[curr_j-1]
					}
				}

				ans = (ans + W*count) % MOD
			}
		}

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