object Main extends App {

  // 入力値から座標の配列を生成
  def generateCoordinates: Array[Array[Int]] = {
    var coordinates = scala.collection.mutable.ListBuffer.empty[Array[Int]]
    io.Source.stdin.getLines().zipWithIndex.foreach {
      case (line, index) if index != 0  =>
        val coordinate = line.split(" ").map(_.toInt)
        coordinates += coordinate
      case _ =>
    }
    coordinates.toArray
  }

  def isIntegerDistance(a1: Array[Int], a2: Array[Int]): Boolean = {
    val squareSum = a1.zip(a2).map {
      case (p1, p2) =>
        val diff = math.abs(p1 - p2)
        diff * diff
    }.sum
    val d = math.sqrt(squareSum)
    d == d.toInt
  }

  val coordinates = generateCoordinates
  val lastCoordinateIndex = coordinates.size - 1
  var result: Int = 0

  coordinates.zipWithIndex.foreach {
    case (c, selfIndex) =>
      var targetIndex = selfIndex + 1
      while (targetIndex <= lastCoordinateIndex) {
        val t = coordinates(targetIndex)
        if (isIntegerDistance(c, t)) result += 1
        targetIndex += 1
      }
  }

  println(result)

}
