← Home
package main

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

const INF = 1e9

type Transition struct {
	occ int
	nj  int
}

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 a, b string
	fmt.Fscan(in, &a, &b)

	nxt := make([][2]Transition, m)
	for j := 0; j < m; j++ {
		for c := 0; c < 2; c++ {
			S := b[:j] + string(byte('0'+c))
			occ := 0
			nj := 0
			for L := len(S); L >= 0; L-- {
				if L <= m {
					if S[len(S)-L:] == b[:L] {
						if L == m {
							occ = 1
						} else {
							nj = L
							break
						}
					}
				}
			}
			nxt[j][c] = Transition{occ, nj}
		}
	}

	maxK := n - m + 1
	dp := make([][]int32, m)
	for i := range dp {
		dp[i] = make([]int32, maxK+2)
		for j := range dp[i] {
			dp[i][j] = INF
		}
	}
	dp[0][0] = 0

	for i := 0; i < n; i++ {
		nextDp := make([][]int32, m)
		for j := range nextDp {
			nextDp[j] = make([]int32, maxK+2)
			for k := range nextDp[j] {
				nextDp[j][k] = INF
			}
		}

		for j := 0; j < m; j++ {
			for k := 0; k <= i && k <= maxK; k++ {
				val := dp[j][k]
				if val == INF {
					continue
				}

				c0Cost := val
				if a[i] != '0' {
					c0Cost++
				}
				t0 := nxt[j][0]
				nk0 := k + t0.occ
				if nk0 <= maxK && nextDp[t0.nj][nk0] > c0Cost {
					nextDp[t0.nj][nk0] = c0Cost
				}

				c1Cost := val
				if a[i] != '1' {
					c1Cost++
				}
				t1 := nxt[j][1]
				nk1 := k + t1.occ
				if nk1 <= maxK && nextDp[t1.nj][nk1] > c1Cost {
					nextDp[t1.nj][nk1] = c1Cost
				}
			}
		}
		dp = nextDp
	}

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