n, d = gets.split.map &:to_i
a = n.times.map{gets.split.map &:to_i}
ans = 0
(0...n).each do |i|
  (i+1...n).each do |j|
    l = (0...d).inject(0){|s, k| s+(a[i][k]-a[j][k])**2}
    ll = Math.sqrt(l).floor
    ans += 1 if ll*ll==l
  end
end
p ans