import java.util.*;

public class Main {
 	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int m = s.nextInt();
      	int[][] arr = new int[n][m];
      	for(int i = 0; i < n; i++) {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        }
      
      	int count = 0;
      	for(int i = 0; i < n; i++ ) {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        }
      System.out.println(count);
    }
} import java.util.*; util.* java public class Main {
 	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int m = s.nextInt();
      	int[][] arr = new int[n][m];
      	for(int i = 0; i < n; i++) {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        }
      
      	int count = 0;
      	for(int i = 0; i < n; i++ ) {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        }
      System.out.println(count);
    }
} Main public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int m = s.nextInt();
      	int[][] arr = new int[n][m];
      	for(int i = 0; i < n; i++) {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        }
      
      	int count = 0;
      	for(int i = 0; i < n; i++ ) {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        }
      System.out.println(count);
    } main {
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int m = s.nextInt();
      	int[][] arr = new int[n][m];
      	for(int i = 0; i < n; i++) {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        }
      
      	int count = 0;
      	for(int i = 0; i < n; i++ ) {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        }
      System.out.println(count);
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int m = s.nextInt(); m s.nextInt() s.nextInt s int[][] arr = new int[n][m]; arr new int[n][m] n m for(int i = 0; i < n; i++) {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        } {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        } for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            } int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
             	arr[i][j] = s.nextInt();
            } {
             	arr[i][j] = s.nextInt();
            } arr[i][j] = s.nextInt() arr[i][j] arr[i] arr i j s.nextInt() s.nextInt s int count = 0; count 0 for(int i = 0; i < n; i++ ) {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        } {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        } for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            } {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            } int sum = 0; sum 0 for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                } int k = 0; int k = 0; k 0 k < m k m k++ k++ k {
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                } {
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                } sum += Math.pow(arr[j][k] - arr[i][k], 2) sum Math.pow(arr[j][k] - arr[i][k], 2) Math.pow Math arr[j][k] - arr[i][k] arr[j][k] arr[j] arr j k arr[i][k] arr[i] arr i k 2 int sqrt = (int)(Math.sqrt(sum)); sqrt (int)(Math.sqrt(sum)) Math.sqrt Math sum if(sqrt * sqrt == sum) {
                	count++;
                } sqrt * sqrt == sum sqrt * sqrt sqrt sqrt sum {
                	count++;
                } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
 	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int m = s.nextInt();
      	int[][] arr = new int[n][m];
      	for(int i = 0; i < n; i++) {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        }
      
      	int count = 0;
      	for(int i = 0; i < n; i++ ) {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        }
      System.out.println(count);
    }
} public class Main {
 	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int m = s.nextInt();
      	int[][] arr = new int[n][m];
      	for(int i = 0; i < n; i++) {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        }
      
      	int count = 0;
      	for(int i = 0; i < n; i++ ) {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        }
      System.out.println(count);
    }
} Main
import java.util.*;

public class Main {
 	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int m = s.nextInt();
      	int[][] arr = new int[n][m];
      	for(int i = 0; i < n; i++) {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        }
      
      	int count = 0;
      	for(int i = 0; i < n; i++ ) {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        }
      System.out.println(count);
    }
}