import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int d = s.nextInt();
      	int counter = 0;
      	int[][] x = new int[n][d];
      	for(int i = 0; i < n; i ++){
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        }
      	for(int i = 0; i < n-1; i ++){
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        }
      	System.out.print(counter);
      	
    }
  	public static boolean distance(int[] x, int[] y, int d){
      	int sum = 0;
    	for(int k = 0; k < d; k++){
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        }
      	if(Math.sqrt(sum) == (int)(Math.sqrt(sum))){
        	return true;
        }
      	else{
        	return false;
        }
    }
} 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 d = s.nextInt();
      	int counter = 0;
      	int[][] x = new int[n][d];
      	for(int i = 0; i < n; i ++){
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        }
      	for(int i = 0; i < n-1; i ++){
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        }
      	System.out.print(counter);
      	
    }
  	public static boolean distance(int[] x, int[] y, int d){
      	int sum = 0;
    	for(int k = 0; k < d; k++){
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        }
      	if(Math.sqrt(sum) == (int)(Math.sqrt(sum))){
        	return true;
        }
      	else{
        	return false;
        }
    }
} Main public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int d = s.nextInt();
      	int counter = 0;
      	int[][] x = new int[n][d];
      	for(int i = 0; i < n; i ++){
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        }
      	for(int i = 0; i < n-1; i ++){
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        }
      	System.out.print(counter);
      	
    } main {
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int d = s.nextInt();
      	int counter = 0;
      	int[][] x = new int[n][d];
      	for(int i = 0; i < n; i ++){
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        }
      	for(int i = 0; i < n-1; i ++){
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        }
      	System.out.print(counter);
      	
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int d = s.nextInt(); d s.nextInt() s.nextInt s int counter = 0; counter 0 int[][] x = new int[n][d]; x new int[n][d] n d for(int i = 0; i < n; i ++){
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < n i n i ++ i ++ i {
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        } {
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        } for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j ++ j ++ j {
            	x[i][j] = s.nextInt();
            } {
            	x[i][j] = s.nextInt();
            } x[i][j] = s.nextInt() x[i][j] x[i] x i j s.nextInt() s.nextInt s for(int i = 0; i < n-1; i ++){
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i ++ i ++ i {
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        } {
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        } for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j ++ j ++ j {
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            } {
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            } if(distance(x[i], x[j], d)){
                	counter ++;
                } distance(x[i], x[j], d) distance x[i] x i x[j] x j d {
                	counter ++;
                } counter ++ counter System.out.print(counter) System.out.print System.out System System.out counter String[] args args public static boolean distance(int[] x, int[] y, int d){
      	int sum = 0;
    	for(int k = 0; k < d; k++){
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        }
      	if(Math.sqrt(sum) == (int)(Math.sqrt(sum))){
        	return true;
        }
      	else{
        	return false;
        }
    } distance {
      	int sum = 0;
    	for(int k = 0; k < d; k++){
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        }
      	if(Math.sqrt(sum) == (int)(Math.sqrt(sum))){
        	return true;
        }
      	else{
        	return false;
        }
    } int sum = 0; sum 0 for(int k = 0; k < d; k++){
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        } {
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        } sum += (x[k] - y[k]) * (x[k] - y[k]) sum (x[k] - y[k]) * (x[k] - y[k]) (x[k] - y[k]) x[k] x k y[k] y k (x[k] - y[k]) x[k] x k y[k] y k if(Math.sqrt(sum) == (int)(Math.sqrt(sum))){
        	return true;
        }
      	else{
        	return false;
        } Math.sqrt(sum) == (int)(Math.sqrt(sum)) Math.sqrt(sum) Math.sqrt Math sum (int)(Math.sqrt(sum)) Math.sqrt Math sum {
        	return true;
        } return true; true {
        	return false;
        } return false; false int[] x x int[] y y int d d public class Main{
	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int d = s.nextInt();
      	int counter = 0;
      	int[][] x = new int[n][d];
      	for(int i = 0; i < n; i ++){
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        }
      	for(int i = 0; i < n-1; i ++){
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        }
      	System.out.print(counter);
      	
    }
  	public static boolean distance(int[] x, int[] y, int d){
      	int sum = 0;
    	for(int k = 0; k < d; k++){
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        }
      	if(Math.sqrt(sum) == (int)(Math.sqrt(sum))){
        	return true;
        }
      	else{
        	return false;
        }
    }
} public class Main{
	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int d = s.nextInt();
      	int counter = 0;
      	int[][] x = new int[n][d];
      	for(int i = 0; i < n; i ++){
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        }
      	for(int i = 0; i < n-1; i ++){
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        }
      	System.out.print(counter);
      	
    }
  	public static boolean distance(int[] x, int[] y, int d){
      	int sum = 0;
    	for(int k = 0; k < d; k++){
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        }
      	if(Math.sqrt(sum) == (int)(Math.sqrt(sum))){
        	return true;
        }
      	else{
        	return false;
        }
    }
} Main
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int d = s.nextInt();
      	int counter = 0;
      	int[][] x = new int[n][d];
      	for(int i = 0; i < n; i ++){
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        }
      	for(int i = 0; i < n-1; i ++){
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        }
      	System.out.print(counter);
      	
    }
  	public static boolean distance(int[] x, int[] y, int d){
      	int sum = 0;
    	for(int k = 0; k < d; k++){
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        }
      	if(Math.sqrt(sum) == (int)(Math.sqrt(sum))){
        	return true;
        }
      	else{
        	return false;
        }
    }
}