object Main extends App {
	val Array(n, d) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val dp = Array.ofDim[Int](n, d)

	for(i<-0 until n){
		dp(i) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	}

	var ans = 0

	for(i<-0 until n-1){
		for(j<-i+1 until n){
			val tp = math.sqrt(dp(i).zip(dp(j)).map{case (a, b) => (a - b) * (a - b)}.sum)

			if(tp - tp.toInt == 0.0){
				ans += 1
			}
		}
	}

	println(ans)
}