    import java.io.*;
    import java.util.*;
    public class Main {
    	
    	public static void main(String[] args) {
    		InputReader in = new InputReader();
    		int n = in.nextInt();
    		int d = in.nextInt();
    		
    		int[][] pts = new int[n][d];
    		for (int i=0; i<n; i++)
    			for (int j=0; j<d; j++)
    				pts[i][j] = in.nextInt();
    		
    		int res = 0;
    		for (int i=0; i<n-1; i++) {
    			for (int j=i+1; j<n; j++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			}
    		}
    		System.out.println(res);
    	}
    	
    	static final double EPSILON = 1e-6;
    	public static boolean isInteger(double d) {
    		for (int i=(int)(d-3); i<(int)(d+3); i++)
    			if (Math.abs(d - i)  < EPSILON)
    				return true;
    		return false;
    	}
     
    	static class InputReader {
    		public BufferedReader br;
    		public StringTokenizer st;
    		
    		public InputReader() {
    			br = new BufferedReader(new InputStreamReader(System.in));
    			st = null;
    		}
    		
    		public String next() {
    			while (st == null || !st.hasMoreTokens()) {
    				try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    			return st.nextToken();
    		}
    		
    		public int nextInt() {
    			return Integer.parseInt(next());
    		}
    	}
    } import java.io.*; io.* java import java.util.*; util.* java public class Main {
    	
    	public static void main(String[] args) {
    		InputReader in = new InputReader();
    		int n = in.nextInt();
    		int d = in.nextInt();
    		
    		int[][] pts = new int[n][d];
    		for (int i=0; i<n; i++)
    			for (int j=0; j<d; j++)
    				pts[i][j] = in.nextInt();
    		
    		int res = 0;
    		for (int i=0; i<n-1; i++) {
    			for (int j=i+1; j<n; j++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			}
    		}
    		System.out.println(res);
    	}
    	
    	static final double EPSILON = 1e-6;
    	public static boolean isInteger(double d) {
    		for (int i=(int)(d-3); i<(int)(d+3); i++)
    			if (Math.abs(d - i)  < EPSILON)
    				return true;
    		return false;
    	}
     
    	static class InputReader {
    		public BufferedReader br;
    		public StringTokenizer st;
    		
    		public InputReader() {
    			br = new BufferedReader(new InputStreamReader(System.in));
    			st = null;
    		}
    		
    		public String next() {
    			while (st == null || !st.hasMoreTokens()) {
    				try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    			return st.nextToken();
    		}
    		
    		public int nextInt() {
    			return Integer.parseInt(next());
    		}
    	}
    } Main static final double EPSILON = 1e-6; EPSILON 1e-6 public static void main(String[] args) {
    		InputReader in = new InputReader();
    		int n = in.nextInt();
    		int d = in.nextInt();
    		
    		int[][] pts = new int[n][d];
    		for (int i=0; i<n; i++)
    			for (int j=0; j<d; j++)
    				pts[i][j] = in.nextInt();
    		
    		int res = 0;
    		for (int i=0; i<n-1; i++) {
    			for (int j=i+1; j<n; j++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			}
    		}
    		System.out.println(res);
    	} main {
    		InputReader in = new InputReader();
    		int n = in.nextInt();
    		int d = in.nextInt();
    		
    		int[][] pts = new int[n][d];
    		for (int i=0; i<n; i++)
    			for (int j=0; j<d; j++)
    				pts[i][j] = in.nextInt();
    		
    		int res = 0;
    		for (int i=0; i<n-1; i++) {
    			for (int j=i+1; j<n; j++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			}
    		}
    		System.out.println(res);
    	} InputReader in = new InputReader(); in new InputReader() int n = in.nextInt(); n in.nextInt() in.nextInt in int d = in.nextInt(); d in.nextInt() in.nextInt in int[][] pts = new int[n][d]; pts new int[n][d] n d for (int i=0; i<n; i++)
    			for (int j=0; j<d; j++)
    				pts[i][j] = in.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i for (int j=0; j<d; j++)
    				pts[i][j] = in.nextInt(); for (int j=0; j<d; j++)
    				pts[i][j] = in.nextInt(); int j=0; int j=0; j 0 j<d j d j++ j++ j pts[i][j] = in.nextInt(); pts[i][j] = in.nextInt() pts[i][j] pts[i] pts i j in.nextInt() in.nextInt in int res = 0; res 0 for (int i=0; i<n-1; i++) {
    			for (int j=i+1; j<n; j++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			}
    		} 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++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			}
    		} {
    			for (int j=i+1; j<n; j++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			}
    		} for (int j=i+1; j<n; j++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			} int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			} {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			} int inside = 0; inside 0 for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]); int k=0; int k=0; k 0 k<d k d k++ k++ k inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]); inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]) inside (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]) (pts[i][k]-pts[j][k]) pts[i][k] pts[i] pts i k pts[j][k] pts[j] pts j k (pts[i][k]-pts[j][k]) pts[i][k] pts[i] pts i k pts[j][k] pts[j] pts j k double dist = Math.sqrt(inside); dist Math.sqrt(inside) Math.sqrt Math inside if (isInteger(dist))
    					++res; isInteger(dist) isInteger dist ++res res System.out.println(res) System.out.println System.out System System.out res String[] args args public static boolean isInteger(double d) {
    		for (int i=(int)(d-3); i<(int)(d+3); i++)
    			if (Math.abs(d - i)  < EPSILON)
    				return true;
    		return false;
    	} isInteger {
    		for (int i=(int)(d-3); i<(int)(d+3); i++)
    			if (Math.abs(d - i)  < EPSILON)
    				return true;
    		return false;
    	} for (int i=(int)(d-3); i<(int)(d+3); i++)
    			if (Math.abs(d - i)  < EPSILON)
    				return true; int i=(int)(d-3); int i=(int)(d-3); i (int)(d-3) d 3 i<(int)(d+3) i (int)(d+3) d 3 i++ i++ i if (Math.abs(d - i)  < EPSILON)
    				return true; if (Math.abs(d - i)  < EPSILON)
    				return true; Math.abs(d - i)  < EPSILON Math.abs(d - i) Math.abs Math d - i d i EPSILON return true; true return false; false double d d static class InputReader {
    		public BufferedReader br;
    		public StringTokenizer st;
    		
    		public InputReader() {
    			br = new BufferedReader(new InputStreamReader(System.in));
    			st = null;
    		}
    		
    		public String next() {
    			while (st == null || !st.hasMoreTokens()) {
    				try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    			return st.nextToken();
    		}
    		
    		public int nextInt() {
    			return Integer.parseInt(next());
    		}
    	} InputReader public BufferedReader br; br public StringTokenizer st; st public InputReader() {
    			br = new BufferedReader(new InputStreamReader(System.in));
    			st = null;
    		} InputReader {
    			br = new BufferedReader(new InputStreamReader(System.in));
    			st = null;
    		} br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) st = null st null public String next() {
    			while (st == null || !st.hasMoreTokens()) {
    				try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    			return st.nextToken();
    		} next {
    			while (st == null || !st.hasMoreTokens()) {
    				try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    			return st.nextToken();
    		} while (st == null || !st.hasMoreTokens()) {
    				try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			} st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st {
    				try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			} try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				} catch (IOException e) {
    					throw new RuntimeException(e);
    				} IOException e {
    					throw new RuntimeException(e);
    				} throw new RuntimeException(e); new RuntimeException(e) {
    					st = new StringTokenizer(br.readLine());
    				} st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public int nextInt() {
    			return Integer.parseInt(next());
    		} nextInt {
    			return Integer.parseInt(next());
    		} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public class Main {
    	
    	public static void main(String[] args) {
    		InputReader in = new InputReader();
    		int n = in.nextInt();
    		int d = in.nextInt();
    		
    		int[][] pts = new int[n][d];
    		for (int i=0; i<n; i++)
    			for (int j=0; j<d; j++)
    				pts[i][j] = in.nextInt();
    		
    		int res = 0;
    		for (int i=0; i<n-1; i++) {
    			for (int j=i+1; j<n; j++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			}
    		}
    		System.out.println(res);
    	}
    	
    	static final double EPSILON = 1e-6;
    	public static boolean isInteger(double d) {
    		for (int i=(int)(d-3); i<(int)(d+3); i++)
    			if (Math.abs(d - i)  < EPSILON)
    				return true;
    		return false;
    	}
     
    	static class InputReader {
    		public BufferedReader br;
    		public StringTokenizer st;
    		
    		public InputReader() {
    			br = new BufferedReader(new InputStreamReader(System.in));
    			st = null;
    		}
    		
    		public String next() {
    			while (st == null || !st.hasMoreTokens()) {
    				try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    			return st.nextToken();
    		}
    		
    		public int nextInt() {
    			return Integer.parseInt(next());
    		}
    	}
    } public class Main {
    	
    	public static void main(String[] args) {
    		InputReader in = new InputReader();
    		int n = in.nextInt();
    		int d = in.nextInt();
    		
    		int[][] pts = new int[n][d];
    		for (int i=0; i<n; i++)
    			for (int j=0; j<d; j++)
    				pts[i][j] = in.nextInt();
    		
    		int res = 0;
    		for (int i=0; i<n-1; i++) {
    			for (int j=i+1; j<n; j++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			}
    		}
    		System.out.println(res);
    	}
    	
    	static final double EPSILON = 1e-6;
    	public static boolean isInteger(double d) {
    		for (int i=(int)(d-3); i<(int)(d+3); i++)
    			if (Math.abs(d - i)  < EPSILON)
    				return true;
    		return false;
    	}
     
    	static class InputReader {
    		public BufferedReader br;
    		public StringTokenizer st;
    		
    		public InputReader() {
    			br = new BufferedReader(new InputStreamReader(System.in));
    			st = null;
    		}
    		
    		public String next() {
    			while (st == null || !st.hasMoreTokens()) {
    				try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    			return st.nextToken();
    		}
    		
    		public int nextInt() {
    			return Integer.parseInt(next());
    		}
    	}
    } Main
    import java.io.*;
    import java.util.*;
    public class Main {
    	
    	public static void main(String[] args) {
    		InputReader in = new InputReader();
    		int n = in.nextInt();
    		int d = in.nextInt();
    		
    		int[][] pts = new int[n][d];
    		for (int i=0; i<n; i++)
    			for (int j=0; j<d; j++)
    				pts[i][j] = in.nextInt();
    		
    		int res = 0;
    		for (int i=0; i<n-1; i++) {
    			for (int j=i+1; j<n; j++) {
    				int inside = 0;
    				for (int k=0; k<d; k++)
    					inside += (pts[i][k]-pts[j][k])*(pts[i][k]-pts[j][k]);
    				double dist = Math.sqrt(inside);
    				if (isInteger(dist))
    					++res;
    			}
    		}
    		System.out.println(res);
    	}
    	
    	static final double EPSILON = 1e-6;
    	public static boolean isInteger(double d) {
    		for (int i=(int)(d-3); i<(int)(d+3); i++)
    			if (Math.abs(d - i)  < EPSILON)
    				return true;
    		return false;
    	}
     
    	static class InputReader {
    		public BufferedReader br;
    		public StringTokenizer st;
    		
    		public InputReader() {
    			br = new BufferedReader(new InputStreamReader(System.in));
    			st = null;
    		}
    		
    		public String next() {
    			while (st == null || !st.hasMoreTokens()) {
    				try {
    					st = new StringTokenizer(br.readLine());
    				}
    				catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    			return st.nextToken();
    		}
    		
    		public int nextInt() {
    			return Integer.parseInt(next());
    		}
    	}
    }