read n d
for i in `seq $n`;do
 read a[i]
done
cnt=0
for i in `seq $n`;do
 for j in `seq $[i+1] $n`;do
  s=(${a[i]})
  t=(${a[j]})
  x=0
  for k in `seq $d`;do
   x=$[x+(s[k-1]-t[k-1])**2]
  done
  c=0
  for k in `seq 50`;do
   if [ $x -eq $[k*k] ];then
    c=1
   fi
  done
  cnt=$[cnt+c]
 done
done
echo $cnt