import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		final int D = scan.nextInt();
		int[][] point = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				point[i][j] = scan.nextInt();
			}
		}
		scan.close();

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i <= 130; i++) {
			list.add(i * i);
		}

		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			}
		}
		
		System.out.println(count);

	}

} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		final int D = scan.nextInt();
		int[][] point = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				point[i][j] = scan.nextInt();
			}
		}
		scan.close();

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i <= 130; i++) {
			list.add(i * i);
		}

		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			}
		}
		
		System.out.println(count);

	}

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

		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		final int D = scan.nextInt();
		int[][] point = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				point[i][j] = scan.nextInt();
			}
		}
		scan.close();

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i <= 130; i++) {
			list.add(i * i);
		}

		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			}
		}
		
		System.out.println(count);

	} main {

		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		final int D = scan.nextInt();
		int[][] point = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				point[i][j] = scan.nextInt();
			}
		}
		scan.close();

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i <= 130; i++) {
			list.add(i * i);
		}

		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			}
		}
		
		System.out.println(count);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) final int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan final int D = scan.nextInt(); D scan.nextInt() scan.nextInt scan int[][] point = new int[N][D]; point new int[N][D] N D for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				point[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++) {
				point[i][j] = scan.nextInt();
			}
		} {
			for (int j = 0; j < D; j++) {
				point[i][j] = scan.nextInt();
			}
		} for (int j = 0; j < D; j++) {
				point[i][j] = scan.nextInt();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				point[i][j] = scan.nextInt();
			} {
				point[i][j] = scan.nextInt();
			} point[i][j] = scan.nextInt() point[i][j] point[i] point i j scan.nextInt() scan.nextInt scan scan.close() scan.close scan List<Integer> list = new ArrayList<>(); list new ArrayList<>() for (int i = 0; i <= 130; i++) {
			list.add(i * i);
		} int i = 0; int i = 0; i 0 i <= 130 i 130 i++ i++ i {
			list.add(i * i);
		} {
			list.add(i * i);
		} list.add(i * i) list.add list i * i i i int count = 0; count 0 for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					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 distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			}
		} {
			for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			}
		} for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			} {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			} int distance = 0; distance 0 for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				} int d = 0; int d = 0; d 0 d < D d D d++ d++ d {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				} {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				} distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]) distance (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]) (point[i][d] - point[j][d]) point[i][d] point[i] point i d point[j][d] point[j] point j d (point[i][d] - point[j][d]) point[i][d] point[i] point i d point[j][d] point[j] point j d if (list.contains(distance)) {
					count++;
				} list.contains(distance) list.contains list distance {
					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 scan = new Scanner(System.in);
		final int N = scan.nextInt();
		final int D = scan.nextInt();
		int[][] point = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				point[i][j] = scan.nextInt();
			}
		}
		scan.close();

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i <= 130; i++) {
			list.add(i * i);
		}

		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			}
		}
		
		System.out.println(count);

	}

} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		final int D = scan.nextInt();
		int[][] point = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				point[i][j] = scan.nextInt();
			}
		}
		scan.close();

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i <= 130; i++) {
			list.add(i * i);
		}

		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			}
		}
		
		System.out.println(count);

	}

} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		final int D = scan.nextInt();
		int[][] point = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				point[i][j] = scan.nextInt();
			}
		}
		scan.close();

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i <= 130; i++) {
			list.add(i * i);
		}

		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int distance = 0;
				for (int d = 0; d < D; d++) {
					distance += (point[i][d] - point[j][d]) * (point[i][d] - point[j][d]);
				}
				if (list.contains(distance)) {
					count++;
				}
			}
		}
		
		System.out.println(count);

	}

}