import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); //2個
		int d = scan.nextInt(); //3次元

		int[][] index = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			}
		}
		
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			}
		}
		
		System.out.println(count);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); //2個
		int d = scan.nextInt(); //3次元

		int[][] index = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			}
		}
		
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			}
		}
		
		System.out.println(count);
	}
} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); //2個
		int d = scan.nextInt(); //3次元

		int[][] index = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			}
		}
		
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			}
		}
		
		System.out.println(count);
	} main {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); //2個
		int d = scan.nextInt(); //3次元

		int[][] index = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			}
		}
		
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			}
		}
		
		System.out.println(count);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int d = scan.nextInt(); d scan.nextInt() scan.nextInt scan int[][] index = new int[n][d]; index new int[n][d] n d for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			}
		} {
			for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			}
		} for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				index[i][j] = scan.nextInt();
			} {
				index[i][j] = scan.nextInt();
			} index[i][j] = scan.nextInt() index[i][j] index[i] index i j scan.nextInt() scan.nextInt scan int count = 0; count 0 for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			}
		} {
			for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			}
		} for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			} {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			} int sum = 0; sum 0 for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				} {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				} sum += Math.pow((index[i][k] - index[j][k]), 2) sum Math.pow((index[i][k] - index[j][k]), 2) Math.pow Math (index[i][k] - index[j][k]) index[i][k] index[i] index i k index[j][k] index[j] index j k 2 int root = (int) Math.sqrt(sum); root (int) Math.sqrt(sum) Math.sqrt Math sum if (root * root == sum) count++; root * root == sum root * root root root sum 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 scan = new Scanner(System.in);
		int n = scan.nextInt(); //2個
		int d = scan.nextInt(); //3次元

		int[][] index = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			}
		}
		
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			}
		}
		
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); //2個
		int d = scan.nextInt(); //3次元

		int[][] index = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			}
		}
		
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			}
		}
		
		System.out.println(count);
	}
} Main
import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); //2個
		int d = scan.nextInt(); //3次元

		int[][] index = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				index[i][j] = scan.nextInt();
			}
		}
		
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += Math.pow((index[i][k] - index[j][k]), 2);
				}
				
				int root = (int) Math.sqrt(sum);
				
				if (root * root == sum) count++;
			}
		}
		
		System.out.println(count);
	}
}