fun main(args:Array<String>){
    val line = readLine()!!.split(" ").map{it.toInt()}
    val n = line[0]
    val d = line[1]
    val list = mutableListOf<List<Int>>()
    for(i in 1..n){
        list.add(readLine()!!.split(" ").map{it.toInt()})
    }
    var result = 0
    for(i in 0..n-2){
        for(ii in i+1..n-1){
            var num = 0
            val a = list[i]
            val b = list[ii]
            for(iii in 0..d-1){
                num += (a[iii]-b[iii])*(a[iii]-b[iii])
            }
            for(x in 0..160){
                if(num == x*x){
                    result++
                    break
                }
            }
        }
    }
    println(result)
}