import scala.math.{abs,sqrt,pow}

object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n, d = sc.nextInt()
  val x = Array.fill(n)(Array.fill(d)(sc.nextInt()))
  val combinations = (0 until n).combinations(2).toList
  val ans = combinations.filter(c => isInt(calcD(x(c(0)), x(c(1))))).size
  println(ans)
    
  def calcD(x: Array[Int], y: Array[Int]): Double = {
    val sum = x.zip(y).foldLeft(0)((x, y) => x + pow((y._1 - y._2), 2).toInt)
    sqrt(sum)
  }
  
  def isInt(x: Double): Boolean = x % 1 == 0
}