import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String in[] = new String[2];
		int n = 0, d = 0;
		try {
			line = br.readLine();
			in = line.split(" ");
			n = Integer.parseInt(in[0]);
			d = Integer.parseInt(in[1]);
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		String in_d [] = new String[d];
		int in_dnum [][] = new int [d][n];
		try {
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			}
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		int c = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			}
		}
		System.out.println(c);
	}
	
	static double dis(int s1, int s2, int[][] in) {
		int dis = 0;
		for (int i = 0; i < in.length; i++) {
			dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2);
		}
		return Math.sqrt(dis);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String in[] = new String[2];
		int n = 0, d = 0;
		try {
			line = br.readLine();
			in = line.split(" ");
			n = Integer.parseInt(in[0]);
			d = Integer.parseInt(in[1]);
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		String in_d [] = new String[d];
		int in_dnum [][] = new int [d][n];
		try {
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			}
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		int c = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			}
		}
		System.out.println(c);
	}
	
	static double dis(int s1, int s2, int[][] in) {
		int dis = 0;
		for (int i = 0; i < in.length; i++) {
			dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2);
		}
		return Math.sqrt(dis);
	}
} Main public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String in[] = new String[2];
		int n = 0, d = 0;
		try {
			line = br.readLine();
			in = line.split(" ");
			n = Integer.parseInt(in[0]);
			d = Integer.parseInt(in[1]);
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		String in_d [] = new String[d];
		int in_dnum [][] = new int [d][n];
		try {
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			}
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		int c = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			}
		}
		System.out.println(c);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String in[] = new String[2];
		int n = 0, d = 0;
		try {
			line = br.readLine();
			in = line.split(" ");
			n = Integer.parseInt(in[0]);
			d = Integer.parseInt(in[1]);
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		String in_d [] = new String[d];
		int in_dnum [][] = new int [d][n];
		try {
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			}
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		int c = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			}
		}
		System.out.println(c);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line; line String in[] = new String[2]; in new String[2] 2 int n = 0 n 0 d = 0; d 0 try {
			line = br.readLine();
			in = line.split(" ");
			n = Integer.parseInt(in[0]);
			d = Integer.parseInt(in[1]);
		} catch (IOException e) {
			e.getStackTrace();
		} catch (IOException e) {
			e.getStackTrace();
		} IOException e {
			e.getStackTrace();
		} e.getStackTrace() e.getStackTrace e {
			line = br.readLine();
			in = line.split(" ");
			n = Integer.parseInt(in[0]);
			d = Integer.parseInt(in[1]);
		} line = br.readLine() line br.readLine() br.readLine br in = line.split(" ") in line.split(" ") line.split line " " n = Integer.parseInt(in[0]) n Integer.parseInt(in[0]) Integer.parseInt Integer in[0] in 0 d = Integer.parseInt(in[1]) d Integer.parseInt(in[1]) Integer.parseInt Integer in[1] in 1 String in_d [] = new String[d]; in_d new String[d] d int in_dnum [][] = new int [d][n]; in_dnum new int [d][n] d n try {
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			}
		} catch (IOException e) {
			e.getStackTrace();
		} catch (IOException e) {
			e.getStackTrace();
		} IOException e {
			e.getStackTrace();
		} e.getStackTrace() e.getStackTrace e {
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			}
		} for (int i = 0; i < n; i++) {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			} {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			} line = br.readLine() line br.readLine() br.readLine br in_d = line.split(" ") in_d line.split(" ") line.split line " " for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				} {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				} in_dnum[j][i] = Integer.parseInt(in_d[j]) in_dnum[j][i] in_dnum[j] in_dnum j i Integer.parseInt(in_d[j]) Integer.parseInt Integer in_d[j] in_d j int c = 0; c 0 for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			}
		} {
			for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			}
		} for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			} int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			} {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			} double dis; dis dis = dis(i, j, in_dnum) dis dis(i, j, in_dnum) dis i j in_dnum if(Math.ceil(dis) == dis) {
					c++;
				} Math.ceil(dis) == dis Math.ceil(dis) Math.ceil Math dis dis {
					c++;
				} c++ c System.out.println(c) System.out.println System.out System System.out c String[] args args static double dis(int s1, int s2, int[][] in) {
		int dis = 0;
		for (int i = 0; i < in.length; i++) {
			dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2);
		}
		return Math.sqrt(dis);
	} dis {
		int dis = 0;
		for (int i = 0; i < in.length; i++) {
			dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2);
		}
		return Math.sqrt(dis);
	} int dis = 0; dis 0 for (int i = 0; i < in.length; i++) {
			dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2);
		} int i = 0; int i = 0; i 0 i < in.length i in.length in in.length i++ i++ i {
			dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2);
		} {
			dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2);
		} dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2) dis Math.pow(Math.abs(in[i][s1] - in[i][s2]),2) Math.pow Math Math.abs(in[i][s1] - in[i][s2]) Math.abs Math in[i][s1] - in[i][s2] in[i][s1] in[i] in i s1 in[i][s2] in[i] in i s2 2 return Math.sqrt(dis); Math.sqrt(dis) Math.sqrt Math dis int s1 s1 int s2 s2 int[][] in in public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String in[] = new String[2];
		int n = 0, d = 0;
		try {
			line = br.readLine();
			in = line.split(" ");
			n = Integer.parseInt(in[0]);
			d = Integer.parseInt(in[1]);
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		String in_d [] = new String[d];
		int in_dnum [][] = new int [d][n];
		try {
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			}
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		int c = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			}
		}
		System.out.println(c);
	}
	
	static double dis(int s1, int s2, int[][] in) {
		int dis = 0;
		for (int i = 0; i < in.length; i++) {
			dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2);
		}
		return Math.sqrt(dis);
	}
} public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String in[] = new String[2];
		int n = 0, d = 0;
		try {
			line = br.readLine();
			in = line.split(" ");
			n = Integer.parseInt(in[0]);
			d = Integer.parseInt(in[1]);
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		String in_d [] = new String[d];
		int in_dnum [][] = new int [d][n];
		try {
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			}
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		int c = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			}
		}
		System.out.println(c);
	}
	
	static double dis(int s1, int s2, int[][] in) {
		int dis = 0;
		for (int i = 0; i < in.length; i++) {
			dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2);
		}
		return Math.sqrt(dis);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String in[] = new String[2];
		int n = 0, d = 0;
		try {
			line = br.readLine();
			in = line.split(" ");
			n = Integer.parseInt(in[0]);
			d = Integer.parseInt(in[1]);
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		String in_d [] = new String[d];
		int in_dnum [][] = new int [d][n];
		try {
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				in_d = line.split(" ");
				for (int j = 0; j < d; j++) {
					in_dnum[j][i] = Integer.parseInt(in_d[j]);
				}
			}
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		int c = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				double dis;
				dis = dis(i, j, in_dnum);
				if(Math.ceil(dis) == dis) {
					c++;
				}
			}
		}
		System.out.println(c);
	}
	
	static double dis(int s1, int s2, int[][] in) {
		int dis = 0;
		for (int i = 0; i < in.length; i++) {
			dis += Math.pow(Math.abs(in[i][s1] - in[i][s2]),2);
		}
		return Math.sqrt(dis);
	}
}