fun main(args: Array<String>) {
    val (n, d) = readLine()!!.split(" ").map { it.toInt() }
    val xs = Array(n, { IntArray(d) })
    repeat(n) {
        xs[it] = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    }

    var ans = 0
    for (i in 0 until n) {
        for (j in i + 1 until n) {
            val d2 = (0 until d).map { xs[i][it] - xs[j][it] }.map { it * it }.sum()
            var r = 0
            while (r * r <= d2) {
                if (r * r == d2) {
                    ans++
                    break
                }
                r++
            }
        }
    }
    println(ans)
}