import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < x.length; i++) {
            for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int integerNum = 0;
        for (int i = 0; i < x.length; i++) {
            for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            }
        }
        System.out.println(integerNum);
        sc.close();
    }
} 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();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < x.length; i++) {
            for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int integerNum = 0;
        for (int i = 0; i < x.length; i++) {
            for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            }
        }
        System.out.println(integerNum);
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < x.length; i++) {
            for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int integerNum = 0;
        for (int i = 0; i < x.length; i++) {
            for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            }
        }
        System.out.println(integerNum);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < x.length; i++) {
            for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int integerNum = 0;
        for (int i = 0; i < x.length; i++) {
            for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            }
        }
        System.out.println(integerNum);
        sc.close();
    } 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[][] x = new int[n][d]; x new int[n][d] n d for (int i = 0; i < x.length; i++) {
            for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < x.length i x.length x x.length i++ i++ i {
            for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < x[i].length j x[i].length x[i] x i x[i].length 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 integerNum = 0; integerNum 0 for (int i = 0; i < x.length; i++) {
            for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            }
        } int i = 0; int i = 0; i 0 i < x.length i x.length x x.length i++ i++ i {
            for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            }
        } {
            for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            }
        } for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < x.length j x.length x x.length j++ j++ j {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            } {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            } int sum = 0; sum 0 for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                } int k = 0; int k = 0; k 0 k < x[i].length k x[i].length x[i] x i x[i].length k++ k++ k {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                } {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                } sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) sum (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k boolean isInteger = false; isInteger false for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                } int k = 0; int k = 0; k 0 k <= sum k sum k++ k++ k {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                } {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                } if (k * k == sum) {
                        isInteger = true;
                    } k * k == sum k * k k k sum {
                        isInteger = true;
                    } isInteger = true isInteger true if (isInteger) {
                    integerNum++;
                } isInteger {
                    integerNum++;
                } integerNum++ integerNum System.out.println(integerNum) System.out.println System.out System System.out integerNum sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < x.length; i++) {
            for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int integerNum = 0;
        for (int i = 0; i < x.length; i++) {
            for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            }
        }
        System.out.println(integerNum);
        sc.close();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < x.length; i++) {
            for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int integerNum = 0;
        for (int i = 0; i < x.length; i++) {
            for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            }
        }
        System.out.println(integerNum);
        sc.close();
    }
} Main
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < x.length; i++) {
            for (int j = 0; j < x[i].length; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        int integerNum = 0;
        for (int i = 0; i < x.length; i++) {
            for (int j = i + 1; j < x.length; j++) {
                int sum = 0;
                for (int k = 0; k < x[i].length; k++) {
                    sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                boolean isInteger = false;
                for (int k = 0; k <= sum; k++) {
                    if (k * k == sum) {
                        isInteger = true;
                    }
                }
                if (isInteger) {
                    integerNum++;
                }
            }
        }
        System.out.println(integerNum);
        sc.close();
    }
}