fun main(args: Array<String>) {
  var split = readLine()!!.split(" ")
  val n = Integer.parseInt(split[0])!!
  val d = Integer.parseInt(split[1])!!
  var points = mutableListOf<List<Int>>()
  var count = 0
  for (i in 0..n - 1) {
    points.add(readLine()!!.split(" ").map { Integer.parseInt(it)!! })
  }
  for (i in 0..n - 1) {
    for (j in i + 1..n - 1) {
      var distance = 0
      for (id in 0..d - 1) {
        distance += (points[i][id] - points[j][id]) * (points[i][id] - points[j][id])
      }
      var dd = Math.sqrt(distance.toDouble())
      var isInt = dd % 1.0 == 0.0
      if (isInt) {
        count += 1
      }
  	}
  }
  println(count)
}