import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int d = getInt(sc);
		int[][] points = new int[n][d];

		for (int i = 0; i < n; i++) {
			points[i] = getIntArray(sc);
		}

		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}

	private static boolean isInteger(double distance) {

		return (int) distance == distance;
	}

	private static double getDistance(int[] is, int[] is2) {
		int distanceSquare = 0;
		for (int i = 0; i < is.length; i++) {
			distanceSquare += Math.pow(is[i] - is2[i], 2);
		}
		return Math.sqrt(distanceSquare);
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int d = getInt(sc);
		int[][] points = new int[n][d];

		for (int i = 0; i < n; i++) {
			points[i] = getIntArray(sc);
		}

		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}

	private static boolean isInteger(double distance) {

		return (int) distance == distance;
	}

	private static double getDistance(int[] is, int[] is2) {
		int distanceSquare = 0;
		for (int i = 0; i < is.length; i++) {
			distanceSquare += Math.pow(is[i] - is2[i], 2);
		}
		return Math.sqrt(distanceSquare);
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int d = getInt(sc);
		int[][] points = new int[n][d];

		for (int i = 0; i < n; i++) {
			points[i] = getIntArray(sc);
		}

		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int d = getInt(sc);
		int[][] points = new int[n][d];

		for (int i = 0; i < n; i++) {
			points[i] = getIntArray(sc);
		}

		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = getInt(sc); n getInt(sc) getInt sc int d = getInt(sc); d getInt(sc) getInt sc int[][] points = new int[n][d]; points new int[n][d] n d for (int i = 0; i < n; i++) {
			points[i] = getIntArray(sc);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			points[i] = getIntArray(sc);
		} {
			points[i] = getIntArray(sc);
		} points[i] = getIntArray(sc) points[i] points i getIntArray(sc) getIntArray sc int count = 0; count 0 for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			}
		} {
			for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			}
		} for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			} {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			} if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				} isInteger(getDistance(points[i], points[j])) isInteger getDistance(points[i], points[j]) getDistance points[i] points i points[j] points j {
					count++;
				} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args private static boolean isInteger(double distance) {

		return (int) distance == distance;
	} isInteger {

		return (int) distance == distance;
	} return (int) distance == distance; (int) distance == distance (int) distance distance double distance distance private static double getDistance(int[] is, int[] is2) {
		int distanceSquare = 0;
		for (int i = 0; i < is.length; i++) {
			distanceSquare += Math.pow(is[i] - is2[i], 2);
		}
		return Math.sqrt(distanceSquare);
	} getDistance {
		int distanceSquare = 0;
		for (int i = 0; i < is.length; i++) {
			distanceSquare += Math.pow(is[i] - is2[i], 2);
		}
		return Math.sqrt(distanceSquare);
	} int distanceSquare = 0; distanceSquare 0 for (int i = 0; i < is.length; i++) {
			distanceSquare += Math.pow(is[i] - is2[i], 2);
		} int i = 0; int i = 0; i 0 i < is.length i is.length is is.length i++ i++ i {
			distanceSquare += Math.pow(is[i] - is2[i], 2);
		} {
			distanceSquare += Math.pow(is[i] - is2[i], 2);
		} distanceSquare += Math.pow(is[i] - is2[i], 2) distanceSquare Math.pow(is[i] - is2[i], 2) Math.pow Math is[i] - is2[i] is[i] is i is2[i] is2 i 2 return Math.sqrt(distanceSquare); Math.sqrt(distanceSquare) Math.sqrt Math distanceSquare int[] is is int[] is2 is2 /**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	} getLong {

		return Long.parseLong(sc.next());
	} return Long.parseLong(sc.next()); Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc Scanner sc sc /**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	} getInt {

		return Integer.parseInt(sc.next());
	} return Integer.parseInt(sc.next()); Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc Scanner sc sc /**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	} getString {

		return sc.next();
	} return sc.next(); sc.next() sc.next sc Scanner sc sc /**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	} getIntArray {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	} String line = ""; line "" while (line.equals("")) {
			line = sc.nextLine();
		} line.equals("") line.equals line "" {
			line = sc.nextLine();
		} line = sc.nextLine() line sc.nextLine() sc.nextLine sc String[] strArray = line.split(" "); strArray line.split(" ") line.split line " " int[] intArray = new int[strArray.length]; intArray new int[strArray.length] strArray.length strArray strArray.length for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		} int i = 0; int i = 0; i 0 i < strArray.length i strArray.length strArray strArray.length i++ i++ i {
			intArray[i] = Integer.parseInt(strArray[i]);
		} {
			intArray[i] = Integer.parseInt(strArray[i]);
		} intArray[i] = Integer.parseInt(strArray[i]) intArray[i] intArray i Integer.parseInt(strArray[i]) Integer.parseInt Integer strArray[i] strArray i return intArray; intArray Scanner sc sc public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int d = getInt(sc);
		int[][] points = new int[n][d];

		for (int i = 0; i < n; i++) {
			points[i] = getIntArray(sc);
		}

		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}

	private static boolean isInteger(double distance) {

		return (int) distance == distance;
	}

	private static double getDistance(int[] is, int[] is2) {
		int distanceSquare = 0;
		for (int i = 0; i < is.length; i++) {
			distanceSquare += Math.pow(is[i] - is2[i], 2);
		}
		return Math.sqrt(distanceSquare);
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int d = getInt(sc);
		int[][] points = new int[n][d];

		for (int i = 0; i < n; i++) {
			points[i] = getIntArray(sc);
		}

		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}

	private static boolean isInteger(double distance) {

		return (int) distance == distance;
	}

	private static double getDistance(int[] is, int[] is2) {
		int distanceSquare = 0;
		for (int i = 0; i < is.length; i++) {
			distanceSquare += Math.pow(is[i] - is2[i], 2);
		}
		return Math.sqrt(distanceSquare);
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int d = getInt(sc);
		int[][] points = new int[n][d];

		for (int i = 0; i < n; i++) {
			points[i] = getIntArray(sc);
		}

		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (isInteger(getDistance(points[i], points[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}

	private static boolean isInteger(double distance) {

		return (int) distance == distance;
	}

	private static double getDistance(int[] is, int[] is2) {
		int distanceSquare = 0;
		for (int i = 0; i < is.length; i++) {
			distanceSquare += Math.pow(is[i] - is2[i], 2);
		}
		return Math.sqrt(distanceSquare);
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}
