import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] list = new int[n][d];

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

        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] list = new int[n][d];

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

        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
} Main public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] list = new int[n][d];

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

        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        }

        System.out.println(count);
    } main {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] list = new int[n][d];

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

        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        }

        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int[][] list = new int[n][d]; list new int[n][d] n d for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
              list[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++) {
              list[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < d; j++) {
              list[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < d; j++) {
              list[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
              list[i][j] = sc.nextInt();
            } {
              list[i][j] = sc.nextInt();
            } list[i][j] = sc.nextInt() list[i][j] list[i] list i j sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        } {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        } for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            } {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            } int sum = 0; sum 0 for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                } {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                } int value = list[i][k] - list[j][k]; value list[i][k] - list[j][k] list[i][k] list[i] list i k list[j][k] list[j] list j k sum += value * value sum value * value value value double root = Math.sqrt(sum); root Math.sqrt(sum) Math.sqrt Math sum int seisu = (int) root; seisu (int) root if ((double)seisu - root == 0) {
                    count++;
                } (double)seisu - root == 0 (double)seisu - root (double)seisu root 0 {
                    count++;
                } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] list = new int[n][d];

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

        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        }

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

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] list = new int[n][d];

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

        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] list = new int[n][d];

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

        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
}
