fun main(args: Array<String>) {
    val (pointCount, dimension) = readLine()!!.split(" ").map { it.toInt() }
    val coordinate = mutableListOf<List<Double>>()
    repeat(pointCount) {
        coordinate.add(readLine()!!.split(" ").map { it.toDouble() })
    }
    var ans = 0

    for (i in 0 until pointCount) {
        for (j in i + 1 until pointCount) {
            var temp = 0.0
            for (k in 0 until dimension) {
                temp += Math.pow(Math.abs(coordinate[i][k] - coordinate[j][k]), 2.0)
            }
            if ((Math.sqrt(temp) - Math.sqrt(temp).toInt()) == 0.0) ans += 1
        }
    }
    print(ans)
}