import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		double[][] point = new double[N][D];
		double[][] y = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int count = 0;
		for(int i = 0; i < N - 1; i++) {
			for(int j = i + 1; j < N; j++) {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			}
		}
		System.out.println(count);
	}
} import java.util.*; util.* java public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		double[][] point = new double[N][D];
		double[][] y = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int count = 0;
		for(int i = 0; i < N - 1; i++) {
			for(int j = i + 1; j < N; j++) {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			}
		}
		System.out.println(count);
	}
} Main public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		double[][] point = new double[N][D];
		double[][] y = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int count = 0;
		for(int i = 0; i < N - 1; i++) {
			for(int j = i + 1; j < N; j++) {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			}
		}
		System.out.println(count);
	} main {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		double[][] point = new double[N][D];
		double[][] y = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int count = 0;
		for(int i = 0; i < N - 1; i++) {
			for(int j = i + 1; j < N; j++) {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			}
		}
		System.out.println(count);
	} 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[][] point = new double[N][D]; point new double[N][D] N D double[][] y = new double[N][D]; y new double[N][D] N D for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[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++) {
				point[i][j] = sc.nextDouble();
			}
		} {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		} for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				point[i][j] = sc.nextDouble();
			} {
				point[i][j] = sc.nextDouble();
			} point[i][j] = sc.nextDouble() point[i][j] point[i] point i j sc.nextDouble() sc.nextDouble sc int count = 0; count 0 for(int i = 0; i < N - 1; i++) {
			for(int j = i + 1; j < N; j++) {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			}
		} 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 dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			}
		} {
			for(int j = i + 1; j < N; j++) {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			}
		} for(int j = i + 1; j < N; j++) {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			} {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			} double dist = 0; dist 0 for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				} {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				} dist += Math.pow((point[i][k] - point[j][k]), 2) dist Math.pow((point[i][k] - point[j][k]), 2) Math.pow Math (point[i][k] - point[j][k]) point[i][k] point[i] point i k point[j][k] point[j] point j k 2 dist = Math.sqrt(dist) dist Math.sqrt(dist) Math.sqrt Math dist if(dist == Math.floor(dist))count++; dist == Math.floor(dist) dist Math.floor(dist) Math.floor Math dist count++ count System.out.println(count) System.out.println System.out System System.out count 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[][] point = new double[N][D];
		double[][] y = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int count = 0;
		for(int i = 0; i < N - 1; i++) {
			for(int j = i + 1; j < N; j++) {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			}
		}
		System.out.println(count);
	}
} public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		double[][] point = new double[N][D];
		double[][] y = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int count = 0;
		for(int i = 0; i < N - 1; i++) {
			for(int j = i + 1; j < N; j++) {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			}
		}
		System.out.println(count);
	}
} Main
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		double[][] point = new double[N][D];
		double[][] y = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int count = 0;
		for(int i = 0; i < N - 1; i++) {
			for(int j = i + 1; j < N; j++) {
				double dist = 0;
				for(int k = 0; k < D; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist))count++;
			}
		}
		System.out.println(count);
	}
}