n,d = gets.split(" ").map(&:to_i)
ary = []
while a = gets
    ary.push(a.split(" ").map(&:to_i))
end

i = 0
j = 1
count = 0
a = []
b = []

def point(a,b)
    result = []
    a.length.times do |i|
        distance = (a[i]-b[i])**2
        result.push(distance)
    end
    return result
end

def sum_point(result)
    sum = 0
    result.each do |a|
        sum = sum + a
    end
    return sum.to_i
end 

def detect_n_num(sum_point)
    sum_point = Math.sqrt(sum_point)
    if sum_point.to_f - sum_point.abs.to_i == 0
        return 1
    else
        return 0
    end
end

while i < ary.length do
    a = []
    d.times do |num|
        a.push(ary[i][num].to_i)
    end
    while j < ary.length do
        b = []
        d.times do |num|
            b.push(ary[j][num])
        end
        point = point(a,b)
        sum   = sum_point(point)
        count = count + detect_n_num(sum)
        j = j + 1
    end
    i = i + 1
    j = i + 1
end

puts count