object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, d = sc.nextInt

  val input = Seq.fill(n, d)(sc.nextInt)
  val result = input.zip(input.tail.tails.toSeq).foldLeft(0) {
    case (count, (base, compareTarget)) =>
      count + compareTarget.count {
        c =>
          math.sqrt {
            (base zip c).map { p =>
              (math.pow(p._1.toDouble - p._2.toDouble, 2))
            }.sum
          }.isValidInt
      }
  }
  println(result)
}