import Foundation
 
let array = readLine()!.componentsSeparatedByString(" ")
let numOfPoints = Int(array[0])!
let dimension = Int(array[1])!
var points: [[Int]] = [[Int]]()
var countInt = 0
 
for i in 0...numOfPoints-1 {
  let array = readLine()!.componentsSeparatedByString(" ")
  var tmpIntArray: [Int] = [Int]()
  for elem in array {
    tmpIntArray.append(Int(elem)!)
  }
  points.append(tmpIntArray)
}
 
for i in 0...numOfPoints-1 {
  for j in 0...numOfPoints-1 {
    if j <= i {
      continue
    }
    var distance = 0
    for (iElem, jElem) in zip(points[i], points[j]) {
      distance += (iElem - jElem) * (iElem - jElem)
    }
    for num in 1...127 {
      if distance == num * num {
        countInt += 1
        break
      }
    }
  }
}
 
print(countInt)