import Control.Monad
squares=[x*x|x<-[0..1000]]
main=do
 [n,d]<-map read.words<$>getLine
 xs<-replicateM n(map read.words<$>getLine)
 print$length[1|i<-[0..n-2],j<-[i+1..n-1],(sum$zipWith(-)(xs!!i)(xs!!j))`elem`squares]