import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ArrayList<int[]> list = new ArrayList<>();
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		
		for(int i = 0; i < N; i++) {
			int[] mlist = new int[D];
			for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			}
			list.add(mlist);
		}
		
		for(int i = 0; i < N-1; i++) {
			for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			}
		}
		System.out.println(ans);
		
	}
	
	public static boolean dis(int[] list1, int[] list2) {
		int sum = 0;
		for(int i = 0; i< list1.length; i++) {
			sum += Math.pow((list1[i]-list2[i]),2);
		}
		if((Math.sqrt(sum) * 10)%10 == 0)  return true;
		else return false;
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		ArrayList<int[]> list = new ArrayList<>();
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		
		for(int i = 0; i < N; i++) {
			int[] mlist = new int[D];
			for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			}
			list.add(mlist);
		}
		
		for(int i = 0; i < N-1; i++) {
			for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			}
		}
		System.out.println(ans);
		
	}
	
	public static boolean dis(int[] list1, int[] list2) {
		int sum = 0;
		for(int i = 0; i< list1.length; i++) {
			sum += Math.pow((list1[i]-list2[i]),2);
		}
		if((Math.sqrt(sum) * 10)%10 == 0)  return true;
		else return false;
	}
} Main public static void main(String[] args) {
		ArrayList<int[]> list = new ArrayList<>();
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		
		for(int i = 0; i < N; i++) {
			int[] mlist = new int[D];
			for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			}
			list.add(mlist);
		}
		
		for(int i = 0; i < N-1; i++) {
			for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			}
		}
		System.out.println(ans);
		
	} main {
		ArrayList<int[]> list = new ArrayList<>();
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		
		for(int i = 0; i < N; i++) {
			int[] mlist = new int[D];
			for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			}
			list.add(mlist);
		}
		
		for(int i = 0; i < N-1; i++) {
			for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			}
		}
		System.out.println(ans);
		
	} ArrayList<int[]> list = new ArrayList<>(); list new ArrayList<>() int ans = 0; ans 0 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt() N sc.nextInt() sc.nextInt sc D = sc.nextInt(); D sc.nextInt() sc.nextInt sc for(int i = 0; i < N; i++) {
			int[] mlist = new int[D];
			for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			}
			list.add(mlist);
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int[] mlist = new int[D];
			for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			}
			list.add(mlist);
		} {
			int[] mlist = new int[D];
			for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			}
			list.add(mlist);
		} int[] mlist = new int[D]; mlist new int[D] D for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				mlist[j] = sc.nextInt();
			} {
				mlist[j] = sc.nextInt();
			} mlist[j] = sc.nextInt() mlist[j] mlist j sc.nextInt() sc.nextInt sc list.add(mlist) list.add list mlist for(int i = 0; i < N-1; i++) {
			for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			}
		} int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
			for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			}
		} {
			for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			}
		} for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				if(dis(list.get(i),list.get(j))) ans++;
			} {
				if(dis(list.get(i),list.get(j))) ans++;
			} if(dis(list.get(i),list.get(j))) ans++; dis(list.get(i),list.get(j)) dis list.get(i) list.get list i list.get(j) list.get list j ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static boolean dis(int[] list1, int[] list2) {
		int sum = 0;
		for(int i = 0; i< list1.length; i++) {
			sum += Math.pow((list1[i]-list2[i]),2);
		}
		if((Math.sqrt(sum) * 10)%10 == 0)  return true;
		else return false;
	} dis {
		int sum = 0;
		for(int i = 0; i< list1.length; i++) {
			sum += Math.pow((list1[i]-list2[i]),2);
		}
		if((Math.sqrt(sum) * 10)%10 == 0)  return true;
		else return false;
	} int sum = 0; sum 0 for(int i = 0; i< list1.length; i++) {
			sum += Math.pow((list1[i]-list2[i]),2);
		} int i = 0; int i = 0; i 0 i< list1.length i list1.length list1 list1.length i++ i++ i {
			sum += Math.pow((list1[i]-list2[i]),2);
		} {
			sum += Math.pow((list1[i]-list2[i]),2);
		} sum += Math.pow((list1[i]-list2[i]),2) sum Math.pow((list1[i]-list2[i]),2) Math.pow Math (list1[i]-list2[i]) list1[i] list1 i list2[i] list2 i 2 if((Math.sqrt(sum) * 10)%10 == 0)  return true;
		else return false; (Math.sqrt(sum) * 10)%10 == 0 (Math.sqrt(sum) * 10)%10 (Math.sqrt(sum) * 10) Math.sqrt(sum) Math.sqrt Math sum 10 10 0 return true; true return false; false int[] list1 list1 int[] list2 list2 public class Main {
	public static void main(String[] args) {
		ArrayList<int[]> list = new ArrayList<>();
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		
		for(int i = 0; i < N; i++) {
			int[] mlist = new int[D];
			for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			}
			list.add(mlist);
		}
		
		for(int i = 0; i < N-1; i++) {
			for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			}
		}
		System.out.println(ans);
		
	}
	
	public static boolean dis(int[] list1, int[] list2) {
		int sum = 0;
		for(int i = 0; i< list1.length; i++) {
			sum += Math.pow((list1[i]-list2[i]),2);
		}
		if((Math.sqrt(sum) * 10)%10 == 0)  return true;
		else return false;
	}
} public class Main {
	public static void main(String[] args) {
		ArrayList<int[]> list = new ArrayList<>();
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		
		for(int i = 0; i < N; i++) {
			int[] mlist = new int[D];
			for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			}
			list.add(mlist);
		}
		
		for(int i = 0; i < N-1; i++) {
			for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			}
		}
		System.out.println(ans);
		
	}
	
	public static boolean dis(int[] list1, int[] list2) {
		int sum = 0;
		for(int i = 0; i< list1.length; i++) {
			sum += Math.pow((list1[i]-list2[i]),2);
		}
		if((Math.sqrt(sum) * 10)%10 == 0)  return true;
		else return false;
	}
} Main
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ArrayList<int[]> list = new ArrayList<>();
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		
		for(int i = 0; i < N; i++) {
			int[] mlist = new int[D];
			for(int j = 0; j < D; j++) {
				mlist[j] = sc.nextInt();
			}
			list.add(mlist);
		}
		
		for(int i = 0; i < N-1; i++) {
			for(int j = i + 1; j < N; j++) {
				if(dis(list.get(i),list.get(j))) ans++;
			}
		}
		System.out.println(ans);
		
	}
	
	public static boolean dis(int[] list1, int[] list2) {
		int sum = 0;
		for(int i = 0; i< list1.length; i++) {
			sum += Math.pow((list1[i]-list2[i]),2);
		}
		if((Math.sqrt(sum) * 10)%10 == 0)  return true;
		else return false;
	}
}