import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int points = Integer.parseInt(sc.next());
        int dimensions = Integer.parseInt(sc.next());
        
        int[][] coordinate = new int[points][dimensions];
        
        for (int i = 0; i < points; i++) {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        }

        int intCount = 0;
        for (int i = 0; i < (points - 1); i++) {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        }

        System.out.println(intCount);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int points = Integer.parseInt(sc.next());
        int dimensions = Integer.parseInt(sc.next());
        
        int[][] coordinate = new int[points][dimensions];
        
        for (int i = 0; i < points; i++) {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        }

        int intCount = 0;
        for (int i = 0; i < (points - 1); i++) {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        }

        System.out.println(intCount);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int points = Integer.parseInt(sc.next());
        int dimensions = Integer.parseInt(sc.next());
        
        int[][] coordinate = new int[points][dimensions];
        
        for (int i = 0; i < points; i++) {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        }

        int intCount = 0;
        for (int i = 0; i < (points - 1); i++) {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        }

        System.out.println(intCount);
    } main {
        Scanner sc = new Scanner(System.in);
        int points = Integer.parseInt(sc.next());
        int dimensions = Integer.parseInt(sc.next());
        
        int[][] coordinate = new int[points][dimensions];
        
        for (int i = 0; i < points; i++) {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        }

        int intCount = 0;
        for (int i = 0; i < (points - 1); i++) {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        }

        System.out.println(intCount);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int points = Integer.parseInt(sc.next()); points Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int dimensions = Integer.parseInt(sc.next()); dimensions Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[][] coordinate = new int[points][dimensions]; coordinate new int[points][dimensions] points dimensions for (int i = 0; i < points; i++) {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        } int i = 0; int i = 0; i 0 i < points i points i++ i++ i {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        } {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        } for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            } int j = 0; int j = 0; j 0 j < dimensions j dimensions j++ j++ j {
                coordinate[i][j] = Integer.parseInt(sc.next());
            } {
                coordinate[i][j] = Integer.parseInt(sc.next());
            } coordinate[i][j] = Integer.parseInt(sc.next()) coordinate[i][j] coordinate[i] coordinate i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int intCount = 0; intCount 0 for (int i = 0; i < (points - 1); i++) {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        } int i = 0; int i = 0; i 0 i < (points - 1) i (points - 1) points 1 i++ i++ i {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        } {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        } for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < points j points j++ j++ j {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            } {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            } int pointDistance = 0; pointDistance 0 for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                } int dimension = 0; int dimension = 0; dimension 0 dimension < dimensions dimension dimensions dimension++ dimension++ dimension {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                } {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                } pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2)) pointDistance Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2)) Math.abs Math Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2) Math.pow Math coordinate[i][dimension] - coordinate[j][dimension] coordinate[i][dimension] coordinate[i] coordinate i dimension coordinate[j][dimension] coordinate[j] coordinate j dimension 2 double distance = Math.sqrt(pointDistance); distance Math.sqrt(pointDistance) Math.sqrt Math pointDistance if ((distance % 1) == 0) {
                    intCount++;
                } (distance % 1) == 0 (distance % 1) distance 1 0 {
                    intCount++;
                } intCount++ intCount System.out.println(intCount) System.out.println System.out System System.out intCount String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int points = Integer.parseInt(sc.next());
        int dimensions = Integer.parseInt(sc.next());
        
        int[][] coordinate = new int[points][dimensions];
        
        for (int i = 0; i < points; i++) {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        }

        int intCount = 0;
        for (int i = 0; i < (points - 1); i++) {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        }

        System.out.println(intCount);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int points = Integer.parseInt(sc.next());
        int dimensions = Integer.parseInt(sc.next());
        
        int[][] coordinate = new int[points][dimensions];
        
        for (int i = 0; i < points; i++) {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        }

        int intCount = 0;
        for (int i = 0; i < (points - 1); i++) {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        }

        System.out.println(intCount);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int points = Integer.parseInt(sc.next());
        int dimensions = Integer.parseInt(sc.next());
        
        int[][] coordinate = new int[points][dimensions];
        
        for (int i = 0; i < points; i++) {
            for (int j = 0; j < dimensions; j++) {
                coordinate[i][j] = Integer.parseInt(sc.next());
            }
        }

        int intCount = 0;
        for (int i = 0; i < (points - 1); i++) {
            for (int j = i + 1; j < points; j++) {
                int pointDistance = 0;

                for (int dimension = 0; dimension < dimensions; dimension++) {
                    pointDistance += Math.abs(Math.pow(coordinate[i][dimension] - coordinate[j][dimension], 2));
                }

                double distance = Math.sqrt(pointDistance);
                if ((distance % 1) == 0) {
                    intCount++;
                }
            }
        }

        System.out.println(intCount);
    }
}