import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static private int sample = 0;
	static private InputStream in;
	static private PrintStream out;
	static private Scanner sc;
	static {
		if(sample == 0) {
			in = System.in;
			out = System.out;
		}else {
			try {
				in = new FileInputStream(new File("sample"+sample));
				out = new PrintStream("result"+sample);
			} catch (Exception e) {
				e.printStackTrace();
				System.exit(1);
			}
		}
		sc = new Scanner(in);
	}
	static public boolean fileCompare2(String fileA, String fileB) {
	    boolean bRet = false;
	    try {
	        bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
	    } catch (IOException e) {
	    }
	    return bRet;
	}
	static public void exit() {
		if(sample!=0) {
			out.close();
			if(fileCompare2("answer"+sample, "result"+sample)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
			}
		}
		sc.close();
	}
	static public void main(String ...strings ) {
		final int N = sc.nextInt();
		final int D = sc.nextInt();
		final int p[][] = new int[N][D];
		Set<Integer> set = new HashSet<>();
		for(int i=1;i<127;i++) {
			set.add(i*i);
		}
		for(int i=0;i<N;i++) {
			for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			}
		}
		int count = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			}
		}
		out.println(count);
		exit();
	}
} import java.io.File; File java.io import java.io.FileInputStream; FileInputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io import java.nio.file.Files; Files java.nio.file import java.nio.file.Paths; Paths java.nio.file import java.util.Arrays; Arrays java.util import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util public class Main {
	static private int sample = 0;
	static private InputStream in;
	static private PrintStream out;
	static private Scanner sc;
	static {
		if(sample == 0) {
			in = System.in;
			out = System.out;
		}else {
			try {
				in = new FileInputStream(new File("sample"+sample));
				out = new PrintStream("result"+sample);
			} catch (Exception e) {
				e.printStackTrace();
				System.exit(1);
			}
		}
		sc = new Scanner(in);
	}
	static public boolean fileCompare2(String fileA, String fileB) {
	    boolean bRet = false;
	    try {
	        bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
	    } catch (IOException e) {
	    }
	    return bRet;
	}
	static public void exit() {
		if(sample!=0) {
			out.close();
			if(fileCompare2("answer"+sample, "result"+sample)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
			}
		}
		sc.close();
	}
	static public void main(String ...strings ) {
		final int N = sc.nextInt();
		final int D = sc.nextInt();
		final int p[][] = new int[N][D];
		Set<Integer> set = new HashSet<>();
		for(int i=1;i<127;i++) {
			set.add(i*i);
		}
		for(int i=0;i<N;i++) {
			for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			}
		}
		int count = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			}
		}
		out.println(count);
		exit();
	}
} Main static private int sample = 0; sample 0 static private InputStream in; in static private PrintStream out; out static private Scanner sc; sc static public boolean fileCompare2(String fileA, String fileB) {
	    boolean bRet = false;
	    try {
	        bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
	    } catch (IOException e) {
	    }
	    return bRet;
	} fileCompare2 {
	    boolean bRet = false;
	    try {
	        bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
	    } catch (IOException e) {
	    }
	    return bRet;
	} boolean bRet = false; bRet false try {
	        bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
	    } catch (IOException e) {
	    } catch (IOException e) {
	    } IOException e {
	    } {
	        bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
	    } bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB))) bRet Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB))) Arrays.equals Arrays Files.readAllBytes(Paths.get(fileA)) Files.readAllBytes Files Paths.get(fileA) Paths.get Paths fileA Files.readAllBytes(Paths.get(fileB)) Files.readAllBytes Files Paths.get(fileB) Paths.get Paths fileB return bRet; bRet String fileA fileA String fileB fileB static public void exit() {
		if(sample!=0) {
			out.close();
			if(fileCompare2("answer"+sample, "result"+sample)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
			}
		}
		sc.close();
	} exit {
		if(sample!=0) {
			out.close();
			if(fileCompare2("answer"+sample, "result"+sample)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
			}
		}
		sc.close();
	} if(sample!=0) {
			out.close();
			if(fileCompare2("answer"+sample, "result"+sample)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
			}
		} sample!=0 sample 0 {
			out.close();
			if(fileCompare2("answer"+sample, "result"+sample)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
			}
		} out.close() out.close out if(fileCompare2("answer"+sample, "result"+sample)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
			} fileCompare2("answer"+sample, "result"+sample) fileCompare2 "answer"+sample "answer" sample "result"+sample "result" sample {
				System.out.println("AC");
			} System.out.println("AC") System.out.println System.out System System.out "AC" {
				System.out.println("WA");
			} System.out.println("WA") System.out.println System.out System System.out "WA" sc.close() sc.close sc static public void main(String ...strings ) {
		final int N = sc.nextInt();
		final int D = sc.nextInt();
		final int p[][] = new int[N][D];
		Set<Integer> set = new HashSet<>();
		for(int i=1;i<127;i++) {
			set.add(i*i);
		}
		for(int i=0;i<N;i++) {
			for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			}
		}
		int count = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			}
		}
		out.println(count);
		exit();
	} main {
		final int N = sc.nextInt();
		final int D = sc.nextInt();
		final int p[][] = new int[N][D];
		Set<Integer> set = new HashSet<>();
		for(int i=1;i<127;i++) {
			set.add(i*i);
		}
		for(int i=0;i<N;i++) {
			for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			}
		}
		int count = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			}
		}
		out.println(count);
		exit();
	} final int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc final int D = sc.nextInt(); D sc.nextInt() sc.nextInt sc final int p[][] = new int[N][D]; p new int[N][D] N D Set<Integer> set = new HashSet<>(); set new HashSet<>() for(int i=1;i<127;i++) {
			set.add(i*i);
		} int i=1; int i=1; i 1 i<127 i 127 i++ i++ i {
			set.add(i*i);
		} {
			set.add(i*i);
		} set.add(i*i) set.add set i*i i i for(int i=0;i<N;i++) {
			for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			}
		} {
			for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			}
		} for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			} int d=0; int d=0; d 0 d<D d D d++ d++ d {
				p[i][d] = sc.nextInt();
			} {
				p[i][d] = sc.nextInt();
			} p[i][d] = sc.nextInt() p[i][d] p[i] p i d sc.nextInt() sc.nextInt sc int count = 0; count 0 for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			}
		} 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 diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			}
		} {
			for(int j=i+1;j<N;j++) {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			}
		} for(int j=i+1;j<N;j++) {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			} int j=i+1; int j=i+1; j i+1 i 1 j<N j N j++ j++ j {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			} {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			} int diff = 0; diff 0 for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				} int d=0; int d=0; d 0 d<D d D d++ d++ d {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				} {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				} diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]) diff (p[i][d]-p[j][d])*(p[i][d]-p[j][d]) (p[i][d]-p[j][d]) p[i][d] p[i] p i d p[j][d] p[j] p j d (p[i][d]-p[j][d]) p[i][d] p[i] p i d p[j][d] p[j] p j d if(set.contains(diff)) {
					count++;
				} set.contains(diff) set.contains set diff {
					count++;
				} count++ count out.println(count) out.println out count exit() exit String ...strings strings public class Main {
	static private int sample = 0;
	static private InputStream in;
	static private PrintStream out;
	static private Scanner sc;
	static {
		if(sample == 0) {
			in = System.in;
			out = System.out;
		}else {
			try {
				in = new FileInputStream(new File("sample"+sample));
				out = new PrintStream("result"+sample);
			} catch (Exception e) {
				e.printStackTrace();
				System.exit(1);
			}
		}
		sc = new Scanner(in);
	}
	static public boolean fileCompare2(String fileA, String fileB) {
	    boolean bRet = false;
	    try {
	        bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
	    } catch (IOException e) {
	    }
	    return bRet;
	}
	static public void exit() {
		if(sample!=0) {
			out.close();
			if(fileCompare2("answer"+sample, "result"+sample)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
			}
		}
		sc.close();
	}
	static public void main(String ...strings ) {
		final int N = sc.nextInt();
		final int D = sc.nextInt();
		final int p[][] = new int[N][D];
		Set<Integer> set = new HashSet<>();
		for(int i=1;i<127;i++) {
			set.add(i*i);
		}
		for(int i=0;i<N;i++) {
			for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			}
		}
		int count = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			}
		}
		out.println(count);
		exit();
	}
} public class Main {
	static private int sample = 0;
	static private InputStream in;
	static private PrintStream out;
	static private Scanner sc;
	static {
		if(sample == 0) {
			in = System.in;
			out = System.out;
		}else {
			try {
				in = new FileInputStream(new File("sample"+sample));
				out = new PrintStream("result"+sample);
			} catch (Exception e) {
				e.printStackTrace();
				System.exit(1);
			}
		}
		sc = new Scanner(in);
	}
	static public boolean fileCompare2(String fileA, String fileB) {
	    boolean bRet = false;
	    try {
	        bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
	    } catch (IOException e) {
	    }
	    return bRet;
	}
	static public void exit() {
		if(sample!=0) {
			out.close();
			if(fileCompare2("answer"+sample, "result"+sample)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
			}
		}
		sc.close();
	}
	static public void main(String ...strings ) {
		final int N = sc.nextInt();
		final int D = sc.nextInt();
		final int p[][] = new int[N][D];
		Set<Integer> set = new HashSet<>();
		for(int i=1;i<127;i++) {
			set.add(i*i);
		}
		for(int i=0;i<N;i++) {
			for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			}
		}
		int count = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			}
		}
		out.println(count);
		exit();
	}
} Main
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static private int sample = 0;
	static private InputStream in;
	static private PrintStream out;
	static private Scanner sc;
	static {
		if(sample == 0) {
			in = System.in;
			out = System.out;
		}else {
			try {
				in = new FileInputStream(new File("sample"+sample));
				out = new PrintStream("result"+sample);
			} catch (Exception e) {
				e.printStackTrace();
				System.exit(1);
			}
		}
		sc = new Scanner(in);
	}
	static public boolean fileCompare2(String fileA, String fileB) {
	    boolean bRet = false;
	    try {
	        bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
	    } catch (IOException e) {
	    }
	    return bRet;
	}
	static public void exit() {
		if(sample!=0) {
			out.close();
			if(fileCompare2("answer"+sample, "result"+sample)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
			}
		}
		sc.close();
	}
	static public void main(String ...strings ) {
		final int N = sc.nextInt();
		final int D = sc.nextInt();
		final int p[][] = new int[N][D];
		Set<Integer> set = new HashSet<>();
		for(int i=1;i<127;i++) {
			set.add(i*i);
		}
		for(int i=0;i<N;i++) {
			for(int d=0;d<D;d++) {
				p[i][d] = sc.nextInt();
			}
		}
		int count = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int diff = 0;
				for(int d=0;d<D;d++) {
					diff += (p[i][d]-p[j][d])*(p[i][d]-p[j][d]);
				}
				if(set.contains(diff)) {
					count++;
				}
			}
		}
		out.println(count);
		exit();
	}
}
