
import java.lang.String
import java.math.BigDecimal


fun main() {
    val (n, d) = readLine()!!.split(" ").map { it.toInt() }
    val x= Array(n){ readLine()!!.split(" ").map { it.toInt() }.toIntArray()}
    fun dist(a: IntArray, b: IntArray):Boolean{
        var d=0
        for (i in 0 until a.size){
            d+=(a[i]-b[i])*(a[i]-b[i])
        }

        val bigDecimal = BigDecimal(String.valueOf( Math.sqrt(d.toDouble()) ))
        val intValue: Int = bigDecimal.toInt()
        val sub=bigDecimal.subtract(
            BigDecimal(intValue)
        ).toDouble()
        if (sub==0.toDouble()){
            return true
        }
        return false
    }
    var ans=0
    for (i in 0 until n){
        for (j in i+1 until n){
            if (dist(x[i], x[j])){ans++}
        }
    }
    println(ans)
}