import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] arrayTwoDimension = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			}
		}
		sc.close();
		int count = 0;
		for(int i = 0; i < N; i++) {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] arrayTwoDimension = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			}
		}
		sc.close();
		int count = 0;
		for(int i = 0; i < N; i++) {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] arrayTwoDimension = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			}
		}
		sc.close();
		int count = 0;
		for(int i = 0; i < N; i++) {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] arrayTwoDimension = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			}
		}
		sc.close();
		int count = 0;
		for(int i = 0; i < N; i++) {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		}
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int D = Integer.parseInt(sc.next()); D Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[][] arrayTwoDimension = new int[N][D]; arrayTwoDimension new int[N][D] N D for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				arrayTwoDimension[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++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			}
		} {
			for(int j = 0; j < D; j++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			}
		} for(int j = 0; j < D; j++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				arrayTwoDimension[i][j] = sc.nextInt();
			} {
				arrayTwoDimension[i][j] = sc.nextInt();
			} arrayTwoDimension[i][j] = sc.nextInt() arrayTwoDimension[i][j] arrayTwoDimension[i] arrayTwoDimension i j sc.nextInt() sc.nextInt sc sc.close() sc.close sc int count = 0; count 0 for(int i = 0; i < N; i++) {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		} {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		} for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			} {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			} double squareValue = 0; squareValue 0 for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				} {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				} double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]); value Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]) Math.abs Math arrayTwoDimension[i][k] - arrayTwoDimension[j][k] arrayTwoDimension[i][k] arrayTwoDimension[i] arrayTwoDimension i k arrayTwoDimension[j][k] arrayTwoDimension[j] arrayTwoDimension j k double square = value * value; square value * value value value squareValue = squareValue + square squareValue squareValue + square squareValue square double judge = Math.sqrt(squareValue); judge Math.sqrt(squareValue) Math.sqrt Math squareValue if(judge == Math.floor(judge)) {
					count++;
				} judge == Math.floor(judge) judge Math.floor(judge) Math.floor Math judge {
					count++;
				} 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 = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] arrayTwoDimension = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			}
		}
		sc.close();
		int count = 0;
		for(int i = 0; i < N; i++) {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] arrayTwoDimension = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			}
		}
		sc.close();
		int count = 0;
		for(int i = 0; i < N; i++) {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int[][] arrayTwoDimension = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				arrayTwoDimension[i][j] = sc.nextInt();
			}
		}
		sc.close();
		int count = 0;
		for(int i = 0; i < N; i++) {
			
			for(int j = i + 1; j < N; j++) {
				double squareValue = 0;
				for(int k = 0; k < D; k++) {
					double value = Math.abs(arrayTwoDimension[i][k] - arrayTwoDimension[j][k]);
					double square = value * value;
					squareValue = squareValue + square;
				}
				double judge = Math.sqrt(squareValue);
				if(judge == Math.floor(judge)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}