import java.util.Scanner;

public class Main {

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

        final int n = sc.nextInt();
        final int d = sc.nextInt();
        final int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }

        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            }
        }

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

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

        final int n = sc.nextInt();
        final int d = sc.nextInt();
        final int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }

        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            }
        }

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

        final int n = sc.nextInt();
        final int d = sc.nextInt();
        final int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }

        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            }
        }

        System.out.println(ans);
    } main {
        final Scanner sc = new Scanner(System.in);

        final int n = sc.nextInt();
        final int d = sc.nextInt();
        final int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }

        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            }
        }

        System.out.println(ans);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc final int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc final int[][] x = new int[n][d]; x new int[n][d] n d for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[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++) {
                x[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                x[i][j] = sc.nextInt();
            } {
                x[i][j] = sc.nextInt();
            } x[i][j] = sc.nextInt() x[i][j] x[i] x i j sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            }
        } {
            for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            }
        } for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            } int j = i; int j = i; j i j < n j n j++ j++ j {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            } {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            } if (i == j) continue; i == j i j continue; double sum = 0; sum 0 for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                } {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                } sum += Math.pow(x[i][k] - x[j][k], 2) sum Math.pow(x[i][k] - x[j][k], 2) Math.pow Math x[i][k] - x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k 2 if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                } Math.sqrt(sum) == Math.floor(Math.sqrt(sum)) Math.sqrt(sum) Math.sqrt Math sum Math.floor(Math.sqrt(sum)) Math.floor Math Math.sqrt(sum) Math.sqrt Math sum {
                    ans++;
                } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

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

        final int n = sc.nextInt();
        final int d = sc.nextInt();
        final int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }

        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            }
        }

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

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

        final int n = sc.nextInt();
        final int d = sc.nextInt();
        final int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }

        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            }
        }

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

public class Main {

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

        final int n = sc.nextInt();
        final int d = sc.nextInt();
        final int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }

        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < d; k++) {
                    sum += Math.pow(x[i][k] - x[j][k], 2);
                }
                if (Math.sqrt(sum) == Math.floor(Math.sqrt(sum))) {
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }
}
