fun main(args: Array<String>) {
    val input = System.`in`.reader().readLines().map { it.split(" ").map(String::toInt) }
    val (n, d) = input[0]
    val posList = input.subList(1, input.size)

    var result = 0
    for (i in 0..(n - 1)) {
        for (j in (i + 1)..(n - 1)) {
            var cord = 0.0
            for (c in 0..(d - 1)) {
                cord += Math.pow(Math.abs(posList[i][c] - posList[j][c]).toDouble(), 2.0)
            }
            if (Math.sqrt(cord) == Math.sqrt(cord).toInt().toDouble()) {
                result++
            }
        }
    }
    println(result)
}