fun main(args:Array<String>) {
    val (n,d) = readLine()!!.split(" ").map { it.toInt() }
    pointList.addAll((1..n).map { readLine()!!.split(" ").map { it.toInt() } })
    var ans = 0
    for(i in (0 until pointList.size - 1)) {
        for(j in (i+1 until pointList.size)) {
            if(dist(pointList[i], pointList[j])) {
                ans++
            }
        }
    }
    println(ans)
}

val pointList = mutableListOf<List<Int>>()
fun dist(pos1:List<Int>, pos2:List<Int>):Boolean {
    var dist = 0
    for(i in pos1.indices) {
        dist += (pos1[i]-pos2[i])*(pos1[i]-pos2[i])
    }
    val tmp = Math.sqrt(dist.toDouble()).toInt()
    return tmp*tmp == dist
}
