import java.util.*;
class Main{
    public static void main(String argv[]) {
        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<N;i++){
            for(int j=0;j<D;j++){
                X[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)count++;
            }
        }
        System.out.println(count);
    }
} import java.util.*; util.* java class Main{
    public static void main(String argv[]) {
        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<N;i++){
            for(int j=0;j<D;j++){
                X[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)count++;
            }
        }
        System.out.println(count);
    }
} Main public static void main(String argv[]) {
        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<N;i++){
            for(int j=0;j<D;j++){
                X[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)count++;
            }
        }
        System.out.println(count);
    } 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<N;i++){
            for(int j=0;j<D;j++){
                X[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)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[][] 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 count = 0; count 0 for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)count++;
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            for(int j=i+1;j<N;j++){
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)count++;
            }
        } {
            for(int j=i+1;j<N;j++){
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)count++;
            }
        } for(int j=i+1;j<N;j++){
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)count++;
            } int j=i+1; int j=i+1; j i+1 i 1 j<N j N j++ j++ j {
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)count++;
            } {
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)count++;
            } Double len = 0D; len 0D for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                } int k=0; int k=0; k 0 k<D k D k++ k++ k {
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                } {
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                } len += (Double) Math.pow(X[i][k] - X[j][k], 2) len (Double) 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 int len2 = (int)Math.sqrt(len); len2 (int)Math.sqrt(len) Math.sqrt Math len len = Math.sqrt(len) len Math.sqrt(len) Math.sqrt Math len if((double)len2 == len)count++; (double)len2 == len (double)len2 len count++ count System.out.println(count) System.out.println System.out System System.out count String argv[] argv
import java.util.*;
class Main{
    public static void main(String argv[]) {
        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<N;i++){
            for(int j=0;j<D;j++){
                X[i][j] = sc.nextInt();
            }
        }

        int count = 0;
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                Double len = 0D;
                for(int k=0;k<D;k++){
                    len += (Double) Math.pow(X[i][k] - X[j][k], 2);
                }
                int len2 = (int)Math.sqrt(len);
                len = Math.sqrt(len);
                if((double)len2 == len)count++;
            }
        }
        System.out.println(count);
    }
}