fun main(arr:Array<String>) {
    val (n,d) = readLine()!!.split(" ").map { it.toInt() }
    val pointList = (1..n).map { readLine()!!.split(" ").map { it.toInt() } }
    val variation = (0 until n).map { p1->(0 until n).map { p2-> (0 until d).map { (pointList[p1][it] - pointList[p2][it])* (pointList[p1][it] - pointList[p2][it])}.sum() } }
    val count = variation.sumBy { list->list.count { num -> num != 0 && (Math.sqrt(num.toDouble())).toInt().let { it*it } == num } }
    println(count/2)
}


