fun main(args:Array<String>) {
    val mod = 1000000007L
    val (N, D) = readLine()!!.split(" ").map(String::toInt)

    val A = Array(N){ readLine()!!.split(" ").map { it.toInt() }.toIntArray()}

    fun dist(Y:IntArray , Z:IntArray ):Int  {
        var res = 0

        for((y,z) in Y.zip(Z))
            res += Math.pow(Math.abs(y-z).toDouble(),2.0).toInt()

        return res
    }

    var ans = 0

    val list = IntArray(200){it*it}

    for (i in 0 until N-1)
        for (j in i+1 until N) {
            val dist = dist(A[i], A[j])
            for (k in list) {
                if (k == dist) ans++
                if (k >= dist) break
            }
        }

    println(ans)
}