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

public class Main {

    public static void main(String[] args) {
	    // input N D \n x11 x12 ... x1d \n x21 x22 ... x2d
        Scanner sc = new Scanner(System.in);
        int numPoint = sc.nextInt();
        int numDim = sc.nextInt();
        int resTuppleNum = 0;
        ArrayList<ArrayList<Integer>> dimArrayList = new ArrayList<>();
        for(int i = 0; i < numPoint; i++){
            ArrayList<Integer> posArrayList = new ArrayList<>();
            for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            }
            dimArrayList.add(posArrayList);
        }
        for(int i = 0; i < numPoint; i++){
            for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            }
        }
        System.out.println(resTuppleNum);
    }

    public static boolean isRegularNum(String num){
        double regNum = Double.parseDouble(num.substring(0, num.indexOf(".")));
        if(String.valueOf(regNum).equals(num)){
            return true;
        } else {
            return false;
        }
    }
} import java.util.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util public class Main {

    public static void main(String[] args) {
	    // input N D \n x11 x12 ... x1d \n x21 x22 ... x2d
        Scanner sc = new Scanner(System.in);
        int numPoint = sc.nextInt();
        int numDim = sc.nextInt();
        int resTuppleNum = 0;
        ArrayList<ArrayList<Integer>> dimArrayList = new ArrayList<>();
        for(int i = 0; i < numPoint; i++){
            ArrayList<Integer> posArrayList = new ArrayList<>();
            for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            }
            dimArrayList.add(posArrayList);
        }
        for(int i = 0; i < numPoint; i++){
            for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            }
        }
        System.out.println(resTuppleNum);
    }

    public static boolean isRegularNum(String num){
        double regNum = Double.parseDouble(num.substring(0, num.indexOf(".")));
        if(String.valueOf(regNum).equals(num)){
            return true;
        } else {
            return false;
        }
    }
} Main public static void main(String[] args) {
	    // input N D \n x11 x12 ... x1d \n x21 x22 ... x2d
        Scanner sc = new Scanner(System.in);
        int numPoint = sc.nextInt();
        int numDim = sc.nextInt();
        int resTuppleNum = 0;
        ArrayList<ArrayList<Integer>> dimArrayList = new ArrayList<>();
        for(int i = 0; i < numPoint; i++){
            ArrayList<Integer> posArrayList = new ArrayList<>();
            for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            }
            dimArrayList.add(posArrayList);
        }
        for(int i = 0; i < numPoint; i++){
            for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            }
        }
        System.out.println(resTuppleNum);
    } main {
	    // input N D \n x11 x12 ... x1d \n x21 x22 ... x2d
        Scanner sc = new Scanner(System.in);
        int numPoint = sc.nextInt();
        int numDim = sc.nextInt();
        int resTuppleNum = 0;
        ArrayList<ArrayList<Integer>> dimArrayList = new ArrayList<>();
        for(int i = 0; i < numPoint; i++){
            ArrayList<Integer> posArrayList = new ArrayList<>();
            for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            }
            dimArrayList.add(posArrayList);
        }
        for(int i = 0; i < numPoint; i++){
            for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            }
        }
        System.out.println(resTuppleNum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int numPoint = sc.nextInt(); numPoint sc.nextInt() sc.nextInt sc int numDim = sc.nextInt(); numDim sc.nextInt() sc.nextInt sc int resTuppleNum = 0; resTuppleNum 0 ArrayList<ArrayList<Integer>> dimArrayList = new ArrayList<>(); dimArrayList new ArrayList<>() for(int i = 0; i < numPoint; i++){
            ArrayList<Integer> posArrayList = new ArrayList<>();
            for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            }
            dimArrayList.add(posArrayList);
        } int i = 0; int i = 0; i 0 i < numPoint i numPoint i++ i++ i {
            ArrayList<Integer> posArrayList = new ArrayList<>();
            for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            }
            dimArrayList.add(posArrayList);
        } {
            ArrayList<Integer> posArrayList = new ArrayList<>();
            for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            }
            dimArrayList.add(posArrayList);
        } ArrayList<Integer> posArrayList = new ArrayList<>(); posArrayList new ArrayList<>() for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            } int j = 0; int j = 0; j 0 j < numDim j numDim j++ j++ j {
                posArrayList.add(sc.nextInt());
            } {
                posArrayList.add(sc.nextInt());
            } posArrayList.add(sc.nextInt()) posArrayList.add posArrayList sc.nextInt() sc.nextInt sc dimArrayList.add(posArrayList) dimArrayList.add dimArrayList posArrayList for(int i = 0; i < numPoint; i++){
            for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            }
        } int i = 0; int i = 0; i 0 i < numPoint i numPoint i++ i++ i {
            for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            }
        } {
            for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            }
        } for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < numPoint j numPoint j++ j++ j {
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            } {
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            } double sumPointDistance = 0; sumPointDistance 0 for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                } int k = 0; int k = 0; k 0 k < numDim k numDim k++ k++ k {
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                } {
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                } sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2) sumPointDistance Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2) Math.pow Math dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k) dimArrayList.get(i).get(k) dimArrayList.get(i).get dimArrayList.get(i) dimArrayList.get dimArrayList i k dimArrayList.get(j).get(k) dimArrayList.get(j).get dimArrayList.get(j) dimArrayList.get dimArrayList j k 2 if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                } isRegularNum(String.valueOf(Math.sqrt(sumPointDistance))) isRegularNum String.valueOf(Math.sqrt(sumPointDistance)) String.valueOf String Math.sqrt(sumPointDistance) Math.sqrt Math sumPointDistance {
                    resTuppleNum++;
                } resTuppleNum++ resTuppleNum System.out.println(resTuppleNum) System.out.println System.out System System.out resTuppleNum String[] args args public static boolean isRegularNum(String num){
        double regNum = Double.parseDouble(num.substring(0, num.indexOf(".")));
        if(String.valueOf(regNum).equals(num)){
            return true;
        } else {
            return false;
        }
    } isRegularNum {
        double regNum = Double.parseDouble(num.substring(0, num.indexOf(".")));
        if(String.valueOf(regNum).equals(num)){
            return true;
        } else {
            return false;
        }
    } double regNum = Double.parseDouble(num.substring(0, num.indexOf("."))); regNum Double.parseDouble(num.substring(0, num.indexOf("."))) Double.parseDouble Double num.substring(0, num.indexOf(".")) num.substring num 0 num.indexOf(".") num.indexOf num "." if(String.valueOf(regNum).equals(num)){
            return true;
        } else {
            return false;
        } String.valueOf(regNum).equals(num) String.valueOf(regNum).equals String.valueOf(regNum) String.valueOf String regNum num {
            return true;
        } return true; true {
            return false;
        } return false; false String num num public class Main {

    public static void main(String[] args) {
	    // input N D \n x11 x12 ... x1d \n x21 x22 ... x2d
        Scanner sc = new Scanner(System.in);
        int numPoint = sc.nextInt();
        int numDim = sc.nextInt();
        int resTuppleNum = 0;
        ArrayList<ArrayList<Integer>> dimArrayList = new ArrayList<>();
        for(int i = 0; i < numPoint; i++){
            ArrayList<Integer> posArrayList = new ArrayList<>();
            for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            }
            dimArrayList.add(posArrayList);
        }
        for(int i = 0; i < numPoint; i++){
            for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            }
        }
        System.out.println(resTuppleNum);
    }

    public static boolean isRegularNum(String num){
        double regNum = Double.parseDouble(num.substring(0, num.indexOf(".")));
        if(String.valueOf(regNum).equals(num)){
            return true;
        } else {
            return false;
        }
    }
} public class Main {

    public static void main(String[] args) {
	    // input N D \n x11 x12 ... x1d \n x21 x22 ... x2d
        Scanner sc = new Scanner(System.in);
        int numPoint = sc.nextInt();
        int numDim = sc.nextInt();
        int resTuppleNum = 0;
        ArrayList<ArrayList<Integer>> dimArrayList = new ArrayList<>();
        for(int i = 0; i < numPoint; i++){
            ArrayList<Integer> posArrayList = new ArrayList<>();
            for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            }
            dimArrayList.add(posArrayList);
        }
        for(int i = 0; i < numPoint; i++){
            for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            }
        }
        System.out.println(resTuppleNum);
    }

    public static boolean isRegularNum(String num){
        double regNum = Double.parseDouble(num.substring(0, num.indexOf(".")));
        if(String.valueOf(regNum).equals(num)){
            return true;
        } else {
            return false;
        }
    }
} Main
import java.util.Scanner;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) {
	    // input N D \n x11 x12 ... x1d \n x21 x22 ... x2d
        Scanner sc = new Scanner(System.in);
        int numPoint = sc.nextInt();
        int numDim = sc.nextInt();
        int resTuppleNum = 0;
        ArrayList<ArrayList<Integer>> dimArrayList = new ArrayList<>();
        for(int i = 0; i < numPoint; i++){
            ArrayList<Integer> posArrayList = new ArrayList<>();
            for(int j = 0; j < numDim; j++){
                posArrayList.add(sc.nextInt());
            }
            dimArrayList.add(posArrayList);
        }
        for(int i = 0; i < numPoint; i++){
            for(int j = i + 1; j < numPoint; j++){
                double sumPointDistance = 0;
                for(int k = 0; k < numDim; k++){
                    sumPointDistance += Math.pow(dimArrayList.get(i).get(k) - dimArrayList.get(j).get(k), 2);
                }
                if(isRegularNum(String.valueOf(Math.sqrt(sumPointDistance)))){
                    resTuppleNum++;
                }
            }
        }
        System.out.println(resTuppleNum);
    }

    public static boolean isRegularNum(String num){
        double regNum = Double.parseDouble(num.substring(0, num.indexOf(".")));
        if(String.valueOf(regNum).equals(num)){
            return true;
        } else {
            return false;
        }
    }
}
