#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
using namespace std;

int main(){ 
  int n,x=0,y=0,ans=100000,c=0;
  cin>>n>>x;
  int xx[n][x];
  rep(i,0,n) rep(j,0,x) cin>>xx[i][j];
  
  rep(i,0,n-1){
    rep(j,i+1,n){
      rep(k,0,x){
        c+=(xx[i][k]-xx[j][k])*(xx[i][k]-xx[j][k]);
      }
      ans=pow(c,0.5);
      if(c==ans*ans) y++;
      c=0;
    }
  }
  co(y);
  
  return 0;
}