import java.util.Scanner;

public class Main {
    //
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt();
        int[][] A = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        System.out.println(sln(A, n, d));
        sc.close();
    }

    static int sln(int[][] A, int n, int d) {
        int res = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        }
        return res;
    }

    static boolean helper(int[] A, int[] B, int d) {
        int sum = 0;
        for (int i = 0; i < d; i++) {
            sum += Math.pow(A[i] - B[i], 2);
        }
        int m = (int) Math.sqrt(sum);
        if (m * m == sum) return true;
        return false;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    //
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt();
        int[][] A = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        System.out.println(sln(A, n, d));
        sc.close();
    }

    static int sln(int[][] A, int n, int d) {
        int res = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        }
        return res;
    }

    static boolean helper(int[] A, int[] B, int d) {
        int sum = 0;
        for (int i = 0; i < d; i++) {
            sum += Math.pow(A[i] - B[i], 2);
        }
        int m = (int) Math.sqrt(sum);
        if (m * m == sum) return true;
        return false;
    }
} Main //
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt();
        int[][] A = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        System.out.println(sln(A, n, d));
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt();
        int[][] A = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        System.out.println(sln(A, n, d));
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int[][] A = new int[n][d]; A new int[n][d] n d for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                A[i][j] = sc.nextInt();
            } {
                A[i][j] = sc.nextInt();
            } A[i][j] = sc.nextInt() A[i][j] A[i] A i j sc.nextInt() sc.nextInt sc System.out.println(sln(A, n, d)) System.out.println System.out System System.out sln(A, n, d) sln A n d sc.close() sc.close sc String[] args args static int sln(int[][] A, int n, int d) {
        int res = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        }
        return res;
    } sln {
        int res = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        }
        return res;
    } int res = 0; res 0 for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        } {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        } for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            } {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            } int[] B = A[i]; B A[i] A i int[] C = A[j]; C A[j] A j if (helper(B, C, d)) res++; helper(B, C, d) helper B C d res++ res return res; res int[][] A A int n n int d d static boolean helper(int[] A, int[] B, int d) {
        int sum = 0;
        for (int i = 0; i < d; i++) {
            sum += Math.pow(A[i] - B[i], 2);
        }
        int m = (int) Math.sqrt(sum);
        if (m * m == sum) return true;
        return false;
    } helper {
        int sum = 0;
        for (int i = 0; i < d; i++) {
            sum += Math.pow(A[i] - B[i], 2);
        }
        int m = (int) Math.sqrt(sum);
        if (m * m == sum) return true;
        return false;
    } int sum = 0; sum 0 for (int i = 0; i < d; i++) {
            sum += Math.pow(A[i] - B[i], 2);
        } int i = 0; int i = 0; i 0 i < d i d i++ i++ i {
            sum += Math.pow(A[i] - B[i], 2);
        } {
            sum += Math.pow(A[i] - B[i], 2);
        } sum += Math.pow(A[i] - B[i], 2) sum Math.pow(A[i] - B[i], 2) Math.pow Math A[i] - B[i] A[i] A i B[i] B i 2 int m = (int) Math.sqrt(sum); m (int) Math.sqrt(sum) Math.sqrt Math sum if (m * m == sum) return true; m * m == sum m * m m m sum return true; true return false; false int[] A A int[] B B int d d public class Main {
    //
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt();
        int[][] A = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        System.out.println(sln(A, n, d));
        sc.close();
    }

    static int sln(int[][] A, int n, int d) {
        int res = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        }
        return res;
    }

    static boolean helper(int[] A, int[] B, int d) {
        int sum = 0;
        for (int i = 0; i < d; i++) {
            sum += Math.pow(A[i] - B[i], 2);
        }
        int m = (int) Math.sqrt(sum);
        if (m * m == sum) return true;
        return false;
    }
} public class Main {
    //
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt();
        int[][] A = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        System.out.println(sln(A, n, d));
        sc.close();
    }

    static int sln(int[][] A, int n, int d) {
        int res = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        }
        return res;
    }

    static boolean helper(int[] A, int[] B, int d) {
        int sum = 0;
        for (int i = 0; i < d; i++) {
            sum += Math.pow(A[i] - B[i], 2);
        }
        int m = (int) Math.sqrt(sum);
        if (m * m == sum) return true;
        return false;
    }
} Main
import java.util.Scanner;

public class Main {
    //
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt();
        int[][] A = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        System.out.println(sln(A, n, d));
        sc.close();
    }

    static int sln(int[][] A, int n, int d) {
        int res = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        }
        return res;
    }

    static boolean helper(int[] A, int[] B, int d) {
        int sum = 0;
        for (int i = 0; i < d; i++) {
            sum += Math.pow(A[i] - B[i], 2);
        }
        int m = (int) Math.sqrt(sum);
        if (m * m == sum) return true;
        return false;
    }
}
