
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		int dimension = sc.nextInt();
		int[][] X = new int[number][dimension];
		int cnt = 0;
		//データを配列に格納
		for(int i =0; i<number ;i++) {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		}
		for(int i =0; i<number ;i++) {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		}
		System.out.println(cnt);

	}

} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		int dimension = sc.nextInt();
		int[][] X = new int[number][dimension];
		int cnt = 0;
		//データを配列に格納
		for(int i =0; i<number ;i++) {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		}
		for(int i =0; i<number ;i++) {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		}
		System.out.println(cnt);

	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		int dimension = sc.nextInt();
		int[][] X = new int[number][dimension];
		int cnt = 0;
		//データを配列に格納
		for(int i =0; i<number ;i++) {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		}
		for(int i =0; i<number ;i++) {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		}
		System.out.println(cnt);

	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		int dimension = sc.nextInt();
		int[][] X = new int[number][dimension];
		int cnt = 0;
		//データを配列に格納
		for(int i =0; i<number ;i++) {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		}
		for(int i =0; i<number ;i++) {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		}
		System.out.println(cnt);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int number = sc.nextInt(); number sc.nextInt() sc.nextInt sc int dimension = sc.nextInt(); dimension sc.nextInt() sc.nextInt sc int[][] X = new int[number][dimension]; X new int[number][dimension] number dimension int cnt = 0; cnt 0 for(int i =0; i<number ;i++) {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		} int i =0; int i =0; i 0 i<number i number i++ i++ i {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		} {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		} for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			} int j =0; int j =0; j 0 j<dimension j dimension j++ j++ j {
				X[i][j] = sc.nextInt();			
			} {
				X[i][j] = sc.nextInt();			
			} X[i][j] = sc.nextInt() X[i][j] X[i] X i j sc.nextInt() sc.nextInt sc for(int i =0; i<number ;i++) {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		} int i =0; int i =0; i 0 i<number i number i++ i++ i {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		} {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		} for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			} int j =i+1; int j =i+1; j i+1 i 1 j<number j number j++ j++ j {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			} {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			} int distance =0; distance 0 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 } int k =0; int k =0; k 0 k<dimension k dimension k++ k++ k {
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 } {
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 } int work =Math.abs(X[i][k]-X[j][k]); work Math.abs(X[i][k]-X[j][k]) Math.abs Math X[i][k]-X[j][k] X[i][k] X[i] X i k X[j][k] X[j] X j k distance +=work*work distance work*work work work boolean flag =false; flag false for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 } int k = 0; int k = 0; k 0 k<=distance k distance k++ k++ k {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 } {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 } if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 } k*k == distance k*k k k distance {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 } flag =true flag true if(flag== true) {
					++cnt;
				 } flag== true flag true {
					++cnt;
				 } ++cnt cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		int dimension = sc.nextInt();
		int[][] X = new int[number][dimension];
		int cnt = 0;
		//データを配列に格納
		for(int i =0; i<number ;i++) {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		}
		for(int i =0; i<number ;i++) {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		}
		System.out.println(cnt);

	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		int dimension = sc.nextInt();
		int[][] X = new int[number][dimension];
		int cnt = 0;
		//データを配列に格納
		for(int i =0; i<number ;i++) {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		}
		for(int i =0; i<number ;i++) {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		}
		System.out.println(cnt);

	}

} Main

import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		int dimension = sc.nextInt();
		int[][] X = new int[number][dimension];
		int cnt = 0;
		//データを配列に格納
		for(int i =0; i<number ;i++) {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		}
		for(int i =0; i<number ;i++) {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		}
		System.out.println(cnt);

	}

}
