fun main(args: Array<String>) {
    val nd = readLine()!!.split(" ").map { it.toInt() }
    val x = mutableListOf<List<Int>>()
    for (i in 0 until nd[0]){
        x.add(readLine()!!.split(" ").map { it.toInt() })
    }
    var count = 0
    for (i in 0 until nd[0]){
        for (j in i+1 until nd[0]){
            var tmp = 0
            for (k in 0 until nd[1]){
                tmp += (x[i][k] - x[j][k])*(x[i][k] - x[j][k])
            }
            var tmp1 = Math.sqrt(tmp.toDouble())
            if (tmp1.toInt().toDouble() == tmp1)count++
        }
    }
    println(count)
}
