import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

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

        double diff = 0;
        double sqrtDist = 0;
        double dist = 0;
        boolean flg = false;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

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

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

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

        double diff = 0;
        double sqrtDist = 0;
        double dist = 0;
        boolean flg = false;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

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

        double diff = 0;
        double sqrtDist = 0;
        double dist = 0;
        boolean flg = false;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    } main {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

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

        double diff = 0;
        double sqrtDist = 0;
        double dist = 0;
        boolean flg = false;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int d = Integer.parseInt(sc.next()); d Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 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] =  Integer.parseInt(sc.next());
            }
        } 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] =  Integer.parseInt(sc.next());
            }
        } {
            for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            }
        } for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                x[i][j] =  Integer.parseInt(sc.next());
            } {
                x[i][j] =  Integer.parseInt(sc.next());
            } x[i][j] =  Integer.parseInt(sc.next()) x[i][j] x[i] x i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc double diff = 0; diff 0 double sqrtDist = 0; sqrtDist 0 double dist = 0; dist 0 boolean flg = false; flg false int count = 0; count 0 for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        } {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        } for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            } {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            } dist = 0 dist 0 for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                } {
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                } diff = x[i][k] - x[j][k] diff x[i][k] - x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k dist += diff * diff dist diff * diff diff diff sqrtDist = (int)Math.sqrt(dist) + 1 sqrtDist (int)Math.sqrt(dist) + 1 (int)Math.sqrt(dist) Math.sqrt Math dist 1 for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                } int k = 0; int k = 0; k 0 k < sqrtDist k sqrtDist k++ k++ k {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                } {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                } if (k * k == dist) {
                        count++;
                        break;
                    } k * k == dist k * k k k dist {
                        count++;
                        break;
                    } count++ count break; 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) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

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

        double diff = 0;
        double sqrtDist = 0;
        double dist = 0;
        boolean flg = false;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

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

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

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

        double diff = 0;
        double sqrtDist = 0;
        double dist = 0;
        boolean flg = false;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

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

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

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

        double diff = 0;
        double sqrtDist = 0;
        double dist = 0;
        boolean flg = false;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    }
}