import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
        public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int ans = 0;

        String[] arr = br.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int D = Integer.parseInt(arr[1]);

        String[][] arr2 = new String[N][D];
        for (int i = 0; i < N; i++) {
            arr2[i] = br.readLine().split(" ");       
        }

        for (int i = 0; i < N - 1; i++) {
            String[] y = arr2[i];
            for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            }
        }

        out.println(ans);
        out.close();
    }

    private static int check(int D, String[] arr1, String[] arr2) {
        int sum = 0;
        for (int i = 0; i < D; i++) {
            int y = Integer.parseInt(arr1[i]);
            int z = Integer.parseInt(arr2[i]);
            sum += Math.pow(y - z, 2);
        }
        double sqrt = Math.sqrt(sum);
        return sqrt % 1 == 0 ? 1 : 0;
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io public class Main {
        public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int ans = 0;

        String[] arr = br.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int D = Integer.parseInt(arr[1]);

        String[][] arr2 = new String[N][D];
        for (int i = 0; i < N; i++) {
            arr2[i] = br.readLine().split(" ");       
        }

        for (int i = 0; i < N - 1; i++) {
            String[] y = arr2[i];
            for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            }
        }

        out.println(ans);
        out.close();
    }

    private static int check(int D, String[] arr1, String[] arr2) {
        int sum = 0;
        for (int i = 0; i < D; i++) {
            int y = Integer.parseInt(arr1[i]);
            int z = Integer.parseInt(arr2[i]);
            sum += Math.pow(y - z, 2);
        }
        double sqrt = Math.sqrt(sum);
        return sqrt % 1 == 0 ? 1 : 0;
    }
} Main public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int ans = 0;

        String[] arr = br.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int D = Integer.parseInt(arr[1]);

        String[][] arr2 = new String[N][D];
        for (int i = 0; i < N; i++) {
            arr2[i] = br.readLine().split(" ");       
        }

        for (int i = 0; i < N - 1; i++) {
            String[] y = arr2[i];
            for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            }
        }

        out.println(ans);
        out.close();
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int ans = 0;

        String[] arr = br.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int D = Integer.parseInt(arr[1]);

        String[][] arr2 = new String[N][D];
        for (int i = 0; i < N; i++) {
            arr2[i] = br.readLine().split(" ");       
        }

        for (int i = 0; i < N - 1; i++) {
            String[] y = arr2[i];
            for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            }
        }

        out.println(ans);
        out.close();
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int ans = 0; ans 0 String[] arr = br.readLine().split(" "); arr br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int N = Integer.parseInt(arr[0]); N Integer.parseInt(arr[0]) Integer.parseInt Integer arr[0] arr 0 int D = Integer.parseInt(arr[1]); D Integer.parseInt(arr[1]) Integer.parseInt Integer arr[1] arr 1 String[][] arr2 = new String[N][D]; arr2 new String[N][D] N D for (int i = 0; i < N; i++) {
            arr2[i] = br.readLine().split(" ");       
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            arr2[i] = br.readLine().split(" ");       
        } {
            arr2[i] = br.readLine().split(" ");       
        } arr2[i] = br.readLine().split(" ") arr2[i] arr2 i br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int i = 0; i < N - 1; i++) {
            String[] y = arr2[i];
            for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            }
        } int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {
            String[] y = arr2[i];
            for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            }
        } {
            String[] y = arr2[i];
            for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            }
        } String[] y = arr2[i]; y arr2[i] arr2 i for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
                String[] z = arr2[j];
                ans += check(D, y, z);
            } {
                String[] z = arr2[j];
                ans += check(D, y, z);
            } String[] z = arr2[j]; z arr2[j] arr2 j ans += check(D, y, z) ans check(D, y, z) check D y z out.println(ans) out.println out ans out.close() out.close out String[] args args private static int check(int D, String[] arr1, String[] arr2) {
        int sum = 0;
        for (int i = 0; i < D; i++) {
            int y = Integer.parseInt(arr1[i]);
            int z = Integer.parseInt(arr2[i]);
            sum += Math.pow(y - z, 2);
        }
        double sqrt = Math.sqrt(sum);
        return sqrt % 1 == 0 ? 1 : 0;
    } check {
        int sum = 0;
        for (int i = 0; i < D; i++) {
            int y = Integer.parseInt(arr1[i]);
            int z = Integer.parseInt(arr2[i]);
            sum += Math.pow(y - z, 2);
        }
        double sqrt = Math.sqrt(sum);
        return sqrt % 1 == 0 ? 1 : 0;
    } int sum = 0; sum 0 for (int i = 0; i < D; i++) {
            int y = Integer.parseInt(arr1[i]);
            int z = Integer.parseInt(arr2[i]);
            sum += Math.pow(y - z, 2);
        } int i = 0; int i = 0; i 0 i < D i D i++ i++ i {
            int y = Integer.parseInt(arr1[i]);
            int z = Integer.parseInt(arr2[i]);
            sum += Math.pow(y - z, 2);
        } {
            int y = Integer.parseInt(arr1[i]);
            int z = Integer.parseInt(arr2[i]);
            sum += Math.pow(y - z, 2);
        } int y = Integer.parseInt(arr1[i]); y Integer.parseInt(arr1[i]) Integer.parseInt Integer arr1[i] arr1 i int z = Integer.parseInt(arr2[i]); z Integer.parseInt(arr2[i]) Integer.parseInt Integer arr2[i] arr2 i sum += Math.pow(y - z, 2) sum Math.pow(y - z, 2) Math.pow Math y - z y z 2 double sqrt = Math.sqrt(sum); sqrt Math.sqrt(sum) Math.sqrt Math sum return sqrt % 1 == 0 ? 1 : 0; sqrt % 1 == 0 ? 1 : 0 sqrt % 1 == 0 sqrt % 1 sqrt 1 0 1 0 int D D String[] arr1 arr1 String[] arr2 arr2 public class Main {
        public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int ans = 0;

        String[] arr = br.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int D = Integer.parseInt(arr[1]);

        String[][] arr2 = new String[N][D];
        for (int i = 0; i < N; i++) {
            arr2[i] = br.readLine().split(" ");       
        }

        for (int i = 0; i < N - 1; i++) {
            String[] y = arr2[i];
            for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            }
        }

        out.println(ans);
        out.close();
    }

    private static int check(int D, String[] arr1, String[] arr2) {
        int sum = 0;
        for (int i = 0; i < D; i++) {
            int y = Integer.parseInt(arr1[i]);
            int z = Integer.parseInt(arr2[i]);
            sum += Math.pow(y - z, 2);
        }
        double sqrt = Math.sqrt(sum);
        return sqrt % 1 == 0 ? 1 : 0;
    }
} public class Main {
        public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int ans = 0;

        String[] arr = br.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int D = Integer.parseInt(arr[1]);

        String[][] arr2 = new String[N][D];
        for (int i = 0; i < N; i++) {
            arr2[i] = br.readLine().split(" ");       
        }

        for (int i = 0; i < N - 1; i++) {
            String[] y = arr2[i];
            for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            }
        }

        out.println(ans);
        out.close();
    }

    private static int check(int D, String[] arr1, String[] arr2) {
        int sum = 0;
        for (int i = 0; i < D; i++) {
            int y = Integer.parseInt(arr1[i]);
            int z = Integer.parseInt(arr2[i]);
            sum += Math.pow(y - z, 2);
        }
        double sqrt = Math.sqrt(sum);
        return sqrt % 1 == 0 ? 1 : 0;
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
        public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int ans = 0;

        String[] arr = br.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int D = Integer.parseInt(arr[1]);

        String[][] arr2 = new String[N][D];
        for (int i = 0; i < N; i++) {
            arr2[i] = br.readLine().split(" ");       
        }

        for (int i = 0; i < N - 1; i++) {
            String[] y = arr2[i];
            for (int j = i + 1; j < N; j++) {
                String[] z = arr2[j];
                ans += check(D, y, z);
            }
        }

        out.println(ans);
        out.close();
    }

    private static int check(int D, String[] arr1, String[] arr2) {
        int sum = 0;
        for (int i = 0; i < D; i++) {
            int y = Integer.parseInt(arr1[i]);
            int z = Integer.parseInt(arr2[i]);
            sum += Math.pow(y - z, 2);
        }
        double sqrt = Math.sqrt(sum);
        return sqrt % 1 == 0 ? 1 : 0;
    }
}
