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

  @annotation.tailrec
  def distance(l: List[Int], r: List[Int], dis: Double): Double = (l, r) match {
    case (hl :: tl, hr :: tr) =>
      distance(tl, tr, dis + Math.pow((hl - hr), 2))
    case _ =>  Math.sqrt(dis)
  }

  def goodDistance(points: List[List[Int]]): Int = {
    points.combinations(2).filter({ comb =>
      val dis = distance(comb.head, comb.tail.head, 0)
      dis == dis.toInt
    }).size
  }

  println(goodDistance(List.fill(n)(List.fill(d)(sc.nextInt))))
}