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();
    	List<int[]> order = new ArrayList<>();
    	for (int i = 0; i < N; i++) {
    		int[] map = new int[D];
    		for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		}
    		order.add(map);
    	}
    	int count = 0;
    	for (int i = 0; i < N-1; i++) {
    		for (int j = i+1; j < N; j++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		}
    	}
    	System.out.println(count);
    }
} 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();
    	List<int[]> order = new ArrayList<>();
    	for (int i = 0; i < N; i++) {
    		int[] map = new int[D];
    		for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		}
    		order.add(map);
    	}
    	int count = 0;
    	for (int i = 0; i < N-1; i++) {
    		for (int j = i+1; j < N; j++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		}
    	}
    	System.out.println(count);
    }
} Main public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int D = sc.nextInt();
    	List<int[]> order = new ArrayList<>();
    	for (int i = 0; i < N; i++) {
    		int[] map = new int[D];
    		for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		}
    		order.add(map);
    	}
    	int count = 0;
    	for (int i = 0; i < N-1; i++) {
    		for (int j = i+1; j < N; j++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		}
    	}
    	System.out.println(count);
    } main {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int D = sc.nextInt();
    	List<int[]> order = new ArrayList<>();
    	for (int i = 0; i < N; i++) {
    		int[] map = new int[D];
    		for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		}
    		order.add(map);
    	}
    	int count = 0;
    	for (int i = 0; i < N-1; i++) {
    		for (int j = i+1; j < N; j++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		}
    	}
    	System.out.println(count);
    } 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 List<int[]> order = new ArrayList<>(); order new ArrayList<>() for (int i = 0; i < N; i++) {
    		int[] map = new int[D];
    		for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		}
    		order.add(map);
    	} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
    		int[] map = new int[D];
    		for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		}
    		order.add(map);
    	} {
    		int[] map = new int[D];
    		for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		}
    		order.add(map);
    	} int[] map = new int[D]; map new int[D] D for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
    			map[j] = sc.nextInt();
    		} {
    			map[j] = sc.nextInt();
    		} map[j] = sc.nextInt() map[j] map j sc.nextInt() sc.nextInt sc order.add(map) order.add order map int count = 0; count 0 for (int i = 0; i < N-1; i++) {
    		for (int j = i+1; j < N; j++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		}
    	} 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++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		}
    	} {
    		for (int j = i+1; j < N; j++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		}
    	} for (int j = i+1; j < N; j++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		} int j = i+1; int j = i+1; j i+1 i 1 j < N j N j++ j++ j {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		} {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		} int[] f = order.get(i); f order.get(i) order.get order i int[] b = order.get(j); b order.get(j) order.get order j double total = 0.0; total 0.0 for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
    				total += Math.pow((f[k] - b[k]), 2);
    			} {
    				total += Math.pow((f[k] - b[k]), 2);
    			} total += Math.pow((f[k] - b[k]), 2) total Math.pow((f[k] - b[k]), 2) Math.pow Math (f[k] - b[k]) f[k] f k b[k] b k 2 double root = Math.sqrt(total); root Math.sqrt(total) Math.sqrt Math total double ceil = Math.ceil(root); ceil Math.ceil(root) Math.ceil Math root if (root == ceil) {
    				count++;
    			} root == ceil root ceil {
    				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);
    	int N = sc.nextInt();
    	int D = sc.nextInt();
    	List<int[]> order = new ArrayList<>();
    	for (int i = 0; i < N; i++) {
    		int[] map = new int[D];
    		for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		}
    		order.add(map);
    	}
    	int count = 0;
    	for (int i = 0; i < N-1; i++) {
    		for (int j = i+1; j < N; j++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		}
    	}
    	System.out.println(count);
    }
} public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int D = sc.nextInt();
    	List<int[]> order = new ArrayList<>();
    	for (int i = 0; i < N; i++) {
    		int[] map = new int[D];
    		for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		}
    		order.add(map);
    	}
    	int count = 0;
    	for (int i = 0; i < N-1; i++) {
    		for (int j = i+1; j < N; j++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		}
    	}
    	System.out.println(count);
    }
} 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();
    	List<int[]> order = new ArrayList<>();
    	for (int i = 0; i < N; i++) {
    		int[] map = new int[D];
    		for (int j = 0; j < D; j++) {
    			map[j] = sc.nextInt();
    		}
    		order.add(map);
    	}
    	int count = 0;
    	for (int i = 0; i < N-1; i++) {
    		for (int j = i+1; j < N; j++) {
    			int[] f = order.get(i);
    			int[] b = order.get(j);
    			double total = 0.0;
    			for (int k = 0; k < D; k++) {
    				total += Math.pow((f[k] - b[k]), 2);
    			}
    			double root = Math.sqrt(total);
    			double ceil = Math.ceil(root);
    			if (root == ceil) {
    				count++;
    			}
     		}
    	}
    	System.out.println(count);
    }
}