import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
	public class Main {
		
	    public static void main(String[] args) throws IOException {
	    	Scanner teclado = new Scanner(System.in);
	    	int[][] x = new int[11][21];
	    	int a = teclado.nextInt();
	    	int b = teclado.nextInt();
	    	for(int i = 0;i<a;i++) {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	}
	    	int orozco = 0;
	    	for(int i = 0;i<a-1;i++) {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	}
	    	System.out.println(orozco);
	    }
	
	} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util import java.io.IOException; IOException java.io public class Main {
		
	    public static void main(String[] args) throws IOException {
	    	Scanner teclado = new Scanner(System.in);
	    	int[][] x = new int[11][21];
	    	int a = teclado.nextInt();
	    	int b = teclado.nextInt();
	    	for(int i = 0;i<a;i++) {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	}
	    	int orozco = 0;
	    	for(int i = 0;i<a-1;i++) {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	}
	    	System.out.println(orozco);
	    }
	
	} Main public static void main(String[] args) throws IOException {
	    	Scanner teclado = new Scanner(System.in);
	    	int[][] x = new int[11][21];
	    	int a = teclado.nextInt();
	    	int b = teclado.nextInt();
	    	for(int i = 0;i<a;i++) {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	}
	    	int orozco = 0;
	    	for(int i = 0;i<a-1;i++) {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	}
	    	System.out.println(orozco);
	    } main {
	    	Scanner teclado = new Scanner(System.in);
	    	int[][] x = new int[11][21];
	    	int a = teclado.nextInt();
	    	int b = teclado.nextInt();
	    	for(int i = 0;i<a;i++) {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	}
	    	int orozco = 0;
	    	for(int i = 0;i<a-1;i++) {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	}
	    	System.out.println(orozco);
	    } Scanner teclado = new Scanner(System.in); teclado new Scanner(System.in) int[][] x = new int[11][21]; x new int[11][21] 11 21 int a = teclado.nextInt(); a teclado.nextInt() teclado.nextInt teclado int b = teclado.nextInt(); b teclado.nextInt() teclado.nextInt teclado for(int i = 0;i<a;i++) {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	} int i = 0; int i = 0; i 0 i<a i a i++ i++ i {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	} {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	} for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		} int ii = 0; int ii = 0; ii 0 ii<b ii b ii++ ii++ ii {
	    			x[i][ii] = teclado.nextInt();
	    		} {
	    			x[i][ii] = teclado.nextInt();
	    		} x[i][ii] = teclado.nextInt() x[i][ii] x[i] x i ii teclado.nextInt() teclado.nextInt teclado int orozco = 0; orozco 0 for(int i = 0;i<a-1;i++) {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	} int i = 0; int i = 0; i 0 i<a-1 i a-1 a 1 i++ i++ i {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	} {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	} for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		} int ii = i+1; int ii = i+1; ii i+1 i 1 ii<a ii a ii++ ii++ ii {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		} {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		} int orozcolord =0; orozcolord 0 for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			} int iii =0; int iii =0; iii 0 iii<b iii b iii++ iii++ iii {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			} {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			} orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]) orozcolord (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]) (x[i][iii]-x[ii][iii]) x[i][iii] x[i] x i iii x[ii][iii] x[ii] x ii iii (x[i][iii]-x[ii][iii]) x[i][iii] x[i] x i iii x[ii][iii] x[ii] x ii iii double sla = Math.sqrt(orozcolord); sla Math.sqrt(orozcolord) Math.sqrt Math orozcolord if(sla == (int)sla) {
	    				orozco++;
	    			} sla == (int)sla sla (int)sla {
	    				orozco++;
	    			} orozco++ orozco System.out.println(orozco) System.out.println System.out System System.out orozco String[] args args public class Main {
		
	    public static void main(String[] args) throws IOException {
	    	Scanner teclado = new Scanner(System.in);
	    	int[][] x = new int[11][21];
	    	int a = teclado.nextInt();
	    	int b = teclado.nextInt();
	    	for(int i = 0;i<a;i++) {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	}
	    	int orozco = 0;
	    	for(int i = 0;i<a-1;i++) {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	}
	    	System.out.println(orozco);
	    }
	
	} public class Main {
		
	    public static void main(String[] args) throws IOException {
	    	Scanner teclado = new Scanner(System.in);
	    	int[][] x = new int[11][21];
	    	int a = teclado.nextInt();
	    	int b = teclado.nextInt();
	    	for(int i = 0;i<a;i++) {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	}
	    	int orozco = 0;
	    	for(int i = 0;i<a-1;i++) {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	}
	    	System.out.println(orozco);
	    }
	
	} Main
import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
	public class Main {
		
	    public static void main(String[] args) throws IOException {
	    	Scanner teclado = new Scanner(System.in);
	    	int[][] x = new int[11][21];
	    	int a = teclado.nextInt();
	    	int b = teclado.nextInt();
	    	for(int i = 0;i<a;i++) {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	}
	    	int orozco = 0;
	    	for(int i = 0;i<a-1;i++) {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	}
	    	System.out.println(orozco);
	    }
	
	}