import java.lang.Math.sqrt

fun main(args: Array<String>) {
    val (n, d) = readLine()!!.split(' ').map(String::toInt)
    val vs = (1..n).map{readLine()!!.split(' ').map(String::toInt)}
    print(vs.indices.flatMap { i -> (i+1 until n).map { j ->
        val xi = vs[i]
        val xj = vs[j]
        (0 until d).map{k ->
            val y = xi[k]
            val z = xj[k]
            (y - z) * (y - z)
        }.sum()
    }.filter { s ->
        s == sqrt(s.toDouble()).toInt() * sqrt(s.toDouble()).toInt()
    }
    }.size)
}