fun main(args: Array<String>) = shojin06a()

fun shojin06a() {
    val (n, d) = readLine()!!.split(' ').map { it.toInt() }
    val xList = (1..n).map { readLine()!!.split(' ').map { it.toInt() } }

    var answer = 0

    for (l in 0 until n) {
        for (r in l + 1 until n) {
            val left = xList[l]
            val right = xList[r]
            val sum = (0 until d).map { Math.pow(Math.abs(left[it] - right[it]).toDouble(), 2.0).toInt() }.sum()
            val sqrt = Math.sqrt(sum.toDouble())
            if (sqrt == Math.floor(sqrt)) answer++
        }
    }

    println(answer)
}
