import java.util.Scanner;

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

        int counter = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            }
        }

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

        int counter = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            }
        }

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

        int counter = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            }
        }

        System.out.println(counter);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] point = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                point[i][j] = Integer.parseInt(sc.next());
            }
        }

        int counter = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            }
        }

        System.out.println(counter);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int D = Integer.parseInt(sc.next()); D Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[][] point = new int[N][D]; point new int[N][D] N D for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                point[i][j] = Integer.parseInt(sc.next());
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for (int j = 0; j < D; j++) {
                point[i][j] = Integer.parseInt(sc.next());
            }
        } {
            for (int j = 0; j < D; j++) {
                point[i][j] = Integer.parseInt(sc.next());
            }
        } for (int j = 0; j < D; j++) {
                point[i][j] = Integer.parseInt(sc.next());
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                point[i][j] = Integer.parseInt(sc.next());
            } {
                point[i][j] = Integer.parseInt(sc.next());
            } point[i][j] = Integer.parseInt(sc.next()) point[i][j] point[i] point i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int counter = 0; counter 0 for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            }
        } {
            for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            }
        } for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            } {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            } int tmpSum = 0; tmpSum 0 for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                } {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                } tmpSum += Math.pow(point[i][k] - point[j][k], 2) tmpSum 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 int tmp = (int) Math.sqrt(tmpSum); tmp (int) Math.sqrt(tmpSum) Math.sqrt Math tmpSum if (tmpSum == tmp * tmp) {
                    counter++;
                } tmpSum == tmp * tmp tmpSum tmp * tmp tmp tmp {
                    counter++;
                } counter++ counter System.out.println(counter) System.out.println System.out System System.out counter String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int[][] point = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                point[i][j] = Integer.parseInt(sc.next());
            }
        }

        int counter = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            }
        }

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

        int counter = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            }
        }

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

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

        int counter = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int tmpSum = 0;
                for (int k = 0; k < D; k++) {
                    tmpSum += Math.pow(point[i][k] - point[j][k], 2);
                }

                int tmp = (int) Math.sqrt(tmpSum);

                if (tmpSum == tmp * tmp) {
                    counter++;
                }
            }
        }

        System.out.println(counter);
    }
}