import java.util.Scanner

import scala.collection.mutable.ArrayBuffer
import scala.math._

object Main {

  case class Point(grids: Vector[Int])

  def solve(sc: Scanner): String = {
    val (n, d) = (sc.nextInt(), sc.nextInt())
    val points = Vector.fill(n)(Vector.fill(d)(sc.nextInt())).map(v => Point(v))

    points.indices.foldLeft(ArrayBuffer.empty[Int]) { case (acc, i) =>
      acc += getGoodDistanceCount(points, i)
      acc
    }.sum.toString
  }

  def getGoodDistanceCount(points: Vector[Point], from: Int): Int = {
    val base = points(from)
    var count = 0
    points.slice(from + 1, points.size).foreach { p =>
      val d = getDistance(base, p)
      if (d.toInt == d) count += 1
    }
    count
  }

  def getDistance(p1: Point, p2: Point) = {
    sqrt(p1.grids.zipWithIndex.foldLeft(ArrayBuffer.empty[Double]) { case (acc, (grid, i)) =>
      acc += pow(grid - p2.grids(i), 2)
      acc
    }.sum)
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}
