import java.lang.Math.abs
import java.lang.Math.sqrt
import java.util.*
//import kotlin.math.abs
//import kotlin.math.sqrt

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)


    val firstLine = argList.nextLine().split(" ")
    val n = firstLine[0].toInt()
    val d = firstLine[1].toInt()
    val x = mutableListOf<List<Int>>()

    while (argList.hasNext()) {
        x.add(argList.nextLine().split(" ").map { it.toInt() })
    }

    val e = GoodDistance()
    println(e.execute(n, d, x))

}

class GoodDistance {
    fun execute(n: Int, d: Int, x: List<List<Int>>): Int {
        var count = 0
        val nIndex = n - 1

        for ((index, i) in x.withIndex()) {
            val nextIndex = index + 1
            for (j in nextIndex..nIndex) {
                if (judgeDis(i, x[j])) {
                    count++
                }
            }
        }

//        x.forEachIndexed { index, i ->
//
//            val nextIndex = index + 1
//            for (j in nextIndex..nIndex) {
//                if (judgeDis(i, x[j])) {
//                    count++
//                }
//            }
//        }

        return count
    }

    private fun judgeDis(i: List<Int>, j: List<Int>): Boolean {
        val d = mutableListOf<Int>()
        for ((index, value) in i.withIndex() ) {
            val sumAbs = abs(j[index] - value)
            d.add(sumAbs * sumAbs)
        }


//        val a = i.mapIndexed { index, value ->
//            val sumAbs = abs(j[index] - value)
//            sumAbs * sumAbs
//        }

        val result = sqrt(d.sum().toDouble())

        return result == result.toInt().toDouble()
    }
}