← Home
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) NextInt64() int64 {
	var sign int64 = 1
	var val int64
	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 + int64(c-'0')
		c, _ = fs.r.ReadByte()
	}
	fs.r.UnreadByte()
	return val * sign
}

func prefixFunction(p []int64) []int {
	pi := make([]int, len(p))
	for i := 1; i < len(p); 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 main() {
	in := NewFastScanner()
	n := int(in.NextInt64())
	w := int(in.NextInt64())

	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = in.NextInt64()
	}
	b := make([]int64, w)
	for i := 0; i < w; i++ {
		b[i] = in.NextInt64()
	}

	if w == 1 {
		fmt.Println(n)
		return
	}
	if w > n {
		fmt.Println(0)
		return
	}

	da := make([]int64, n-1)
	for i := 0; i < n-1; i++ {
		da[i] = a[i+1] - a[i]
	}
	db := make([]int64, w-1)
	for i := 0; i < w-1; i++ {
		db[i] = b[i+1] - b[i]
	}

	pi := prefixFunction(db)
	ans := 0
	j := 0
	for i := 0; i < len(da); i++ {
		for j > 0 && da[i] != db[j] {
			j = pi[j-1]
		}
		if da[i] == db[j] {
			j++
		}
		if j == len(db) {
			ans++
			j = pi[j-1]
		}
	}

	fmt.Println(ans)
}