fun main(args : Array<String>) {
    val (N, D) = readLine()!!.split(" ").map { it.toInt() }
    val X = mutableListOf<List<Double>>()
    (1..N).forEach {
        val x = readLine()!!.split(" ").map { it.toDouble() }
        X.add(x)
    }

    var count = 0
    (0..(N-1)).forEach { i ->
        ((i+1)..(N-1)).forEach { j ->
            val a = X[i]
            val b = X[j]
            var distance = 0.0
            (0..(D-1)).forEach { d->
                distance += (a[d] - b[d]) * (a[d] - b[d])
            }
            val sqrt = Math.sqrt(distance)
            if (sqrt - sqrt.toInt() == 0.0) {
                count++
            }
        }
    }
    println(count)
}