object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val squared = LazyList.from(0)
    .map(i => i * i)
    .takeWhile(_ <= 10 * 10 * 200)
    .toIndexedSeq
  val N, D = sc.nextInt()
  val pairs = List.fill(N)(List.fill(D)(sc.nextInt())).combinations(2)
  val count = pairs.count { case Seq(r, l) =>
    val squaredDistance = r.zip(l).map { case (y, z) => (y - z) * (y - z) }.sum
    squared.contains(squaredDistance)
  }
  println(count)
}
