import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();

		int[][] X = new int[N][D];

		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			}
		}
		int ans = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
	}
	public static int d2(int[] y, int[] z,int D) {
		int d2 = 0;

		int sum = 0;
		for(int i=0;i<D;i++) {
			sum += (y[i]-z[i])*(y[i]-z[i]);
		}
		d2 = sum;

		return d2;
	}
    // 平方数かどうかを調べる。
    public static boolean isSquareNumber (int number) {
        if (number < 0) {
            throw new IllegalArgumentException("Argument must be 0 and over.");
        }
        double sqrtOfNumber = Math.sqrt(number);
        return (isInteger(sqrtOfNumber));
    }

    // 整数かどうかを調べる。
    public static boolean isInteger (double number) {
        return (number == Math.floor(number));
    }
} import java.io.FileNotFoundException; FileNotFoundException java.io import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();

		int[][] X = new int[N][D];

		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			}
		}
		int ans = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
	}
	public static int d2(int[] y, int[] z,int D) {
		int d2 = 0;

		int sum = 0;
		for(int i=0;i<D;i++) {
			sum += (y[i]-z[i])*(y[i]-z[i]);
		}
		d2 = sum;

		return d2;
	}
    // 平方数かどうかを調べる。
    public static boolean isSquareNumber (int number) {
        if (number < 0) {
            throw new IllegalArgumentException("Argument must be 0 and over.");
        }
        double sqrtOfNumber = Math.sqrt(number);
        return (isInteger(sqrtOfNumber));
    }

    // 整数かどうかを調べる。
    public static boolean isInteger (double number) {
        return (number == Math.floor(number));
    }
} Main public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();

		int[][] X = new int[N][D];

		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			}
		}
		int ans = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
	} main {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();

		int[][] X = new int[N][D];

		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			}
		}
		int ans = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
	} 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 int[][] X = new int[N][D]; X new int[N][D] N D for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			}
		} {
			for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			}
		} for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			} int j=0; int j=0; j 0 j<D j D j++ j++ j {
				X[i][j]= sc.nextInt();
			} {
				X[i][j]= sc.nextInt();
			} X[i][j]= sc.nextInt() X[i][j] X[i] X i j sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					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++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			}
		} {
			for(int j=i+1;j<N;j++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			}
		} for(int j=i+1;j<N;j++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			} int j=i+1; int j=i+1; j i+1 i 1 j<N j N j++ j++ j {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			} {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			} int[] a = X[i]; a X[i] X i int[] b = X[j]; b X[j] X j int d2  = d2(a,b,D); d2 d2(a,b,D) d2 a b D if(isSquareNumber(d2)) {
					ans ++;
				} isSquareNumber(d2) isSquareNumber d2 {
					ans ++;
				} ans ++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static int d2(int[] y, int[] z,int D) {
		int d2 = 0;

		int sum = 0;
		for(int i=0;i<D;i++) {
			sum += (y[i]-z[i])*(y[i]-z[i]);
		}
		d2 = sum;

		return d2;
	} d2 {
		int d2 = 0;

		int sum = 0;
		for(int i=0;i<D;i++) {
			sum += (y[i]-z[i])*(y[i]-z[i]);
		}
		d2 = sum;

		return d2;
	} int d2 = 0; d2 0 int sum = 0; sum 0 for(int i=0;i<D;i++) {
			sum += (y[i]-z[i])*(y[i]-z[i]);
		} int i=0; int i=0; i 0 i<D i D i++ i++ i {
			sum += (y[i]-z[i])*(y[i]-z[i]);
		} {
			sum += (y[i]-z[i])*(y[i]-z[i]);
		} sum += (y[i]-z[i])*(y[i]-z[i]) sum (y[i]-z[i])*(y[i]-z[i]) (y[i]-z[i]) y[i] y i z[i] z i (y[i]-z[i]) y[i] y i z[i] z i d2 = sum d2 sum return d2; d2 int[] y y int[] z z int D D // 平方数かどうかを調べる。
    public static boolean isSquareNumber (int number) {
        if (number < 0) {
            throw new IllegalArgumentException("Argument must be 0 and over.");
        }
        double sqrtOfNumber = Math.sqrt(number);
        return (isInteger(sqrtOfNumber));
    } isSquareNumber {
        if (number < 0) {
            throw new IllegalArgumentException("Argument must be 0 and over.");
        }
        double sqrtOfNumber = Math.sqrt(number);
        return (isInteger(sqrtOfNumber));
    } if (number < 0) {
            throw new IllegalArgumentException("Argument must be 0 and over.");
        } number < 0 number 0 {
            throw new IllegalArgumentException("Argument must be 0 and over.");
        } throw new IllegalArgumentException("Argument must be 0 and over."); new IllegalArgumentException("Argument must be 0 and over.") double sqrtOfNumber = Math.sqrt(number); sqrtOfNumber Math.sqrt(number) Math.sqrt Math number return (isInteger(sqrtOfNumber)); (isInteger(sqrtOfNumber)) isInteger sqrtOfNumber int number number // 整数かどうかを調べる。
    public static boolean isInteger (double number) {
        return (number == Math.floor(number));
    } isInteger {
        return (number == Math.floor(number));
    } return (number == Math.floor(number)); (number == Math.floor(number)) number Math.floor(number) Math.floor Math number double number number public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();

		int[][] X = new int[N][D];

		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			}
		}
		int ans = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
	}
	public static int d2(int[] y, int[] z,int D) {
		int d2 = 0;

		int sum = 0;
		for(int i=0;i<D;i++) {
			sum += (y[i]-z[i])*(y[i]-z[i]);
		}
		d2 = sum;

		return d2;
	}
    // 平方数かどうかを調べる。
    public static boolean isSquareNumber (int number) {
        if (number < 0) {
            throw new IllegalArgumentException("Argument must be 0 and over.");
        }
        double sqrtOfNumber = Math.sqrt(number);
        return (isInteger(sqrtOfNumber));
    }

    // 整数かどうかを調べる。
    public static boolean isInteger (double number) {
        return (number == Math.floor(number));
    }
} public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();

		int[][] X = new int[N][D];

		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			}
		}
		int ans = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
	}
	public static int d2(int[] y, int[] z,int D) {
		int d2 = 0;

		int sum = 0;
		for(int i=0;i<D;i++) {
			sum += (y[i]-z[i])*(y[i]-z[i]);
		}
		d2 = sum;

		return d2;
	}
    // 平方数かどうかを調べる。
    public static boolean isSquareNumber (int number) {
        if (number < 0) {
            throw new IllegalArgumentException("Argument must be 0 and over.");
        }
        double sqrtOfNumber = Math.sqrt(number);
        return (isInteger(sqrtOfNumber));
    }

    // 整数かどうかを調べる。
    public static boolean isInteger (double number) {
        return (number == Math.floor(number));
    }
} Main
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();

		int[][] X = new int[N][D];

		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				X[i][j]= sc.nextInt();
			}
		}
		int ans = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				int[] a = X[i];
				int[] b = X[j];
				int d2  = d2(a,b,D);
				if(isSquareNumber(d2)) {
					ans ++;
				}
			}
		}
		System.out.println(ans);
	}
	public static int d2(int[] y, int[] z,int D) {
		int d2 = 0;

		int sum = 0;
		for(int i=0;i<D;i++) {
			sum += (y[i]-z[i])*(y[i]-z[i]);
		}
		d2 = sum;

		return d2;
	}
    // 平方数かどうかを調べる。
    public static boolean isSquareNumber (int number) {
        if (number < 0) {
            throw new IllegalArgumentException("Argument must be 0 and over.");
        }
        double sqrtOfNumber = Math.sqrt(number);
        return (isInteger(sqrtOfNumber));
    }

    // 整数かどうかを調べる。
    public static boolean isInteger (double number) {
        return (number == Math.floor(number));
    }
}
