fun main(args: Array<String>){
    val (n, d) = readLine()!!.split(" ").map { it.toInt() }
    var count = 0
    var xx = Array(n, { listOf(d) }).toList().toMutableList()
    for (i in 0 until n){
        xx[i] = readLine()!!.split(" ").map { it.toInt() }
    }
    for (i in 0 until n){
        for (j in i+1 until n){
            var distance = 0
            for (k in 0 until d){
                val a = xx[i][k] - xx[j][k]
                distance += a * a
            }
            for (k in 0 until 127){
                if (distance == k * k){
                    count++
                    break
                }
            }
        }
    }
    println(count)
}