fun isInteger(value: Double): Boolean {
    return Math.ceil(value) == Math.floor(value)
}

fun main(args: Array<String>) {
    val (n, d) = readLine()!!.split(" ").map(String::toInt)
    var values = Array(n) { IntArray(d) }

    for (i in 0 until n) {
        val line = readLine()!!.split(" ").map(String::toInt)
        for (j in 0 until d) {
            values[i][j] = line[j]
        }
    }

    var count = 0;
    for (i in 0 until n) {
        for (j in i+1 until n) {
            if (i == j) continue

            var value = 0;
            for (k in 0 until d) {
                val v = values[i][k] - values[j][k]
                value += v*v
            }

            val result = Math.sqrt(value.toDouble())
            if (isInteger(result)) {
                count++
            }

        }
    }

    println(count)
}