import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val (n, d) = br.readLine().split(" ").map { it.toInt() }
  val x = (1..n).map { br.readLine().split(" ").map { it.toInt() }.toIntArray() }

  var cnt = 0
  for(i in 0 until n) {
    for(j in i+1 until n) {
      val v = x[i].zip(x[j]).map { z -> (z.first - z.second) * (z.first - z.second) }.sum()
      if((v % Math.sqrt(v.toDouble())) == 0.0) {
        cnt++
      }
    }
  }

  val ans = cnt
  println(ans)
}