fun main(args: Array<String>) {
    val (N, D) = readLine()!!.split(" ").map { it.toInt() }
    val points = mutableListOf<List<Int>>()
    var integerDistanceCount = 0
    for (i in 0 until N) {
        points.add(readLine()!!.split(" ").map { it.toInt() })
    }

    for (i in 0 until points.size) {
        for (j in 0 until points.size) {
            if (i < j) {
                val diff = pointsDistance(points[i], points[j], D)
                if (diff == Math.floor(diff)) {
                    integerDistanceCount += 1
                }
            }
        }
    }

    println(integerDistanceCount)
}

fun pointsDistance(p1: List<Int>, p2: List<Int>, dimensions: Int): Double {
    var distance = 0.0
    for (i in 0 until dimensions){
        distance += ((p1[i] - p2[i]) * (p1[i] - p2[i]))
    }

     return Math.sqrt(distance)
}