fun main(arr: Array<String>) {
    val (n,d) = readLine()!!.split(" ").map { it.toInt() }
    val pos = (1..n).map { readLine()!!.split(" ").map { it.toInt() } }
    val ans = pos.indices.map{ idx-> pos.indices.count { idx2 -> (idx!=idx2) && (isSquare(getDist(pos[idx], pos[idx2]))) } }.sum()
    println(ans/2)
}

fun getDist(pos1:List<Int>, pos2:List<Int>):Int {
    return pos1.indices.map { (pos1[it]-pos2[it])*(pos1[it]-pos2[it]) }.sum()
}
fun isSquare(num:Int):Boolean {
    for(i in (1..num)) {
        val tmp = i*i
        if(tmp == num) {
            return true
        }
        if(tmp > num) {
            break
        }
    }
    return false
}
