import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] condstr = in.nextLine().split(" ");
        int num = Integer.parseInt(condstr[0]);
        int dim = Integer.parseInt(condstr[1]);
        int[][] point = new int[num][dim];
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            }
        }
        in.close();
        int count = 0;
        for (int i = 0; i < num - 1; i++) {
            for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] condstr = in.nextLine().split(" ");
        int num = Integer.parseInt(condstr[0]);
        int dim = Integer.parseInt(condstr[1]);
        int[][] point = new int[num][dim];
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            }
        }
        in.close();
        int count = 0;
        for (int i = 0; i < num - 1; i++) {
            for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] condstr = in.nextLine().split(" ");
        int num = Integer.parseInt(condstr[0]);
        int dim = Integer.parseInt(condstr[1]);
        int[][] point = new int[num][dim];
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            }
        }
        in.close();
        int count = 0;
        for (int i = 0; i < num - 1; i++) {
            for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            }
        }
        System.out.println(count);
    } main {
        Scanner in = new Scanner(System.in);
        String[] condstr = in.nextLine().split(" ");
        int num = Integer.parseInt(condstr[0]);
        int dim = Integer.parseInt(condstr[1]);
        int[][] point = new int[num][dim];
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            }
        }
        in.close();
        int count = 0;
        for (int i = 0; i < num - 1; i++) {
            for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            }
        }
        System.out.println(count);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) String[] condstr = in.nextLine().split(" "); condstr in.nextLine().split(" ") in.nextLine().split in.nextLine() in.nextLine in " " int num = Integer.parseInt(condstr[0]); num Integer.parseInt(condstr[0]) Integer.parseInt Integer condstr[0] condstr 0 int dim = Integer.parseInt(condstr[1]); dim Integer.parseInt(condstr[1]) Integer.parseInt Integer condstr[1] condstr 1 int[][] point = new int[num][dim]; point new int[num][dim] num dim for (int i = 0; i < num; i++) {
            for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            }
        } int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
            for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            }
        } {
            for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            }
        } for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            } int j = 0; int j = 0; j 0 j < dim j dim j++ j++ j {
                point[i][j] = Integer.parseInt(in.next());
            } {
                point[i][j] = Integer.parseInt(in.next());
            } point[i][j] = Integer.parseInt(in.next()) point[i][j] point[i] point i j Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in in.close() in.close in int count = 0; count 0 for (int i = 0; i < num - 1; i++) {
            for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            }
        } int i = 0; int i = 0; i 0 i < num - 1 i num - 1 num 1 i++ i++ i {
            for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            }
        } {
            for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            }
        } for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            } int j = 1 + i; int j = 1 + i; j 1 + i 1 i j < num j num j++ j++ j {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            } {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            } int distsq = 0; distsq 0 for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                } int k = 0; int k = 0; k 0 k < dim k dim k++ k++ k {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                } {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                } distsq += Math.pow((point[i][k] - point[j][k]), 2) distsq Math.pow((point[i][k] - point[j][k]), 2) Math.pow Math (point[i][k] - point[j][k]) point[i][k] point[i] point i k point[j][k] point[j] point j k 2 double dist = Math.sqrt(distsq); dist Math.sqrt(distsq) Math.sqrt Math distsq int distint = 0; distint 0 distint += Math.pow((int) (dist), 2) distint Math.pow((int) (dist), 2) Math.pow Math (int) (dist) 2 if (distint == distsq) {
                    count++;
                } distint == distsq distint distsq {
                    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 in = new Scanner(System.in);
        String[] condstr = in.nextLine().split(" ");
        int num = Integer.parseInt(condstr[0]);
        int dim = Integer.parseInt(condstr[1]);
        int[][] point = new int[num][dim];
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            }
        }
        in.close();
        int count = 0;
        for (int i = 0; i < num - 1; i++) {
            for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] condstr = in.nextLine().split(" ");
        int num = Integer.parseInt(condstr[0]);
        int dim = Integer.parseInt(condstr[1]);
        int[][] point = new int[num][dim];
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            }
        }
        in.close();
        int count = 0;
        for (int i = 0; i < num - 1; i++) {
            for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] condstr = in.nextLine().split(" ");
        int num = Integer.parseInt(condstr[0]);
        int dim = Integer.parseInt(condstr[1]);
        int[][] point = new int[num][dim];
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < dim; j++) {
                point[i][j] = Integer.parseInt(in.next());
            }
        }
        in.close();
        int count = 0;
        for (int i = 0; i < num - 1; i++) {
            for (int j = 1 + i; j < num; j++) {
                int distsq = 0;
                for (int k = 0; k < dim; k++) {
                    distsq += Math.pow((point[i][k] - point[j][k]), 2);
                }
                double dist = Math.sqrt(distsq);
                int distint = 0;
                distint += Math.pow((int) (dist), 2);
                if (distint == distsq) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}
