import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //n個の点
		int d = stdIn.nextInt(); //d次元
		
		int[][] x = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		}
		
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		}
		System.out.println(cnt);
		
	}

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //n個の点
		int d = stdIn.nextInt(); //d次元
		
		int[][] x = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		}
		
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		}
		System.out.println(cnt);
		
	}

} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //n個の点
		int d = stdIn.nextInt(); //d次元
		
		int[][] x = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		}
		
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		}
		System.out.println(cnt);
		
	} main {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //n個の点
		int d = stdIn.nextInt(); //d次元
		
		int[][] x = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		}
		
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		}
		System.out.println(cnt);
		
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int d = stdIn.nextInt(); d stdIn.nextInt() stdIn.nextInt stdIn int[][] x = new int[n][d]; x new int[n][d] n d for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		} {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		} for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				x[i][j] = stdIn.nextInt();
			} {
				x[i][j] = stdIn.nextInt();
			} x[i][j] = stdIn.nextInt() x[i][j] x[i] x i j stdIn.nextInt() stdIn.nextInt stdIn int cnt = 0; cnt 0 for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		} {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		} for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			} int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			} {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			} int norm = 0; norm 0 for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				} {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				} int diff = Math.abs(x[i][k]-x[j][k]); diff Math.abs(x[i][k]-x[j][k]) Math.abs Math x[i][k]-x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k norm += diff*diff norm diff*diff diff diff boolean flag = false; flag false for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				} int k = 0; int k = 0; k 0 k <= norm k norm k++ k++ k {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				} {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				} if(k*k == norm) {
						flag = true;
						cnt++;
					} k*k == norm k*k k k norm {
						flag = true;
						cnt++;
					} flag = true flag true cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //n個の点
		int d = stdIn.nextInt(); //d次元
		
		int[][] x = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		}
		
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		}
		System.out.println(cnt);
		
	}

} public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //n個の点
		int d = stdIn.nextInt(); //d次元
		
		int[][] x = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		}
		
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		}
		System.out.println(cnt);
		
	}

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //n個の点
		int d = stdIn.nextInt(); //d次元
		
		int[][] x = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = stdIn.nextInt();
			}
		}
		
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				int norm = 0;
				
				for(int k = 0; k < d; k++) {
					int diff = Math.abs(x[i][k]-x[j][k]);
					norm += diff*diff;
					
				}
				//check whether norm = k for some k
				boolean flag = false;
				
				for(int k = 0; k <= norm; k++) {
					if(k*k == norm) {
						flag = true;
						cnt++;
					}
				}
				
				
			}
		}
		System.out.println(cnt);
		
	}

}
