import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int d = sc.nextInt();

		List<List<Integer>> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			List<Integer> xList = new ArrayList<>();
			for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			}
			list.add(xList);
		}


		int resultCount = 0;
		for (int i = 0; i < n; i++) {
			List<Integer> xiList = list.get(i);
			for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			}
		}

			System.out.println(resultCount);

	}

	public static boolean isNumber(double val) {
		if ((val == Math.floor(val)) && !Double.isInfinite(val)) {
			return true;
		}
		return false;
	}

} import java.util.*; util.* java import java.math.*; math.* java import java.lang.*; lang.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int d = sc.nextInt();

		List<List<Integer>> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			List<Integer> xList = new ArrayList<>();
			for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			}
			list.add(xList);
		}


		int resultCount = 0;
		for (int i = 0; i < n; i++) {
			List<Integer> xiList = list.get(i);
			for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			}
		}

			System.out.println(resultCount);

	}

	public static boolean isNumber(double val) {
		if ((val == Math.floor(val)) && !Double.isInfinite(val)) {
			return true;
		}
		return false;
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int d = sc.nextInt();

		List<List<Integer>> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			List<Integer> xList = new ArrayList<>();
			for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			}
			list.add(xList);
		}


		int resultCount = 0;
		for (int i = 0; i < n; i++) {
			List<Integer> xiList = list.get(i);
			for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			}
		}

			System.out.println(resultCount);

	} main {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int d = sc.nextInt();

		List<List<Integer>> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			List<Integer> xList = new ArrayList<>();
			for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			}
			list.add(xList);
		}


		int resultCount = 0;
		for (int i = 0; i < n; i++) {
			List<Integer> xiList = list.get(i);
			for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			}
		}

			System.out.println(resultCount);

	} 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 List<List<Integer>> list = new ArrayList<>(); list new ArrayList<>() for (int i = 0; i < n; i++) {
			List<Integer> xList = new ArrayList<>();
			for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			}
			list.add(xList);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			List<Integer> xList = new ArrayList<>();
			for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			}
			list.add(xList);
		} {
			List<Integer> xList = new ArrayList<>();
			for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			}
			list.add(xList);
		} List<Integer> xList = new ArrayList<>(); xList new ArrayList<>() for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				int xnd = sc.nextInt();
				xList.add(xnd);
			} {
				int xnd = sc.nextInt();
				xList.add(xnd);
			} int xnd = sc.nextInt(); xnd sc.nextInt() sc.nextInt sc xList.add(xnd) xList.add xList xnd list.add(xList) list.add list xList int resultCount = 0; resultCount 0 for (int i = 0; i < n; i++) {
			List<Integer> xiList = list.get(i);
			for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			List<Integer> xiList = list.get(i);
			for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			}
		} {
			List<Integer> xiList = list.get(i);
			for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			}
		} List<Integer> xiList = list.get(i); xiList list.get(i) list.get list i for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			} int l = i; int l = i; l i l < n l n l++ l++ l {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			} {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			} if(i==l){
					continue;
				} i==l i l {
					continue;
				} continue; List<Integer> xlList = list.get(l); xlList list.get(l) list.get list l int lengthDouble = 0; lengthDouble 0 for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				} {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				} int xi = xiList.get(j); xi xiList.get(j) xiList.get xiList j int xl = xlList.get(j); xl xlList.get(j) xlList.get xlList j lengthDouble += (xi-xl) * (xi-xl) lengthDouble (xi-xl) * (xi-xl) (xi-xl) xi xl (xi-xl) xi xl double length = Math.sqrt(lengthDouble); length Math.sqrt(lengthDouble) Math.sqrt Math lengthDouble if(isNumber(length)){
					resultCount++;
				} isNumber(length) isNumber length {
					resultCount++;
				} resultCount++ resultCount System.out.println(resultCount) System.out.println System.out System System.out resultCount String[] args args public static boolean isNumber(double val) {
		if ((val == Math.floor(val)) && !Double.isInfinite(val)) {
			return true;
		}
		return false;
	} isNumber {
		if ((val == Math.floor(val)) && !Double.isInfinite(val)) {
			return true;
		}
		return false;
	} if ((val == Math.floor(val)) && !Double.isInfinite(val)) {
			return true;
		} (val == Math.floor(val)) && !Double.isInfinite(val) (val == Math.floor(val)) val Math.floor(val) Math.floor Math val !Double.isInfinite(val) Double.isInfinite(val) Double.isInfinite Double val {
			return true;
		} return true; true return false; false double val val public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int d = sc.nextInt();

		List<List<Integer>> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			List<Integer> xList = new ArrayList<>();
			for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			}
			list.add(xList);
		}


		int resultCount = 0;
		for (int i = 0; i < n; i++) {
			List<Integer> xiList = list.get(i);
			for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			}
		}

			System.out.println(resultCount);

	}

	public static boolean isNumber(double val) {
		if ((val == Math.floor(val)) && !Double.isInfinite(val)) {
			return true;
		}
		return false;
	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int d = sc.nextInt();

		List<List<Integer>> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			List<Integer> xList = new ArrayList<>();
			for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			}
			list.add(xList);
		}


		int resultCount = 0;
		for (int i = 0; i < n; i++) {
			List<Integer> xiList = list.get(i);
			for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			}
		}

			System.out.println(resultCount);

	}

	public static boolean isNumber(double val) {
		if ((val == Math.floor(val)) && !Double.isInfinite(val)) {
			return true;
		}
		return false;
	}

} Main
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int d = sc.nextInt();

		List<List<Integer>> list = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			List<Integer> xList = new ArrayList<>();
			for (int j = 0; j < d; j++) {
				int xnd = sc.nextInt();
				xList.add(xnd);
			}
			list.add(xList);
		}


		int resultCount = 0;
		for (int i = 0; i < n; i++) {
			List<Integer> xiList = list.get(i);
			for (int l = i; l < n; l++) {
				if(i==l){
					continue;
				}
				List<Integer> xlList = list.get(l);
				int lengthDouble = 0;
				for (int j = 0; j < d; j++) {
					int xi = xiList.get(j);
					int xl = xlList.get(j);
					lengthDouble += (xi-xl) * (xi-xl);
				}
				double length = Math.sqrt(lengthDouble);
				// System.out.println("length "+length);
				// System.out.println("isNumber "+isNumber(length));


				if(isNumber(length)){
					resultCount++;
				}

			}
		}

			System.out.println(resultCount);

	}

	public static boolean isNumber(double val) {
		if ((val == Math.floor(val)) && !Double.isInfinite(val)) {
			return true;
		}
		return false;
	}

}
