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[][] array = new int[n][d];
      int count = 0;
      int sum = 0;
      for(int i = 0;i < n;i++) {
    	  for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  }
      }
      for(int i = 0;i < n;i++) {
    	  for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  }
      }
      System.out.println(count);
      sc.close();
    }
} 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[][] array = new int[n][d];
      int count = 0;
      int sum = 0;
      for(int i = 0;i < n;i++) {
    	  for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  }
      }
      for(int i = 0;i < n;i++) {
    	  for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  }
      }
      System.out.println(count);
      sc.close();
    }
} Main public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int d = sc.nextInt();
      int[][] array = new int[n][d];
      int count = 0;
      int sum = 0;
      for(int i = 0;i < n;i++) {
    	  for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  }
      }
      for(int i = 0;i < n;i++) {
    	  for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  }
      }
      System.out.println(count);
      sc.close();
    } main {
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int d = sc.nextInt();
      int[][] array = new int[n][d];
      int count = 0;
      int sum = 0;
      for(int i = 0;i < n;i++) {
    	  for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  }
      }
      for(int i = 0;i < n;i++) {
    	  for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  }
      }
      System.out.println(count);
      sc.close();
    } 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[][] array = new int[n][d]; array new int[n][d] n d int count = 0; count 0 int sum = 0; sum 0 for(int i = 0;i < n;i++) {
    	  for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  }
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
    	  for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  }
      } {
    	  for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  }
      } for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
    		  array[i][j] = sc.nextInt();
    	  } {
    		  array[i][j] = sc.nextInt();
    	  } array[i][j] = sc.nextInt() array[i][j] array[i] array i j sc.nextInt() sc.nextInt sc for(int i = 0;i < n;i++) {
    	  for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  }
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
    	  for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  }
      } {
    	  for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  }
      } for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  } int k = 1; int k = 1; k 1 k < n-i k n-i n i k++ k++ k {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  } {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  } for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  } {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  } sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]) sum (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]) (array[i][j]-array[i+k][j]) array[i][j] array[i] array i j array[i+k][j] array[i+k] array i+k i k j (array[i][j]-array[i+k][j]) array[i][j] array[i] array i j array[i+k][j] array[i+k] array i+k i k j if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++; Math.sqrt(sum) == (int)Math.sqrt(sum) Math.sqrt(sum) Math.sqrt Math sum (int)Math.sqrt(sum) Math.sqrt Math sum count++ count sum = 0 sum 0 System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc 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[][] array = new int[n][d];
      int count = 0;
      int sum = 0;
      for(int i = 0;i < n;i++) {
    	  for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  }
      }
      for(int i = 0;i < n;i++) {
    	  for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  }
      }
      System.out.println(count);
      sc.close();
    }
} public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int d = sc.nextInt();
      int[][] array = new int[n][d];
      int count = 0;
      int sum = 0;
      for(int i = 0;i < n;i++) {
    	  for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  }
      }
      for(int i = 0;i < n;i++) {
    	  for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  }
      }
      System.out.println(count);
      sc.close();
    }
} 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[][] array = new int[n][d];
      int count = 0;
      int sum = 0;
      for(int i = 0;i < n;i++) {
    	  for(int j = 0;j < d;j++) {
    		  array[i][j] = sc.nextInt();
    	  }
      }
      for(int i = 0;i < n;i++) {
    	  for(int k = 1;k < n-i;k++) {
    		  for(int j = 0;j < d;j++) {
    			  sum += (array[i][j]-array[i+k][j])*(array[i][j]-array[i+k][j]);
    		  }
    		  if(Math.sqrt(sum) == (int)Math.sqrt(sum)) count++;
        	  sum = 0;
    	  }
      }
      System.out.println(count);
      sc.close();
    }
}