import java.util.Scanner;

public class Main {
    static int N;
    static int D;
    static int[][] x;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        D = scanner.nextInt();

        x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        scanner.close();

        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    static int N;
    static int D;
    static int[][] x;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        D = scanner.nextInt();

        x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        scanner.close();

        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
} Main static int N; N static int D; D static int[][] x; x public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        D = scanner.nextInt();

        x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        scanner.close();

        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    } main {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        D = scanner.nextInt();

        x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        scanner.close();

        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) N = scanner.nextInt() N scanner.nextInt() scanner.nextInt scanner D = scanner.nextInt() D scanner.nextInt() scanner.nextInt scanner 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] = scanner.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] = scanner.nextInt();
            }
        } {
            for (int j = 0; j < D; j++) {
                x[i][j] = scanner.nextInt();
            }
        } for (int j = 0; j < D; j++) {
                x[i][j] = scanner.nextInt();
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                x[i][j] = scanner.nextInt();
            } {
                x[i][j] = scanner.nextInt();
            } x[i][j] = scanner.nextInt() x[i][j] x[i] x i j scanner.nextInt() scanner.nextInt scanner scanner.close() scanner.close scanner int ans = 0; ans 0 for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        } {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        } for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            } {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            } int sum = 0; sum 0 for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                } {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                } sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) sum (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k double sq = Math.sqrt(sum); sq Math.sqrt(sum) Math.sqrt Math sum if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                } Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE Math.abs(sq - Math.round(sq)) Math.abs Math sq - Math.round(sq) sq Math.round(sq) Math.round Math sq Double.MIN_VALUE Double Double.MIN_VALUE {
                    ans++;
                } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main {
    static int N;
    static int D;
    static int[][] x;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        D = scanner.nextInt();

        x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        scanner.close();

        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
} public class Main {
    static int N;
    static int D;
    static int[][] x;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        D = scanner.nextInt();

        x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        scanner.close();

        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {
    static int N;
    static int D;
    static int[][] x;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        D = scanner.nextInt();

        x = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                x[i][j] = scanner.nextInt();
            }
        }

        scanner.close();

        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                double sq = Math.sqrt(sum);
                if(Math.abs(sq - Math.round(sq)) < Double.MIN_VALUE) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}