//package Atcoder133;

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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        List<List<Double>> list = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
            List<Double> list2 = new ArrayList<>();
            for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            }
            list.add(list2);
        }
        int squareNumCount = 0;
        for(int i = 0 ; i< N ; i++){
            for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            }
        }
        System.out.println(squareNumCount);
    }

    private static boolean isSquareNum(double squaredDistanse) {
        for(int i=1; i<=Math.sqrt(squaredDistanse); i++){
            if(i*i == squaredDistanse) return true;
        }
        return false;
    }

    private static double calSquaredDistanse(List<Double> integers, List<Double> integers1) {
        double sum = 0;
        for(int i=0; i < integers.size(); i++){
            double d = integers.get(i) - integers1.get(i);
//            sum = d>0 ? sum+d*d : sum-d;
            sum+=d*d;
        }
        return sum;
    }
}


//15hunn import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        List<List<Double>> list = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
            List<Double> list2 = new ArrayList<>();
            for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            }
            list.add(list2);
        }
        int squareNumCount = 0;
        for(int i = 0 ; i< N ; i++){
            for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            }
        }
        System.out.println(squareNumCount);
    }

    private static boolean isSquareNum(double squaredDistanse) {
        for(int i=1; i<=Math.sqrt(squaredDistanse); i++){
            if(i*i == squaredDistanse) return true;
        }
        return false;
    }

    private static double calSquaredDistanse(List<Double> integers, List<Double> integers1) {
        double sum = 0;
        for(int i=0; i < integers.size(); i++){
            double d = integers.get(i) - integers1.get(i);
//            sum = d>0 ? sum+d*d : sum-d;
            sum+=d*d;
        }
        return sum;
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        List<List<Double>> list = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
            List<Double> list2 = new ArrayList<>();
            for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            }
            list.add(list2);
        }
        int squareNumCount = 0;
        for(int i = 0 ; i< N ; i++){
            for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            }
        }
        System.out.println(squareNumCount);
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        List<List<Double>> list = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
            List<Double> list2 = new ArrayList<>();
            for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            }
            list.add(list2);
        }
        int squareNumCount = 0;
        for(int i = 0 ; i< N ; i++){
            for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            }
        }
        System.out.println(squareNumCount);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int D = scanner.nextInt(); D scanner.nextInt() scanner.nextInt scanner List<List<Double>> list = new ArrayList<>(); list new ArrayList<>() for(int i = 0 ; i < N ; i++){
            List<Double> list2 = new ArrayList<>();
            for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            }
            list.add(list2);
        } int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
            List<Double> list2 = new ArrayList<>();
            for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            }
            list.add(list2);
        } {
            List<Double> list2 = new ArrayList<>();
            for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            }
            list.add(list2);
        } List<Double> list2 = new ArrayList<>(); list2 new ArrayList<>() for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            } int j = 0 ; int j = 0 ; j 0 j< D j D j++ j++ j {
                list2.add(scanner.nextDouble());
            } {
                list2.add(scanner.nextDouble());
            } list2.add(scanner.nextDouble()) list2.add list2 scanner.nextDouble() scanner.nextDouble scanner list.add(list2) list.add list list2 int squareNumCount = 0; squareNumCount 0 for(int i = 0 ; i< N ; i++){
            for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            }
        } int i = 0 ; int i = 0 ; i 0 i< N i N i++ i++ i {
            for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            }
        } {
            for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            }
        } for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            } int j = N-1; int j = N-1; j N-1 N 1 j> i j i j-- j-- j {
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            } {
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            } double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j)); squaredDistanse calSquaredDistanse(list.get(i),list.get(j)) calSquaredDistanse list.get(i) list.get list i list.get(j) list.get list j if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                } isSquareNum(squaredDistanse) isSquareNum squaredDistanse {
                    squareNumCount++;
                } squareNumCount++ squareNumCount System.out.println(squareNumCount) System.out.println System.out System System.out squareNumCount String[] args args private static boolean isSquareNum(double squaredDistanse) {
        for(int i=1; i<=Math.sqrt(squaredDistanse); i++){
            if(i*i == squaredDistanse) return true;
        }
        return false;
    } isSquareNum {
        for(int i=1; i<=Math.sqrt(squaredDistanse); i++){
            if(i*i == squaredDistanse) return true;
        }
        return false;
    } for(int i=1; i<=Math.sqrt(squaredDistanse); i++){
            if(i*i == squaredDistanse) return true;
        } int i=1; int i=1; i 1 i<=Math.sqrt(squaredDistanse) i Math.sqrt(squaredDistanse) Math.sqrt Math squaredDistanse i++ i++ i {
            if(i*i == squaredDistanse) return true;
        } {
            if(i*i == squaredDistanse) return true;
        } if(i*i == squaredDistanse) return true; i*i == squaredDistanse i*i i i squaredDistanse return true; true return false; false double squaredDistanse squaredDistanse private static double calSquaredDistanse(List<Double> integers, List<Double> integers1) {
        double sum = 0;
        for(int i=0; i < integers.size(); i++){
            double d = integers.get(i) - integers1.get(i);
//            sum = d>0 ? sum+d*d : sum-d;
            sum+=d*d;
        }
        return sum;
    } calSquaredDistanse {
        double sum = 0;
        for(int i=0; i < integers.size(); i++){
            double d = integers.get(i) - integers1.get(i);
//            sum = d>0 ? sum+d*d : sum-d;
            sum+=d*d;
        }
        return sum;
    } double sum = 0; sum 0 for(int i=0; i < integers.size(); i++){
            double d = integers.get(i) - integers1.get(i);
//            sum = d>0 ? sum+d*d : sum-d;
            sum+=d*d;
        } int i=0; int i=0; i 0 i < integers.size() i integers.size() integers.size integers i++ i++ i {
            double d = integers.get(i) - integers1.get(i);
//            sum = d>0 ? sum+d*d : sum-d;
            sum+=d*d;
        } {
            double d = integers.get(i) - integers1.get(i);
//            sum = d>0 ? sum+d*d : sum-d;
            sum+=d*d;
        } double d = integers.get(i) - integers1.get(i); d integers.get(i) - integers1.get(i) integers.get(i) integers.get integers i integers1.get(i) integers1.get integers1 i sum+=d*d sum d*d d d return sum; sum List<Double> integers integers List<Double> integers1 integers1 public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        List<List<Double>> list = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
            List<Double> list2 = new ArrayList<>();
            for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            }
            list.add(list2);
        }
        int squareNumCount = 0;
        for(int i = 0 ; i< N ; i++){
            for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            }
        }
        System.out.println(squareNumCount);
    }

    private static boolean isSquareNum(double squaredDistanse) {
        for(int i=1; i<=Math.sqrt(squaredDistanse); i++){
            if(i*i == squaredDistanse) return true;
        }
        return false;
    }

    private static double calSquaredDistanse(List<Double> integers, List<Double> integers1) {
        double sum = 0;
        for(int i=0; i < integers.size(); i++){
            double d = integers.get(i) - integers1.get(i);
//            sum = d>0 ? sum+d*d : sum-d;
            sum+=d*d;
        }
        return sum;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        List<List<Double>> list = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
            List<Double> list2 = new ArrayList<>();
            for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            }
            list.add(list2);
        }
        int squareNumCount = 0;
        for(int i = 0 ; i< N ; i++){
            for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            }
        }
        System.out.println(squareNumCount);
    }

    private static boolean isSquareNum(double squaredDistanse) {
        for(int i=1; i<=Math.sqrt(squaredDistanse); i++){
            if(i*i == squaredDistanse) return true;
        }
        return false;
    }

    private static double calSquaredDistanse(List<Double> integers, List<Double> integers1) {
        double sum = 0;
        for(int i=0; i < integers.size(); i++){
            double d = integers.get(i) - integers1.get(i);
//            sum = d>0 ? sum+d*d : sum-d;
            sum+=d*d;
        }
        return sum;
    }
} Main
//package Atcoder133;

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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        List<List<Double>> list = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
            List<Double> list2 = new ArrayList<>();
            for(int j = 0 ; j< D ; j++){
                list2.add(scanner.nextDouble());
            }
            list.add(list2);
        }
        int squareNumCount = 0;
        for(int i = 0 ; i< N ; i++){
            for(int j = N-1; j> i ; j--){
                double squaredDistanse = calSquaredDistanse(list.get(i),list.get(j));
                if(isSquareNum(squaredDistanse)){
                    squareNumCount++;
                }
            }
        }
        System.out.println(squareNumCount);
    }

    private static boolean isSquareNum(double squaredDistanse) {
        for(int i=1; i<=Math.sqrt(squaredDistanse); i++){
            if(i*i == squaredDistanse) return true;
        }
        return false;
    }

    private static double calSquaredDistanse(List<Double> integers, List<Double> integers1) {
        double sum = 0;
        for(int i=0; i < integers.size(); i++){
            double d = integers.get(i) - integers1.get(i);
//            sum = d>0 ? sum+d*d : sum-d;
            sum+=d*d;
        }
        return sum;
    }
}


//15hunn
