fun main(args: Array<String>) {
    val (N, D) = readLine()!!.split(" ").map { Integer.parseInt(it) }
    val pointsList = mutableListOf<List<Int>>()
    for (i in 0 until N) {
        val list2add = readLine()!!.split(" ").map { Integer.parseInt(it) }
        pointsList.add(list2add)
    }
    var result = 0
    for (i in 0 until N) {
        for (j in i + 1 until N) {
            var sumPowerd = 0
            for (k in 0 until D) {
                sumPowerd +=
                    Math.abs(pointsList[i][k] - pointsList[j][k]) * Math.abs(pointsList[i][k] - pointsList[j][k])
            }
            val distance = Math.sqrt(sumPowerd.toDouble())
            if (Math.floor(distance) == distance) {
                result++
            }
        }

    }
    println(result)
}
