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());
        double[][] Xnd = new double[N][D];
        for (int i = 0; i < N; i++) {

            for (int j=0; j < D;j++) {

                Xnd[i][j] = Integer.parseInt(sc.next());
            }
        }

        sc.close();

        int ansCount = 0;

        //必要な計算量はNC2回,N個の座標のうちのi番目(1,2・・・N-1)
        for (int i = 0; i < N-1; i++) {

            //i番目に対してのj番目(i+1,2・・・N)の座標
            for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            }
        }

        System.out.println(ansCount);
    }

    public static boolean isNumber(double val) {

        boolean retval = val == Math.floor(val) ? true : false;

        return retval;
    }
} 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());
        double[][] Xnd = new double[N][D];
        for (int i = 0; i < N; i++) {

            for (int j=0; j < D;j++) {

                Xnd[i][j] = Integer.parseInt(sc.next());
            }
        }

        sc.close();

        int ansCount = 0;

        //必要な計算量はNC2回,N個の座標のうちのi番目(1,2・・・N-1)
        for (int i = 0; i < N-1; i++) {

            //i番目に対してのj番目(i+1,2・・・N)の座標
            for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            }
        }

        System.out.println(ansCount);
    }

    public static boolean isNumber(double val) {

        boolean retval = val == Math.floor(val) ? true : false;

        return retval;
    }
} 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());
        double[][] Xnd = new double[N][D];
        for (int i = 0; i < N; i++) {

            for (int j=0; j < D;j++) {

                Xnd[i][j] = Integer.parseInt(sc.next());
            }
        }

        sc.close();

        int ansCount = 0;

        //必要な計算量はNC2回,N個の座標のうちのi番目(1,2・・・N-1)
        for (int i = 0; i < N-1; i++) {

            //i番目に対してのj番目(i+1,2・・・N)の座標
            for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            }
        }

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

        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        double[][] Xnd = new double[N][D];
        for (int i = 0; i < N; i++) {

            for (int j=0; j < D;j++) {

                Xnd[i][j] = Integer.parseInt(sc.next());
            }
        }

        sc.close();

        int ansCount = 0;

        //必要な計算量はNC2回,N個の座標のうちのi番目(1,2・・・N-1)
        for (int i = 0; i < N-1; i++) {

            //i番目に対してのj番目(i+1,2・・・N)の座標
            for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            }
        }

        System.out.println(ansCount);
    } 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 double[][] Xnd = new double[N][D]; Xnd new double[N][D] N D for (int i = 0; i < N; i++) {

            for (int j=0; j < D;j++) {

                Xnd[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++) {

                Xnd[i][j] = Integer.parseInt(sc.next());
            }
        } {

            for (int j=0; j < D;j++) {

                Xnd[i][j] = Integer.parseInt(sc.next());
            }
        } for (int j=0; j < D;j++) {

                Xnd[i][j] = Integer.parseInt(sc.next());
            } int j=0; int j=0; j 0 j < D j D j++ j++ j {

                Xnd[i][j] = Integer.parseInt(sc.next());
            } {

                Xnd[i][j] = Integer.parseInt(sc.next());
            } Xnd[i][j] = Integer.parseInt(sc.next()) Xnd[i][j] Xnd[i] Xnd i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int ansCount = 0; ansCount 0 for (int i = 0; i < N-1; i++) {

            //i番目に対してのj番目(i+1,2・・・N)の座標
            for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            }
        } int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {

            //i番目に対してのj番目(i+1,2・・・N)の座標
            for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            }
        } {

            //i番目に対してのj番目(i+1,2・・・N)の座標
            for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            }
        } for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            } int j = i+1; int j = i+1; j i+1 i 1 j < N j N j++ j++ j {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            } {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            } double sum = 0; sum 0 double distance = 0; distance 0 for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                } int Dindex = 0; int Dindex = 0; Dindex 0 Dindex < D Dindex D Dindex++ Dindex++ Dindex {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                } {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                } sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2) sum Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2) Math.pow Math (Xnd[i][Dindex] - Xnd[j][Dindex]) Xnd[i][Dindex] Xnd[i] Xnd i Dindex Xnd[j][Dindex] Xnd[j] Xnd j Dindex 2 distance = Math.sqrt(sum) distance Math.sqrt(sum) Math.sqrt Math sum if (isNumber(distance)) {

                    ansCount++;
                } isNumber(distance) isNumber distance {

                    ansCount++;
                } ansCount++ ansCount System.out.println(ansCount) System.out.println System.out System System.out ansCount String[] args args public static boolean isNumber(double val) {

        boolean retval = val == Math.floor(val) ? true : false;

        return retval;
    } isNumber {

        boolean retval = val == Math.floor(val) ? true : false;

        return retval;
    } boolean retval = val == Math.floor(val) ? true : false; retval val == Math.floor(val) ? true : false val == Math.floor(val) val Math.floor(val) Math.floor Math val true false return retval; retval double val val 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());
        double[][] Xnd = new double[N][D];
        for (int i = 0; i < N; i++) {

            for (int j=0; j < D;j++) {

                Xnd[i][j] = Integer.parseInt(sc.next());
            }
        }

        sc.close();

        int ansCount = 0;

        //必要な計算量はNC2回,N個の座標のうちのi番目(1,2・・・N-1)
        for (int i = 0; i < N-1; i++) {

            //i番目に対してのj番目(i+1,2・・・N)の座標
            for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            }
        }

        System.out.println(ansCount);
    }

    public static boolean isNumber(double val) {

        boolean retval = val == Math.floor(val) ? true : false;

        return retval;
    }
} 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());
        double[][] Xnd = new double[N][D];
        for (int i = 0; i < N; i++) {

            for (int j=0; j < D;j++) {

                Xnd[i][j] = Integer.parseInt(sc.next());
            }
        }

        sc.close();

        int ansCount = 0;

        //必要な計算量はNC2回,N個の座標のうちのi番目(1,2・・・N-1)
        for (int i = 0; i < N-1; i++) {

            //i番目に対してのj番目(i+1,2・・・N)の座標
            for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            }
        }

        System.out.println(ansCount);
    }

    public static boolean isNumber(double val) {

        boolean retval = val == Math.floor(val) ? true : false;

        return retval;
    }
} 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());
        double[][] Xnd = new double[N][D];
        for (int i = 0; i < N; i++) {

            for (int j=0; j < D;j++) {

                Xnd[i][j] = Integer.parseInt(sc.next());
            }
        }

        sc.close();

        int ansCount = 0;

        //必要な計算量はNC2回,N個の座標のうちのi番目(1,2・・・N-1)
        for (int i = 0; i < N-1; i++) {

            //i番目に対してのj番目(i+1,2・・・N)の座標
            for (int j = i+1; j < N; j++) {

                double sum = 0;
                double distance = 0;

                //(Xnd[i][~]-Xnd[j][~])^2
                for (int Dindex = 0; Dindex < D; Dindex++) {

                    sum += Math.pow((Xnd[i][Dindex] - Xnd[j][Dindex]),2);
                }

                distance = Math.sqrt(sum);
                //i,j番目の座標の距離が整数ならカウント
                if (isNumber(distance)) {

                    ansCount++;
                }
            }
        }

        System.out.println(ansCount);
    }

    public static boolean isNumber(double val) {

        boolean retval = val == Math.floor(val) ? true : false;

        return retval;
    }
}
