import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s= sc.next();
		String buff= "";
		//double n = sc.nextInt()/1000.0;
		int m = sc.nextInt();
		int k = sc.nextInt();
		//String s=sc.next();
		double count=1,flag=0;
		double count1=0,count2=0;
		int count3=9999999;
		int[][] array1 = new int[m][k];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		//Arrays.sort(array);

		for(int i=0;i<m;i++) {
			for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			}
		}
		for(int i=0;i<m-1;i++) {
			for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			}
		}

		/*if(count==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}*/

		System.out.println((int)count1);
	}
}

 import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s= sc.next();
		String buff= "";
		//double n = sc.nextInt()/1000.0;
		int m = sc.nextInt();
		int k = sc.nextInt();
		//String s=sc.next();
		double count=1,flag=0;
		double count1=0,count2=0;
		int count3=9999999;
		int[][] array1 = new int[m][k];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		//Arrays.sort(array);

		for(int i=0;i<m;i++) {
			for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			}
		}
		for(int i=0;i<m-1;i++) {
			for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			}
		}

		/*if(count==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}*/

		System.out.println((int)count1);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s= sc.next();
		String buff= "";
		//double n = sc.nextInt()/1000.0;
		int m = sc.nextInt();
		int k = sc.nextInt();
		//String s=sc.next();
		double count=1,flag=0;
		double count1=0,count2=0;
		int count3=9999999;
		int[][] array1 = new int[m][k];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		//Arrays.sort(array);

		for(int i=0;i<m;i++) {
			for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			}
		}
		for(int i=0;i<m-1;i++) {
			for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			}
		}

		/*if(count==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}*/

		System.out.println((int)count1);
	} main {
		Scanner sc = new Scanner(System.in);
		//String s= sc.next();
		String buff= "";
		//double n = sc.nextInt()/1000.0;
		int m = sc.nextInt();
		int k = sc.nextInt();
		//String s=sc.next();
		double count=1,flag=0;
		double count1=0,count2=0;
		int count3=9999999;
		int[][] array1 = new int[m][k];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		//Arrays.sort(array);

		for(int i=0;i<m;i++) {
			for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			}
		}
		for(int i=0;i<m-1;i++) {
			for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			}
		}

		/*if(count==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}*/

		System.out.println((int)count1);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String buff= ""; buff "" int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc double count=1 count 1 flag=0; flag 0 double count1=0 count1 0 count2=0; count2 0 int count3=9999999; count3 9999999 int[][] array1 = new int[m][k]; array1 new int[m][k] m k for(int i=0;i<m;i++) {
			for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			}
		} int i=0; int i=0; i 0 i<m i m i++ i++ i {
			for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			}
		} {
			for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			}
		} for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			} int j=0; int j=0; j 0 j<k j k j++ j++ j {
				array1[i][j] = sc.nextInt();
			} {
				array1[i][j] = sc.nextInt();
			} array1[i][j] = sc.nextInt() array1[i][j] array1[i] array1 i j sc.nextInt() sc.nextInt sc for(int i=0;i<m-1;i++) {
			for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			}
		} int i=0; int i=0; i 0 i<m-1 i m-1 m 1 i++ i++ i {
			for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			}
		} {
			for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			}
		} for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			} int j=i+1; int j=i+1; j i+1 i 1 j<m j m j++ j++ j {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			} {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			} for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				} int g=0; int g=0; g 0 g<k g k g++ g++ g {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				} {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				} count2+=Math.pow((array1[i][g]-array1[j][g]), 2) count2 Math.pow((array1[i][g]-array1[j][g]), 2) Math.pow Math (array1[i][g]-array1[j][g]) array1[i][g] array1[i] array1 i g array1[j][g] array1[j] array1 j g 2 count=Math.sqrt(count2) count Math.sqrt(count2) Math.sqrt Math count2 count3=(int)count count3 (int)count if(count-count3==0) {
					count1++;
				} count-count3==0 count-count3 count count3 0 {
					count1++;
				} count1++ count1 count2=0 count2 0 System.out.println((int)count1) System.out.println System.out System System.out (int)count1 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s= sc.next();
		String buff= "";
		//double n = sc.nextInt()/1000.0;
		int m = sc.nextInt();
		int k = sc.nextInt();
		//String s=sc.next();
		double count=1,flag=0;
		double count1=0,count2=0;
		int count3=9999999;
		int[][] array1 = new int[m][k];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		//Arrays.sort(array);

		for(int i=0;i<m;i++) {
			for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			}
		}
		for(int i=0;i<m-1;i++) {
			for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			}
		}

		/*if(count==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}*/

		System.out.println((int)count1);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s= sc.next();
		String buff= "";
		//double n = sc.nextInt()/1000.0;
		int m = sc.nextInt();
		int k = sc.nextInt();
		//String s=sc.next();
		double count=1,flag=0;
		double count1=0,count2=0;
		int count3=9999999;
		int[][] array1 = new int[m][k];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		//Arrays.sort(array);

		for(int i=0;i<m;i++) {
			for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			}
		}
		for(int i=0;i<m-1;i++) {
			for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			}
		}

		/*if(count==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}*/

		System.out.println((int)count1);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s= sc.next();
		String buff= "";
		//double n = sc.nextInt()/1000.0;
		int m = sc.nextInt();
		int k = sc.nextInt();
		//String s=sc.next();
		double count=1,flag=0;
		double count1=0,count2=0;
		int count3=9999999;
		int[][] array1 = new int[m][k];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		//Arrays.sort(array);

		for(int i=0;i<m;i++) {
			for(int j=0;j<k;j++) {
				array1[i][j] = sc.nextInt();
			}
		}
		for(int i=0;i<m-1;i++) {
			for(int j=i+1;j<m;j++) {
				for(int g=0;g<k;g++) {
					count2+=Math.pow((array1[i][g]-array1[j][g]), 2);
				}
				count=Math.sqrt(count2);
				count3=(int)count;
				//System.out.println(count2);
				if(count-count3==0) {
					count1++;
				}
				count2=0;
			}
		}

		/*if(count==0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}*/

		System.out.println((int)count1);
	}
}


