fun main(args: Array<String>) {
    val (n, d) = readLine()!!.split(' ').map(String::toInt)
    val x = (1..n).map {
        readLine()!!.split(' ').map(String::toInt)
    }
    var count = 0
    for (i in 1 until n) {
        for (j in 0 until i) {
            val dd = x[i].zip(x[j]).map { (it.first - it.second) * (it.first - it.second) }.sum()
            val d = Math.round(Math.sqrt(dd.toDouble()))
            if (dd.toLong() == d * d) {
                count ++
            }
        }
    }
    println(count)
}
