fun main(args:Array<String>){
    val (n,d) = readLine()!!.split(" ").map{it.toInt()}
    val a = Array(n){readLine()!!.split(" ").map{it.toInt()}}
    var ans = 0
    for(i in 0 until n){
        for(j in i + 1 until n){
            var sum = a[i].zip(a[j]).map{it.first - it.second}.map{it * it}.sum()
            for(i in 1 .. Math.sqrt(sum.toDouble()).toInt()){
                if(sum % i == 0 && i == sum / i) ans++
            }
        }
    }
    println(ans)
}
