fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }
    var a = 0
    val l = mutableListOf<List<Int>>()
    val newl = Array<Int>(y,{0})
    for (i in 0 until x) {
        l.add(readLine()!!.split(" ").map{ it.toInt()})
    }
    for(i in 0 until x - 1)for (j in i + 1 until x) {
        for (k in 0 until y) {
            newl[k] = Math.pow((l[i][k] - l[j][k]).toDouble(), 2.0).toInt()
        }
        if (Math.sqrt(newl.sum().toDouble()) % 1.0 == 0.0) a += 1
    }
    println(a)
}