import java.math.*

fun main(args: Array<String>) {
    val (N, D) = readLine()!!.split(" ").map(String::toInt)
    val list = (0 until N).map {
        readLine()!!.split(" ").map(String::toInt)
    }

    var count = 0

    for (i in 0 until N - 1) {
        for (j in i + 1 until N) {
            var sum = 0.0
            for (k in 0 until D) {
                sum += (list[i][k] - list[j][k]) * (list[i][k] - list[j][k])
            }
            val distance = Math.sqrt(sum)
            if(distance.isDecimal().not()) {
                count++
            }
        }
    }

    println(count)


}

fun Double.isDecimal(): Boolean = ((this - Math.floor(this)) != 0.0)
