import java.util.Scanner;
import java.util.ArrayList;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        Integer D = Integer.parseInt(scan.next());

        Integer array[][] = new Integer[N][D];
        double distance[] = new double[N];
        ArrayList<Double> d = new ArrayList<Double>();

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

            for(int k=i+1;k<N;k++){

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            }
        }

        int count = 0;
        for(int i=0;i<d.size();i++){
            double dd = d.get(i);
            if(d.get(i) == (int)dd){
                count++;
            }
        }

        System.out.println(count);
    }
    
    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      }
} import java.util.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        Integer D = Integer.parseInt(scan.next());

        Integer array[][] = new Integer[N][D];
        double distance[] = new double[N];
        ArrayList<Double> d = new ArrayList<Double>();

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

            for(int k=i+1;k<N;k++){

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            }
        }

        int count = 0;
        for(int i=0;i<d.size();i++){
            double dd = d.get(i);
            if(d.get(i) == (int)dd){
                count++;
            }
        }

        System.out.println(count);
    }
    
    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      }
} Main public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        Integer D = Integer.parseInt(scan.next());

        Integer array[][] = new Integer[N][D];
        double distance[] = new double[N];
        ArrayList<Double> d = new ArrayList<Double>();

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

            for(int k=i+1;k<N;k++){

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            }
        }

        int count = 0;
        for(int i=0;i<d.size();i++){
            double dd = d.get(i);
            if(d.get(i) == (int)dd){
                count++;
            }
        }

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

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        Integer D = Integer.parseInt(scan.next());

        Integer array[][] = new Integer[N][D];
        double distance[] = new double[N];
        ArrayList<Double> d = new ArrayList<Double>();

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

            for(int k=i+1;k<N;k++){

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            }
        }

        int count = 0;
        for(int i=0;i<d.size();i++){
            double dd = d.get(i);
            if(d.get(i) == (int)dd){
                count++;
            }
        }

        System.out.println(count);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) Integer N = Integer.parseInt(scan.next()); N Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan Integer D = Integer.parseInt(scan.next()); D Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan Integer array[][] = new Integer[N][D]; array new Integer[N][D] N D double distance[] = new double[N]; distance new double[N] N ArrayList<Double> d = new ArrayList<Double>(); d new ArrayList<Double>() for(int i=0;i<N;i++){
            for(int j=0;j<D;j++){
                array[i][j] = Integer.parseInt(scan.next());
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            for(int j=0;j<D;j++){
                array[i][j] = Integer.parseInt(scan.next());
            }
        } {
            for(int j=0;j<D;j++){
                array[i][j] = Integer.parseInt(scan.next());
            }
        } for(int j=0;j<D;j++){
                array[i][j] = Integer.parseInt(scan.next());
            } int j=0; int j=0; j 0 j<D j D j++ j++ j {
                array[i][j] = Integer.parseInt(scan.next());
            } {
                array[i][j] = Integer.parseInt(scan.next());
            } array[i][j] = Integer.parseInt(scan.next()) array[i][j] array[i] array i j Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan for(int i=0;i<N;i++){

            for(int k=i+1;k<N;k++){

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {

            for(int k=i+1;k<N;k++){

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            }
        } {

            for(int k=i+1;k<N;k++){

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

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

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            } int k=i+1; int k=i+1; k i+1 i 1 k<N k N k++ k++ k {

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            } {

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            } int sum = 0; sum 0 for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                } int j=0; int j=0; j 0 j<D j D j++ j++ j {
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                } {
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                } if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    } i != N-1 i N-1 N 1 {
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    } sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j])) sum Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j])) Math.abs Math (array[i][j] - array[k][j]) * (array[i][j] - array[k][j]) (array[i][j] - array[k][j]) array[i][j] array[i] array i j array[k][j] array[k] array k j (array[i][j] - array[k][j]) array[i][j] array[i] array i j array[k][j] array[k] array k j {
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    } sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  ) sum Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  ) Math.abs Math (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] ) (array[i][j] - array[0][j] ) array[i][j] array[i] array i j array[0][j] array[0] array 0 j (array[i][j] - array[0][j] ) array[i][j] array[i] array i j array[0][j] array[0] array 0 j d.add(Math.sqrt(sum)) d.add d Math.sqrt(sum) Math.sqrt Math sum int count = 0; count 0 for(int i=0;i<d.size();i++){
            double dd = d.get(i);
            if(d.get(i) == (int)dd){
                count++;
            }
        } int i=0; int i=0; i 0 i<d.size() i d.size() d.size d i++ i++ i {
            double dd = d.get(i);
            if(d.get(i) == (int)dd){
                count++;
            }
        } {
            double dd = d.get(i);
            if(d.get(i) == (int)dd){
                count++;
            }
        } double dd = d.get(i); dd d.get(i) d.get d i if(d.get(i) == (int)dd){
                count++;
            } d.get(i) == (int)dd d.get(i) d.get d i (int)dd {
                count++;
            } count++ count System.out.println(count) System.out.println System.out System System.out count String args[] args static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      } factorial {
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      } if(n == 0){
          return 1;
        } n == 0 n 0 {
          return 1;
        } return 1; 1 return n * factorial(n-1); n * factorial(n-1) n factorial(n-1) factorial n-1 n 1 int n n public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        Integer D = Integer.parseInt(scan.next());

        Integer array[][] = new Integer[N][D];
        double distance[] = new double[N];
        ArrayList<Double> d = new ArrayList<Double>();

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

            for(int k=i+1;k<N;k++){

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            }
        }

        int count = 0;
        for(int i=0;i<d.size();i++){
            double dd = d.get(i);
            if(d.get(i) == (int)dd){
                count++;
            }
        }

        System.out.println(count);
    }
    
    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      }
} public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        Integer D = Integer.parseInt(scan.next());

        Integer array[][] = new Integer[N][D];
        double distance[] = new double[N];
        ArrayList<Double> d = new ArrayList<Double>();

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

            for(int k=i+1;k<N;k++){

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            }
        }

        int count = 0;
        for(int i=0;i<d.size();i++){
            double dd = d.get(i);
            if(d.get(i) == (int)dd){
                count++;
            }
        }

        System.out.println(count);
    }
    
    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      }
} Main
import java.util.Scanner;
import java.util.ArrayList;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        Integer D = Integer.parseInt(scan.next());

        Integer array[][] = new Integer[N][D];
        double distance[] = new double[N];
        ArrayList<Double> d = new ArrayList<Double>();

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

            for(int k=i+1;k<N;k++){

                int sum = 0;
                for(int j=0;j<D;j++){
                    if(i != N-1){
                        sum += Math.abs((array[i][j] - array[k][j]) * (array[i][j] - array[k][j]));
                    }else{
                        sum += Math.abs(  (array[i][j] - array[0][j] ) * (array[i][j] - array[0][j] )  );
                    }
                }
                d.add(Math.sqrt(sum));

            }
        }

        int count = 0;
        for(int i=0;i<d.size();i++){
            double dd = d.get(i);
            if(d.get(i) == (int)dd){
                count++;
            }
        }

        System.out.println(count);
    }
    
    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      }
}