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

public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int dotCount = Integer.parseInt(line[0]);
		int dimCount = Integer.parseInt(line[1]);
		
		ArrayList<String[]> list = new ArrayList();
		for(int i = 0;i<dotCount;i++) {
			list.add(sc.nextLine().split(" "));
		}
		
		int result = 0;
		for(int i = 0;i<dotCount;i++) {
			for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			}
		}
		System.out.println(result);
	}
} 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);
		String[] line = sc.nextLine().split(" ");
		int dotCount = Integer.parseInt(line[0]);
		int dimCount = Integer.parseInt(line[1]);
		
		ArrayList<String[]> list = new ArrayList();
		for(int i = 0;i<dotCount;i++) {
			list.add(sc.nextLine().split(" "));
		}
		
		int result = 0;
		for(int i = 0;i<dotCount;i++) {
			for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			}
		}
		System.out.println(result);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int dotCount = Integer.parseInt(line[0]);
		int dimCount = Integer.parseInt(line[1]);
		
		ArrayList<String[]> list = new ArrayList();
		for(int i = 0;i<dotCount;i++) {
			list.add(sc.nextLine().split(" "));
		}
		
		int result = 0;
		for(int i = 0;i<dotCount;i++) {
			for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			}
		}
		System.out.println(result);
	} main {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int dotCount = Integer.parseInt(line[0]);
		int dimCount = Integer.parseInt(line[1]);
		
		ArrayList<String[]> list = new ArrayList();
		for(int i = 0;i<dotCount;i++) {
			list.add(sc.nextLine().split(" "));
		}
		
		int result = 0;
		for(int i = 0;i<dotCount;i++) {
			for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			}
		}
		System.out.println(result);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] line = sc.nextLine().split(" "); line sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int dotCount = Integer.parseInt(line[0]); dotCount Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int dimCount = Integer.parseInt(line[1]); dimCount Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 ArrayList<String[]> list = new ArrayList(); list new ArrayList() for(int i = 0;i<dotCount;i++) {
			list.add(sc.nextLine().split(" "));
		} int i = 0; int i = 0; i 0 i<dotCount i dotCount i++ i++ i {
			list.add(sc.nextLine().split(" "));
		} {
			list.add(sc.nextLine().split(" "));
		} list.add(sc.nextLine().split(" ")) list.add list sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int result = 0; result 0 for(int i = 0;i<dotCount;i++) {
			for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			}
		} int i = 0; int i = 0; i 0 i<dotCount i dotCount i++ i++ i {
			for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			}
		} {
			for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			}
		} for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			} int j = i+1; int j = i+1; j i+1 i 1 j<dotCount j dotCount j++ j++ j {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			} {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			} double distatnFrom1to2 = 0d; distatnFrom1to2 0d String[] strArray1 = list.get(i); strArray1 list.get(i) list.get list i String[] strArray2 = list.get(j); strArray2 list.get(j) list.get list j for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				} int x = 0; int x = 0; x 0 x<dimCount x dimCount x++ x++ x {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				} {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				} int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x])); tmp Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x])) Math.abs Math Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]) Integer.parseInt(strArray1[x]) Integer.parseInt Integer strArray1[x] strArray1 x Integer.parseInt(strArray2[x]) Integer.parseInt Integer strArray2[x] strArray2 x distatnFrom1to2 += tmp*tmp distatnFrom1to2 tmp*tmp tmp tmp double checkDouble = Math.sqrt(distatnFrom1to2); checkDouble Math.sqrt(distatnFrom1to2) Math.sqrt Math distatnFrom1to2 if(checkDouble == (int)checkDouble) {
					result++;
				} checkDouble == (int)checkDouble checkDouble (int)checkDouble {
					result++;
				} result++ result System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int dotCount = Integer.parseInt(line[0]);
		int dimCount = Integer.parseInt(line[1]);
		
		ArrayList<String[]> list = new ArrayList();
		for(int i = 0;i<dotCount;i++) {
			list.add(sc.nextLine().split(" "));
		}
		
		int result = 0;
		for(int i = 0;i<dotCount;i++) {
			for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			}
		}
		System.out.println(result);
	}
} public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int dotCount = Integer.parseInt(line[0]);
		int dimCount = Integer.parseInt(line[1]);
		
		ArrayList<String[]> list = new ArrayList();
		for(int i = 0;i<dotCount;i++) {
			list.add(sc.nextLine().split(" "));
		}
		
		int result = 0;
		for(int i = 0;i<dotCount;i++) {
			for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			}
		}
		System.out.println(result);
	}
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] line = sc.nextLine().split(" ");
		int dotCount = Integer.parseInt(line[0]);
		int dimCount = Integer.parseInt(line[1]);
		
		ArrayList<String[]> list = new ArrayList();
		for(int i = 0;i<dotCount;i++) {
			list.add(sc.nextLine().split(" "));
		}
		
		int result = 0;
		for(int i = 0;i<dotCount;i++) {
			for(int j = i+1;j<dotCount;j++) {
				
				double distatnFrom1to2 = 0d;
				String[] strArray1 = list.get(i);
				String[] strArray2 = list.get(j);
				for(int x = 0;x<dimCount;x++) {
					int tmp = Math.abs(Integer.parseInt(strArray1[x]) 
							- Integer.parseInt(strArray2[x]));
					distatnFrom1to2 += tmp*tmp;
				}
				
				double checkDouble = Math.sqrt(distatnFrom1to2);
				if(checkDouble == (int)checkDouble) {
					result++;
				}
				
				
			}
		}
		System.out.println(result);
	}
}