'use strict'

const main = input => {
	const args = input.trim().split('\n')
	const t1 = args[0].split(' ').map(Number)
	const d = t1[1]
	const x = []
	let cnt = 0

	for (let i = 1; i < args.length; i++) {
		x.push(args[i].split(' '))
	}

	for (let i = 0; i < x.length; i++) {
		const cur = x[i]
		const nxt = x[(i + 1) % x.length]
		let t = 0

		for (let j = 0; j < cur.length; j++) {
			t += Math.pow(cur[j] - nxt[j], 2)
		}

		if (Math.sqrt(t) % 1 === 0) cnt++
	}

	if (d === 1) console.log(cnt * 2)
	else console.log(cnt)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
