import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);

		ArrayList<ArrayList<Integer>> point = new ArrayList<ArrayList<Integer>>();
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		for(int i = 0; i < n ; i++) {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		}
		
		
		
		
		int count= 0;
		
		for(int i = 0; i < n; i++) {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		}
		
		System.out.println(count);
		
		
	}

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

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);

		ArrayList<ArrayList<Integer>> point = new ArrayList<ArrayList<Integer>>();
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		for(int i = 0; i < n ; i++) {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		}
		
		
		
		
		int count= 0;
		
		for(int i = 0; i < n; i++) {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		}
		
		System.out.println(count);
		
		
	}

} Main public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);

		ArrayList<ArrayList<Integer>> point = new ArrayList<ArrayList<Integer>>();
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		for(int i = 0; i < n ; i++) {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		}
		
		
		
		
		int count= 0;
		
		for(int i = 0; i < n; i++) {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		}
		
		System.out.println(count);
		
		
	} main {
		
		Scanner sc = new Scanner(System.in);

		ArrayList<ArrayList<Integer>> point = new ArrayList<ArrayList<Integer>>();
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		for(int i = 0; i < n ; i++) {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		}
		
		
		
		
		int count= 0;
		
		for(int i = 0; i < n; i++) {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		}
		
		System.out.println(count);
		
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) ArrayList<ArrayList<Integer>> point = new ArrayList<ArrayList<Integer>>(); point new ArrayList<ArrayList<Integer>>() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc for(int i = 0; i < n ; i++) {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		} {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		} ArrayList<Integer> array = new ArrayList<Integer>(); array new ArrayList<Integer>() for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				
				array.add(sc.nextInt());
				
			} {
				
				array.add(sc.nextInt());
				
			} array.add(sc.nextInt()) array.add array sc.nextInt() sc.nextInt sc point.add(array) point.add point array int count= 0; count 0 for(int i = 0; i < n; i++) {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		} {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		} for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			} int j = i+1 ; int j = i+1 ; j i+1 i 1 j < n j n j++ j++ j {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			} {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			} double distance = 0.0; distance 0.0 for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				} {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				} distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2) distance Math.pow(point.get(i).get(k)-point.get(j).get(k), 2) Math.pow Math point.get(i).get(k)-point.get(j).get(k) point.get(i).get(k) point.get(i).get point.get(i) point.get point i k point.get(j).get(k) point.get(j).get point.get(j) point.get point j k 2 distance = Math.sqrt(distance) distance Math.sqrt(distance) Math.sqrt Math distance if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				} Math.ceil(distance) == Math.floor(distance) Math.ceil(distance) Math.ceil Math distance Math.floor(distance) Math.floor Math distance {
					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 sc = new Scanner(System.in);

		ArrayList<ArrayList<Integer>> point = new ArrayList<ArrayList<Integer>>();
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		for(int i = 0; i < n ; i++) {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		}
		
		
		
		
		int count= 0;
		
		for(int i = 0; i < n; i++) {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		}
		
		System.out.println(count);
		
		
	}

} public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);

		ArrayList<ArrayList<Integer>> point = new ArrayList<ArrayList<Integer>>();
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		for(int i = 0; i < n ; i++) {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		}
		
		
		
		
		int count= 0;
		
		for(int i = 0; i < n; i++) {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		}
		
		System.out.println(count);
		
		
	}

} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);

		ArrayList<ArrayList<Integer>> point = new ArrayList<ArrayList<Integer>>();
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		for(int i = 0; i < n ; i++) {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		}
		
		
		
		
		int count= 0;
		
		for(int i = 0; i < n; i++) {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		}
		
		System.out.println(count);
		
		
	}

}
