
import java.util.Scanner;
public class Main {
	static int mod = 1000000007;
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		double dis = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
		
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static int mod = 1000000007;
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		double dis = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
		
	}
} Main static int mod = 1000000007; mod 1000000007 public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		double dis = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
		
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		double dis = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
		
	} 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 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] = sc.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] = sc.nextInt();
			}
		} {
			for(int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		} for(int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				x[i][j] = sc.nextInt();
			} {
				x[i][j] = sc.nextInt();
			} x[i][j] = sc.nextInt() x[i][j] x[i] x i j sc.nextInt() sc.nextInt sc int ans = 0; ans 0 double dis = 0; dis 0 for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			}
		} {
			for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			}
		} for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			} int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			} {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			} dis = 0 dis 0 for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				} {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				} dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]) dis Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]) 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 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 if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				} Math.sqrt(dis) == (int)Math.sqrt(dis) Math.sqrt(dis) Math.sqrt Math dis (int)Math.sqrt(dis) Math.sqrt Math dis {
					ans ++;
				} ans ++ ans System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args public class Main {
	static int mod = 1000000007;
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		double dis = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
		
	}
} public class Main {
	static int mod = 1000000007;
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		double dis = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
		
	}
} Main

import java.util.Scanner;
public class Main {
	static int mod = 1000000007;
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		double dis = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				dis = 0;
				for(int k = 0; k < d; k++) {
					dis += Math.abs(x[i][k]-x[j][k]) * Math.abs(x[i][k]-x[j][k]);
				}
				if(Math.sqrt(dis) == (int)Math.sqrt(dis)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
		
	}
}
