import java.util.Scanner



object Main {

  def read(): (Int, Int, IndexedSeq[IndexedSeq[Int]]) = {
    val sc = new Scanner(System.in)
    val n, d = sc.nextInt()
    val x: IndexedSeq[IndexedSeq[Int]] = IndexedSeq.fill(n, d)(sc.nextInt())
    (n, d, x)
  }

  def dist(y: IndexedSeq[Int], z: IndexedSeq[Int]): Double = {
    Math.sqrt((y,z).zipped.map((yi, zi) => Math.pow(yi - zi, 2)).sum)
  }

  def solve(n: Int, x: IndexedSeq[IndexedSeq[Int]]): Int = {
    (for {
      i <- 0 until n - 1
      j <- i + 1 until n
    } yield {
      val y = x(i)
      val z = x(j)
      val d = dist(y, z)
      d % 1 == 0
    }).count(identity)
  }

  def main(args: Array[String]) = {
    val (n, d, x) = read()
    println(solve(n, x))
  }

}