← Home
 ```go
package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n, m int
	fmt.Fscan(in, &n, &m)
	var aStr, bStr string
	fmt.Fscan(in, &aStr)
	fmt.Fscan(in, &bStr)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = int(aStr[i] - '0')
	}
	b := make([]int, m)
	for i := 0; i < m; i++ {
		b[i] = int(bStr[i] - '0')
	}

	maxK := n - m + 1

	pi := make([]int, m)
	for i := 1; i < m; i++ {
		j := pi[i-1]
		for j > 0 && b[i] != b[j] {
			j = pi[j-1]
		}
		if b[i] == b[j] {
			j++
		}
		pi[i] = j
	}

	trans := make([][2]int, m)
	add := make([][2]int, m)
	for s := 0; s < m; s++ {
		for c := 0; c < 2; c++ {
			j := s
			for j > 0 && b[j] != c {
				j = pi[j-1]
			}
			if b[j] == c {
				j++
			}
			if j == m {
				add[s][c] = 1
				trans[s][c] = pi[m-1]
			} else {
				add[s][c] = 0
				trans[s][c] = j
			}
		}
	}

	inf := 1 << 30
	curr := make([][]int, maxK+1)
	next := make([][]int, maxK+1)
	for i := 0; i <= maxK; i++ {
		curr[i] = make([]int, m)
		next[i] = make([]int, m)
		for j := 0; j < m; j++ {
			curr[i][j] = inf
			next[i][j] = inf
		}
	}
	curr[0][0] = 0

	for i := 0; i < n; i++ {
		for j := 0; j <= maxK; j++ {
			for s := 0; s < m; s++ {
				next[j][s] = inf
			}
		}
		ach := a[i]
		for j := 0; j <= maxK; j++ {
			for s := 0; s < m; s++ {
				if curr[j][s] == inf {
					continue
				}
				for c := 0; c < 2; c++ {
					cost := 0
					if c != ach {
						cost = 1
					}
					nj := j + add[s][c]
					if nj > maxK {
						continue
					}
					ns := trans[s][c]
					if next[nj][ns] > curr[j][s]+cost {
						next[nj][ns] = curr[j][s] + cost
					}
				}
			}
		}
		curr, next = next, curr
	}

	ans := make([]int, maxK+1)
	for k := 0; k <= maxK; k++ {
		ans[k] = inf
		for s := 0; s < m; s++ {
			if curr[k][s] < ans[k] {
				ans[k] = curr[k][s]
			}
		}
	}

	for k := 0; k <= maxK; k++ {
		if k > 0 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, ans[k])
	}
	fmt.Fprintln(out)
}
```