import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int[][] arr = new int[n][d];
        int count = 0;
        for (int i = 0; i < n; i++) {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        }
        br.close();
        for (int i = 1; i < n; i++) {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        }
        System.out.println(count + "\n");
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int[][] arr = new int[n][d];
        int count = 0;
        for (int i = 0; i < n; i++) {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        }
        br.close();
        for (int i = 1; i < n; i++) {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        }
        System.out.println(count + "\n");
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int[][] arr = new int[n][d];
        int count = 0;
        for (int i = 0; i < n; i++) {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        }
        br.close();
        for (int i = 1; i < n; i++) {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        }
        System.out.println(count + "\n");
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int[][] arr = new int[n][d];
        int count = 0;
        for (int i = 0; i < n; i++) {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        }
        br.close();
        for (int i = 1; i < n; i++) {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        }
        System.out.println(count + "\n");
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st = new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int n = Integer.parseInt(st.nextToken()); n Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int d = Integer.parseInt(st.nextToken()); d Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int[][] arr = new int[n][d]; arr new int[n][d] n d int count = 0; count 0 for (int i = 0; i < n; i++) {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        } {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        } StringTokenizer st1 = new StringTokenizer(br.readLine()); st1 new StringTokenizer(br.readLine()) for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            } {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            } arr[i][j] = Integer.parseInt(st1.nextToken()) arr[i][j] arr[i] arr i j Integer.parseInt(st1.nextToken()) Integer.parseInt Integer st1.nextToken() st1.nextToken st1 br.close() br.close br for (int i = 1; i < n; i++) {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        } {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        } double sumsqr = 0; sumsqr 0 for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            } int j = 1; int j = 1; j 1 j <= i j i j++ j++ j {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            } {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            } for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                } int k=0; int k=0; k 0 k<d k d k++ k++ k {
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                } {
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                } sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2) sumsqr Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2) Math.pow Math Math.abs(arr[i][k] - arr[i -j][k]) Math.abs Math arr[i][k] - arr[i -j][k] arr[i][k] arr[i] arr i k arr[i -j][k] arr[i -j] arr i -j i j k 2 double dist = Math.sqrt(sumsqr); dist Math.sqrt(sumsqr) Math.sqrt Math sumsqr if (dist==Math.floor(dist)) {
                    count++;
                } dist==Math.floor(dist) dist Math.floor(dist) Math.floor Math dist {
                    count++;
                } count++ count sumsqr = 0 sumsqr 0 System.out.println(count + "\n") System.out.println System.out System System.out count + "\n" count "\n" String[] args args public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int[][] arr = new int[n][d];
        int count = 0;
        for (int i = 0; i < n; i++) {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        }
        br.close();
        for (int i = 1; i < n; i++) {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        }
        System.out.println(count + "\n");
    }
} public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int[][] arr = new int[n][d];
        int count = 0;
        for (int i = 0; i < n; i++) {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        }
        br.close();
        for (int i = 1; i < n; i++) {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        }
        System.out.println(count + "\n");
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int[][] arr = new int[n][d];
        int count = 0;
        for (int i = 0; i < n; i++) {
            StringTokenizer st1 = new StringTokenizer(br.readLine());
            for (int j = 0; j < d; j++) {
                arr[i][j] = Integer.parseInt(st1.nextToken());
            }
        }
        br.close();
        for (int i = 1; i < n; i++) {
            double sumsqr = 0;
            for (int j = 1; j <= i; j++) {
                for(int k=0;k<d;k++){
                    sumsqr += Math.pow(Math.abs(arr[i][k] - arr[i -j][k]), 2);
                }
                double dist = Math.sqrt(sumsqr);
                if (dist==Math.floor(dist)) {
                    count++;
                }
                sumsqr = 0;
            }

        }
        System.out.println(count + "\n");
    }
}
