import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        final int DIMENSION = scan.nextInt();
        int[][] points = new int [NUM][DIMENSION];
        for(int i = 0; i < NUM; i++){
            for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            }
        }

        // search
        int count = 0;
        for(int i = 0; i < NUM - 1; i++){
            for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }

        // answer
        System.out.println(count);

    }
} import java.util.Scanner; Scanner java.util public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        final int DIMENSION = scan.nextInt();
        int[][] points = new int [NUM][DIMENSION];
        for(int i = 0; i < NUM; i++){
            for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            }
        }

        // search
        int count = 0;
        for(int i = 0; i < NUM - 1; i++){
            for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }

        // answer
        System.out.println(count);

    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        final int DIMENSION = scan.nextInt();
        int[][] points = new int [NUM][DIMENSION];
        for(int i = 0; i < NUM; i++){
            for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            }
        }

        // search
        int count = 0;
        for(int i = 0; i < NUM - 1; i++){
            for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }

        // answer
        System.out.println(count);

    } main {
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        final int DIMENSION = scan.nextInt();
        int[][] points = new int [NUM][DIMENSION];
        for(int i = 0; i < NUM; i++){
            for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            }
        }

        // search
        int count = 0;
        for(int i = 0; i < NUM - 1; i++){
            for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }

        // answer
        System.out.println(count);

    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) final int NUM = scan.nextInt(); NUM scan.nextInt() scan.nextInt scan final int DIMENSION = scan.nextInt(); DIMENSION scan.nextInt() scan.nextInt scan int[][] points = new int [NUM][DIMENSION]; points new int [NUM][DIMENSION] NUM DIMENSION for(int i = 0; i < NUM; i++){
            for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < NUM i NUM i++ i++ i {
            for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            }
        } {
            for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            }
        } for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            } int j = 0; int j = 0; j 0 j < DIMENSION j DIMENSION j++ j++ j {
                points[i][j] = scan.nextInt();
            } {
                points[i][j] = scan.nextInt();
            } points[i][j] = scan.nextInt() points[i][j] points[i] points i j scan.nextInt() scan.nextInt scan int count = 0; count 0 for(int i = 0; i < NUM - 1; i++){
            for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        } int i = 0; int i = 0; i 0 i < NUM - 1 i NUM - 1 NUM 1 i++ i++ i {
            for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        } {
            for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        } for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < NUM j NUM j++ j++ j {
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            } {
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            } double sum = 0.0; sum 0.0 for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                } int k = 0; int k = 0; k 0 k < DIMENSION k DIMENSION k++ k++ k {
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                } {
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                } sum += Math.pow(points[i][k] - points[j][k] , 2) sum Math.pow(points[i][k] - points[j][k] , 2) Math.pow Math points[i][k] - points[j][k] points[i][k] points[i] points i k points[j][k] points[j] points j k 2 sum = Math.sqrt(sum) sum Math.sqrt(sum) Math.sqrt Math sum if(sum == (int)sum){
                    count++;
                } sum == (int)sum sum (int)sum {
                    count++;
                } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        final int DIMENSION = scan.nextInt();
        int[][] points = new int [NUM][DIMENSION];
        for(int i = 0; i < NUM; i++){
            for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            }
        }

        // search
        int count = 0;
        for(int i = 0; i < NUM - 1; i++){
            for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }

        // answer
        System.out.println(count);

    }
} public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        final int DIMENSION = scan.nextInt();
        int[][] points = new int [NUM][DIMENSION];
        for(int i = 0; i < NUM; i++){
            for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            }
        }

        // search
        int count = 0;
        for(int i = 0; i < NUM - 1; i++){
            for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }

        // answer
        System.out.println(count);

    }
} Main
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        final int DIMENSION = scan.nextInt();
        int[][] points = new int [NUM][DIMENSION];
        for(int i = 0; i < NUM; i++){
            for(int j = 0; j < DIMENSION; j++){
                points[i][j] = scan.nextInt();
            }
        }

        // search
        int count = 0;
        for(int i = 0; i < NUM - 1; i++){
            for(int j = i + 1; j < NUM; j++){
                double sum = 0.0;
                for(int k = 0; k < DIMENSION; k++){
                    sum += Math.pow(points[i][k] - points[j][k] , 2);
                }
                sum = Math.sqrt(sum);
                if(sum == (int)sum){
                    count++;
                }
            }
        }

        // answer
        System.out.println(count);

    }
}