import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

let nd=readInts()
let n=nd[0]
let d=nd[1]
var box:[[Int]]=[]

for i in 0..<n{
  let a=readInts()
  box.append([])
  for j in 0..<d{
    box[i].append(a[j])
  }
}

var ans=0

for i in 0..<n-1{
  for j in i+1..<n{
    var sum:Double=0
    for k in 0..<d{
      sum+=Double((box[j][k]-box[i][k])*(box[j][k]-box[i][k]))
    }
    if Double(sqrt(sum))-Double(Int(sqrt(sum)))==0.0 {ans+=1}
  }
}

print(ans)