fun main(arr: Array<String>) {
    val (n,d) = readLine()!!.split(" ").map { it.toInt() }
    val points = (1..n).map { readLine()!!.split(" ").map { it.toInt() } }
    val ans = (0 until points.lastIndex).map { idx-> (idx+1 until n).count { isGoodDist(points[idx], points[it]) } }.sum()
    println(ans)
}

fun isGoodDist(p1:List<Int>, p2:List<Int>):Boolean {
    val total = p1.indices.map { (p1[it] - p2[it])*(p1[it] - p2[it]) }.sum()
    for(i in (1..total)) {
        if(i*i>total) {
            break
        }
        if(i*i==total) {
            return true
        }
    }
    return false
}