import java.util.Scanner;

public class Main {

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

        int n = scanner.nextInt();
        int d = scanner.nextInt();

        int[][] arr = new int[n][d];

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < d; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }

        int count = 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++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        }

        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main {

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

        int n = scanner.nextInt();
        int d = scanner.nextInt();

        int[][] arr = new int[n][d];

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < d; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }

        int count = 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++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        }

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

        int n = scanner.nextInt();
        int d = scanner.nextInt();

        int[][] arr = new int[n][d];

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < d; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }

        int count = 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++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        }

        System.out.println(count);
    } main {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int d = scanner.nextInt();

        int[][] arr = new int[n][d];

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < d; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }

        int count = 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++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        }

        System.out.println(count);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int d = scanner.nextInt(); d scanner.nextInt() scanner.nextInt scanner int[][] arr = new int[n][d]; arr new int[n][d] n d for (int i = 0; i < n; i++) {

            for (int j = 0; j < d; j++) {
                arr[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++) {
                arr[i][j] = scanner.nextInt();
            }
        } {

            for (int j = 0; j < d; j++) {
                arr[i][j] = scanner.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                arr[i][j] = scanner.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                arr[i][j] = scanner.nextInt();
            } {
                arr[i][j] = scanner.nextInt();
            } arr[i][j] = scanner.nextInt() arr[i][j] arr[i] arr i j scanner.nextInt() scanner.nextInt scanner int count = 0; count 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++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        } 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++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        } {

            for (int j = i + 1; j < n; j++) {

                int sum = 0;
                for (int k = 0; k < d; k++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        } for (int j = i + 1; j < n; j++) {

                int sum = 0;
                for (int k = 0; k < d; k++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            } 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++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            } {

                int sum = 0;
                for (int k = 0; k < d; k++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            } int sum = 0; sum 0 for (int k = 0; k < d; k++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                } {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                } int value = Math.abs(arr[i][k] - arr[j][k]); value Math.abs(arr[i][k] - arr[j][k]) Math.abs Math arr[i][k] - arr[j][k] arr[i][k] arr[i] arr i k arr[j][k] arr[j] arr j k sum += (value * value) sum (value * value) value value double sqrt = Math.sqrt(sum); sqrt Math.sqrt(sum) Math.sqrt Math sum if (sqrt == (int) (sqrt))
                    count++; sqrt == (int) (sqrt) sqrt (int) (sqrt) 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 scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int d = scanner.nextInt();

        int[][] arr = new int[n][d];

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < d; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }

        int count = 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++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        }

        System.out.println(count);
    }
} public class Main {

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

        int n = scanner.nextInt();
        int d = scanner.nextInt();

        int[][] arr = new int[n][d];

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < d; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }

        int count = 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++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        }

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

public class Main {

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

        int n = scanner.nextInt();
        int d = scanner.nextInt();

        int[][] arr = new int[n][d];

        for (int i = 0; i < n; i++) {

            for (int j = 0; j < d; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }

        int count = 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++) {

                    int value = Math.abs(arr[i][k] - arr[j][k]);
                    sum += (value * value);
                }

                double sqrt = Math.sqrt(sum);
                if (sqrt == (int) (sqrt))
                    count++;
            }
        }

        System.out.println(count);
    }
}