import java.util.*;
public class Main {
	public static void main(String args[] ){
		Scanner sc =new Scanner(System.in);
		int n =sc.nextInt();
		int d =sc.nextInt();
		int count =0;
		int ans = 0;
		int aaa =n*d;
		int data[] =new int[aaa];
		for(int i=0;i<n*d;i++) {
			data[i] =sc.nextInt();
		}
		
			for(int i=0;i<n*d;i+=d) {
				
				for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			}
			
			
						
		
	  }
			System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String args[] ){
		Scanner sc =new Scanner(System.in);
		int n =sc.nextInt();
		int d =sc.nextInt();
		int count =0;
		int ans = 0;
		int aaa =n*d;
		int data[] =new int[aaa];
		for(int i=0;i<n*d;i++) {
			data[i] =sc.nextInt();
		}
		
			for(int i=0;i<n*d;i+=d) {
				
				for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			}
			
			
						
		
	  }
			System.out.println(ans);
	}
} Main public static void main(String args[] ){
		Scanner sc =new Scanner(System.in);
		int n =sc.nextInt();
		int d =sc.nextInt();
		int count =0;
		int ans = 0;
		int aaa =n*d;
		int data[] =new int[aaa];
		for(int i=0;i<n*d;i++) {
			data[i] =sc.nextInt();
		}
		
			for(int i=0;i<n*d;i+=d) {
				
				for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			}
			
			
						
		
	  }
			System.out.println(ans);
	} main {
		Scanner sc =new Scanner(System.in);
		int n =sc.nextInt();
		int d =sc.nextInt();
		int count =0;
		int ans = 0;
		int aaa =n*d;
		int data[] =new int[aaa];
		for(int i=0;i<n*d;i++) {
			data[i] =sc.nextInt();
		}
		
			for(int i=0;i<n*d;i+=d) {
				
				for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			}
			
			
						
		
	  }
			System.out.println(ans);
	} Scanner sc =new Scanner(System.in); sc new Scanner(System.in) int n =sc.nextInt(); n sc.nextInt() sc.nextInt sc int d =sc.nextInt(); d sc.nextInt() sc.nextInt sc int count =0; count 0 int ans = 0; ans 0 int aaa =n*d; aaa n*d n d int data[] =new int[aaa]; data new int[aaa] aaa for(int i=0;i<n*d;i++) {
			data[i] =sc.nextInt();
		} int i=0; int i=0; i 0 i<n*d i n*d n d i++ i++ i {
			data[i] =sc.nextInt();
		} {
			data[i] =sc.nextInt();
		} data[i] =sc.nextInt() data[i] data i sc.nextInt() sc.nextInt sc for(int i=0;i<n*d;i+=d) {
				
				for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			}
			
			
						
		
	  } int i=0; int i=0; i 0 i<n*d i n*d n d i+=d i+=d i d {
				
				for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			}
			
			
						
		
	  } {
				
				for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			}
			
			
						
		
	  } for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			} int j=i+d; int j=i+d; j i+d i d j<n*d j n*d n d j+=d j+=d j d {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			} {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			} if(i==j)continue; i==j i j continue; int ccount =0; ccount 0 int tt =0; tt 0 while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				} ccount<d ccount d {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				} for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					} int t=0; int t=0; t 0 t<d t d t++ t++ t {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					} {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					} tt += Math.pow(data[i+t]-data[j+t],2) tt Math.pow(data[i+t]-data[j+t],2) Math.pow Math data[i+t]-data[j+t] data[i+t] data i+t i t data[j+t] data j+t j t 2 ccount++ ccount double ttt =Math.sqrt(tt); ttt Math.sqrt(tt) Math.sqrt Math tt int intint = (int)ttt; intint (int)ttt if((ttt-intint)==0.0) {
								ans++;
					  } (ttt-intint)==0.0 (ttt-intint) ttt intint 0.0 {
								ans++;
					  } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main {
	public static void main(String args[] ){
		Scanner sc =new Scanner(System.in);
		int n =sc.nextInt();
		int d =sc.nextInt();
		int count =0;
		int ans = 0;
		int aaa =n*d;
		int data[] =new int[aaa];
		for(int i=0;i<n*d;i++) {
			data[i] =sc.nextInt();
		}
		
			for(int i=0;i<n*d;i+=d) {
				
				for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			}
			
			
						
		
	  }
			System.out.println(ans);
	}
} public class Main {
	public static void main(String args[] ){
		Scanner sc =new Scanner(System.in);
		int n =sc.nextInt();
		int d =sc.nextInt();
		int count =0;
		int ans = 0;
		int aaa =n*d;
		int data[] =new int[aaa];
		for(int i=0;i<n*d;i++) {
			data[i] =sc.nextInt();
		}
		
			for(int i=0;i<n*d;i+=d) {
				
				for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			}
			
			
						
		
	  }
			System.out.println(ans);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String args[] ){
		Scanner sc =new Scanner(System.in);
		int n =sc.nextInt();
		int d =sc.nextInt();
		int count =0;
		int ans = 0;
		int aaa =n*d;
		int data[] =new int[aaa];
		for(int i=0;i<n*d;i++) {
			data[i] =sc.nextInt();
		}
		
			for(int i=0;i<n*d;i+=d) {
				
				for(int j=i+d;j<n*d;j+=d) {
					if(i==j)continue;
					//System.out.println("i"+i+"j"+j);
				int ccount =0;
				int tt =0;
				while(ccount<d) {
					for(int t=0;t<d;t++) {
					 tt += Math.pow(data[i+t]-data[j+t],2);
					 //System.out.println(data[i+t]);
					 //System.out.println(data[j+t]);
					//System.out.println(t+"t");
							ccount++;
					}
					double ttt =Math.sqrt(tt);
				    int intint = (int)ttt;
					if((ttt-intint)==0.0) {
								ans++;
					  }
				}
		
			}
			
			
						
		
	  }
			System.out.println(ans);
	}
}
