require "prime"
N,D = gets.split.map &:to_i
XS = (0...N).map{ gets.split.map &:to_i }
ans = 0
(0...N).each{ |i|
  (i+1...N).each{ |j|
    d2 = (0...D).reduce(0){ |a,k|
      a + (XS[i][k] - XS[j][k])**2
    }
    ans += 1 if d2.prime_division.all?{ |q,d| d % 2 == 0 }
  }
}
p ans
