fun main(args: Array<String>) {
    val (N, D) = listOfInt()
    val X = Array<List<Int>>(N) { listOfInt() }
    var ans = 0
    for (a in 0 until N-1) {
        for (b in a+1 until N) {
            var sum = 0
            for (n in 0 until D) {
                val d = Math.abs(X[a][n] - X[b][n])
                sum += (d * d)
            }
            val q = Math.floor(Math.sqrt(sum.toDouble())).toInt()
            if (sum == (q * q)) ans++
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
