import java.util.*;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		double[][]  pos = new double[n][d];
		for (int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		}
		//double[][] dist = new double[n][n];
		int cnt = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		}
		out.println(cnt);
	}
} import java.util.*; util.* java import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		double[][]  pos = new double[n][d];
		for (int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		}
		//double[][] dist = new double[n][n];
		int cnt = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		}
		out.println(cnt);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		double[][]  pos = new double[n][d];
		for (int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		}
		//double[][] dist = new double[n][n];
		int cnt = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		}
		out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		double[][]  pos = new double[n][d];
		for (int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		}
		//double[][] dist = new double[n][n];
		int cnt = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		}
		out.println(cnt);
	} 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 double[][]  pos = new double[n][d]; pos new double[n][d] n d for (int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		} {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		} for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				pos[i][j] = sc.nextDouble();
			} {
				pos[i][j] = sc.nextDouble();
			} pos[i][j] = sc.nextDouble() pos[i][j] pos[i] pos i j sc.nextDouble() sc.nextDouble sc int cnt = 0; cnt 0 for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		} {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		} for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			} {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			} double num = 0; num 0 for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				} {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				} num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]) num ( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]) ( pos[i][k] - pos[j][k]) pos[i][k] pos[i] pos i k pos[j][k] pos[j] pos j k (pos[i][k] - pos[j][k]) pos[i][k] pos[i] pos i k pos[j][k] pos[j] pos j k num = Math.sqrt(num) num Math.sqrt(num) Math.sqrt Math num if( ((int)num - num) == 0)
					cnt++; ((int)num - num) == 0 ((int)num - num) (int)num num 0 cnt++ cnt out.println(cnt) out.println out cnt String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		double[][]  pos = new double[n][d];
		for (int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		}
		//double[][] dist = new double[n][n];
		int cnt = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		}
		out.println(cnt);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		double[][]  pos = new double[n][d];
		for (int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		}
		//double[][] dist = new double[n][n];
		int cnt = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		}
		out.println(cnt);
	}
} Main
import java.util.*;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		double[][]  pos = new double[n][d];
		for (int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				pos[i][j] = sc.nextDouble();
			}
		}
		//double[][] dist = new double[n][n];
		int cnt = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double num = 0;
				for(int k = 0; k < d; k++) {
					num +=( pos[i][k] - pos[j][k]) * (pos[i][k] - pos[j][k]);
				}
				num = Math.sqrt(num);
				if( ((int)num - num) == 0)
					cnt++;
			}
		}
		out.println(cnt);
	}
}