import java.util.Scanner;

public class Main {

    public static void main( String[] args ){

        Scanner in = new Scanner(System.in);

        String[] params = in.nextLine().split(" ");
        int n = Integer.parseInt(params[0]);
        int d = Integer.parseInt(params[1]);

        int[][] x = new int[n][d];
        for( int i = 0 ; i < n ; i++ ){
            String[] rows = in.nextLine().split(" ");
            for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            }
        }

        int count = 0;
        for( int nIndex = 0 ; nIndex < n - 1 ; nIndex++ ){
            for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            }
        }

        System.out.println(count);

        return;

    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main( String[] args ){

        Scanner in = new Scanner(System.in);

        String[] params = in.nextLine().split(" ");
        int n = Integer.parseInt(params[0]);
        int d = Integer.parseInt(params[1]);

        int[][] x = new int[n][d];
        for( int i = 0 ; i < n ; i++ ){
            String[] rows = in.nextLine().split(" ");
            for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            }
        }

        int count = 0;
        for( int nIndex = 0 ; nIndex < n - 1 ; nIndex++ ){
            for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            }
        }

        System.out.println(count);

        return;

    }
} Main public static void main( String[] args ){

        Scanner in = new Scanner(System.in);

        String[] params = in.nextLine().split(" ");
        int n = Integer.parseInt(params[0]);
        int d = Integer.parseInt(params[1]);

        int[][] x = new int[n][d];
        for( int i = 0 ; i < n ; i++ ){
            String[] rows = in.nextLine().split(" ");
            for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            }
        }

        int count = 0;
        for( int nIndex = 0 ; nIndex < n - 1 ; nIndex++ ){
            for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            }
        }

        System.out.println(count);

        return;

    } main {

        Scanner in = new Scanner(System.in);

        String[] params = in.nextLine().split(" ");
        int n = Integer.parseInt(params[0]);
        int d = Integer.parseInt(params[1]);

        int[][] x = new int[n][d];
        for( int i = 0 ; i < n ; i++ ){
            String[] rows = in.nextLine().split(" ");
            for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            }
        }

        int count = 0;
        for( int nIndex = 0 ; nIndex < n - 1 ; nIndex++ ){
            for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            }
        }

        System.out.println(count);

        return;

    } Scanner in = new Scanner(System.in); in new Scanner(System.in) String[] params = in.nextLine().split(" "); params in.nextLine().split(" ") in.nextLine().split in.nextLine() in.nextLine in " " int n = Integer.parseInt(params[0]); n Integer.parseInt(params[0]) Integer.parseInt Integer params[0] params 0 int d = Integer.parseInt(params[1]); d Integer.parseInt(params[1]) Integer.parseInt Integer params[1] params 1 int[][] x = new int[n][d]; x new int[n][d] n d for( int i = 0 ; i < n ; i++ ){
            String[] rows = in.nextLine().split(" ");
            for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            }
        } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
            String[] rows = in.nextLine().split(" ");
            for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            }
        } {
            String[] rows = in.nextLine().split(" ");
            for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            }
        } String[] rows = in.nextLine().split(" "); rows in.nextLine().split(" ") in.nextLine().split in.nextLine() in.nextLine in " " for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            } int j = 0 ; int j = 0 ; j 0 j < d j d j++ j++ j {
                x[i][j] = Integer.parseInt(rows[j]);
            } {
                x[i][j] = Integer.parseInt(rows[j]);
            } x[i][j] = Integer.parseInt(rows[j]) x[i][j] x[i] x i j Integer.parseInt(rows[j]) Integer.parseInt Integer rows[j] rows j int count = 0; count 0 for( int nIndex = 0 ; nIndex < n - 1 ; nIndex++ ){
            for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            }
        } int nIndex = 0 ; int nIndex = 0 ; nIndex 0 nIndex < n - 1 nIndex n - 1 n 1 nIndex++ nIndex++ nIndex {
            for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            }
        } {
            for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            }
        } for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            } int nIndex2 = nIndex + 1 ; int nIndex2 = nIndex + 1 ; nIndex2 nIndex + 1 nIndex 1 nIndex2 < n nIndex2 n nIndex2++ nIndex2++ nIndex2 {

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            } {

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            } double square = 0; square 0 for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                } int j = 0 ; int j = 0 ; j 0 j < d j d j++ j++ j {
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                } {
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                } square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]) square (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]) (x[nIndex][j] - x[nIndex2][j]) x[nIndex][j] x[nIndex] x nIndex j x[nIndex2][j] x[nIndex2] x nIndex2 j (x[nIndex][j] - x[nIndex2][j]) x[nIndex][j] x[nIndex] x nIndex j x[nIndex2][j] x[nIndex2] x nIndex2 j double result = Math.sqrt(square); result Math.sqrt(square) Math.sqrt Math square if( result%1 == 0.0 ){
                    count++;
                } result%1 == 0.0 result%1 result 1 0.0 {
                    count++;
                } count++ count System.out.println(count) System.out.println System.out System System.out count return; String[] args args public class Main {

    public static void main( String[] args ){

        Scanner in = new Scanner(System.in);

        String[] params = in.nextLine().split(" ");
        int n = Integer.parseInt(params[0]);
        int d = Integer.parseInt(params[1]);

        int[][] x = new int[n][d];
        for( int i = 0 ; i < n ; i++ ){
            String[] rows = in.nextLine().split(" ");
            for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            }
        }

        int count = 0;
        for( int nIndex = 0 ; nIndex < n - 1 ; nIndex++ ){
            for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            }
        }

        System.out.println(count);

        return;

    }
} public class Main {

    public static void main( String[] args ){

        Scanner in = new Scanner(System.in);

        String[] params = in.nextLine().split(" ");
        int n = Integer.parseInt(params[0]);
        int d = Integer.parseInt(params[1]);

        int[][] x = new int[n][d];
        for( int i = 0 ; i < n ; i++ ){
            String[] rows = in.nextLine().split(" ");
            for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            }
        }

        int count = 0;
        for( int nIndex = 0 ; nIndex < n - 1 ; nIndex++ ){
            for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            }
        }

        System.out.println(count);

        return;

    }
} Main
import java.util.Scanner;

public class Main {

    public static void main( String[] args ){

        Scanner in = new Scanner(System.in);

        String[] params = in.nextLine().split(" ");
        int n = Integer.parseInt(params[0]);
        int d = Integer.parseInt(params[1]);

        int[][] x = new int[n][d];
        for( int i = 0 ; i < n ; i++ ){
            String[] rows = in.nextLine().split(" ");
            for( int j = 0 ; j < d ; j++ ){
                x[i][j] = Integer.parseInt(rows[j]);
            }
        }

        int count = 0;
        for( int nIndex = 0 ; nIndex < n - 1 ; nIndex++ ){
            for( int nIndex2 = nIndex + 1 ; nIndex2 < n ; nIndex2++ ){

                double square = 0;
                for( int j = 0 ; j < d ; j++ ){
                    square += (x[nIndex][j] - x[nIndex2][j])*(x[nIndex][j] - x[nIndex2][j]);
                }
                double result = Math.sqrt(square);

                if( result%1 == 0.0 ){
                    count++;
                }

            }
        }

        System.out.println(count);

        return;

    }
}