import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();int m=sc.nextInt();
        int[][]co=new int[n][m];
        for(int i=0;i<n;i++) {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        }
        int ans=0;
        for(int i=0;i<n;i++) {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        }
        pw.println(ans);
        pw.flush();
    }
    
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} import java.io.*; io.* java import java.math.BigInteger; BigInteger java.math import java.util.*; util.* java public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();int m=sc.nextInt();
        int[][]co=new int[n][m];
        for(int i=0;i<n;i++) {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        }
        int ans=0;
        for(int i=0;i<n;i++) {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        }
        pw.println(ans);
        pw.flush();
    }
    
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} Main public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();int m=sc.nextInt();
        int[][]co=new int[n][m];
        for(int i=0;i<n;i++) {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        }
        int ans=0;
        for(int i=0;i<n;i++) {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        }
        pw.println(ans);
        pw.flush();
    } main {
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();int m=sc.nextInt();
        int[][]co=new int[n][m];
        for(int i=0;i<n;i++) {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        }
        int ans=0;
        for(int i=0;i<n;i++) {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        }
        pw.println(ans);
        pw.flush();
    } MScanner sc = new MScanner(System.in); sc new MScanner(System.in) PrintWriter pw=new PrintWriter(System.out); pw new PrintWriter(System.out) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int m=sc.nextInt(); m sc.nextInt() sc.nextInt sc int[][]co=new int[n][m]; co new int[n][m] n m for(int i=0;i<n;i++) {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        } {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        } for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	} int j=0; int j=0; j 0 j<m j m j++ j++ j {
        		co[i][j]=sc.nextInt();
        	} {
        		co[i][j]=sc.nextInt();
        	} co[i][j]=sc.nextInt() co[i][j] co[i] co i j sc.nextInt() sc.nextInt sc int ans=0; ans 0 for(int i=0;i<n;i++) {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        } {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        } for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	} int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	} {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	} int dist=0; dist 0 for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		} int o=0; int o=0; o 0 o<m o m o++ o++ o {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		} {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		} dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]) dist (co[i][o]-co[j][o])*(co[i][o]-co[j][o]) (co[i][o]-co[j][o]) co[i][o] co[i] co i o co[j][o] co[j] co j o (co[i][o]-co[j][o]) co[i][o] co[i] co i o co[j][o] co[j] co j o if((Math.sqrt(dist))%1==0) {
        			ans++;
        		} (Math.sqrt(dist))%1==0 (Math.sqrt(dist))%1 (Math.sqrt(dist)) Math.sqrt Math dist 1 0 {
        			ans++;
        		} ans++ ans pw.println(ans) pw.println pw ans pw.flush() pw.flush pw String[] args args static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	} MScanner StringTokenizer st; st BufferedReader br; br public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		} MScanner {
			br = new BufferedReader(new InputStreamReader(system));
		} br = new BufferedReader(new InputStreamReader(system)) br new BufferedReader(new InputStreamReader(system)) InputStream system system public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		} MScanner {
			br = new BufferedReader(new FileReader(file));
		} br = new BufferedReader(new FileReader(file)) br new BufferedReader(new FileReader(file)) String file file public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		} next {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		} while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine()); st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public String nextLine() throws IOException {
			return br.readLine();
		} nextLine {
			return br.readLine();
		} return br.readLine(); br.readLine() br.readLine br public int nextInt() throws IOException {
			return Integer.parseInt(next());
		} nextInt {
			return Integer.parseInt(next());
		} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		} nextDouble {
			return Double.parseDouble(next());
		} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public char nextChar() throws IOException {
			return next().charAt(0);
		} nextChar {
			return next().charAt(0);
		} return next().charAt(0); next().charAt(0) next().charAt next() next 0 public Long nextLong() throws IOException {
			return Long.parseLong(next());
		} nextLong {
			return Long.parseLong(next());
		} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public boolean ready() throws IOException {
			return br.ready();
		} ready {
			return br.ready();
		} return br.ready(); br.ready() br.ready br public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		} waitForInput {
			Thread.sleep(3000);
		} Thread.sleep(3000) Thread.sleep Thread 3000 public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();int m=sc.nextInt();
        int[][]co=new int[n][m];
        for(int i=0;i<n;i++) {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        }
        int ans=0;
        for(int i=0;i<n;i++) {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        }
        pw.println(ans);
        pw.flush();
    }
    
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();int m=sc.nextInt();
        int[][]co=new int[n][m];
        for(int i=0;i<n;i++) {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        }
        int ans=0;
        for(int i=0;i<n;i++) {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        }
        pw.println(ans);
        pw.flush();
    }
    
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
} Main
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();int m=sc.nextInt();
        int[][]co=new int[n][m];
        for(int i=0;i<n;i++) {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        }
        int ans=0;
        for(int i=0;i<n;i++) {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        }
        pw.println(ans);
        pw.flush();
    }
    
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}