import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] ins = sc.nextLine().split(" ");
        int n = Integer.parseInt(ins[0]);
        int d = Integer.parseInt(ins[1]);
        List<List<Integer>> locations = new ArrayList<>();
        for(int i = 0;i < n;i++){
            String[] locs = sc.nextLine().split(" ");
            List<Integer> loc1 = new ArrayList<>();
            for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            }
            locations.add(loc1);
        }
        int r = 0;
        for(int i = 0;i < locations.size();i++){
            for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            }
        }
        System.out.println(r);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] ins = sc.nextLine().split(" ");
        int n = Integer.parseInt(ins[0]);
        int d = Integer.parseInt(ins[1]);
        List<List<Integer>> locations = new ArrayList<>();
        for(int i = 0;i < n;i++){
            String[] locs = sc.nextLine().split(" ");
            List<Integer> loc1 = new ArrayList<>();
            for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            }
            locations.add(loc1);
        }
        int r = 0;
        for(int i = 0;i < locations.size();i++){
            for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            }
        }
        System.out.println(r);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] ins = sc.nextLine().split(" ");
        int n = Integer.parseInt(ins[0]);
        int d = Integer.parseInt(ins[1]);
        List<List<Integer>> locations = new ArrayList<>();
        for(int i = 0;i < n;i++){
            String[] locs = sc.nextLine().split(" ");
            List<Integer> loc1 = new ArrayList<>();
            for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            }
            locations.add(loc1);
        }
        int r = 0;
        for(int i = 0;i < locations.size();i++){
            for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            }
        }
        System.out.println(r);
    } main {
        Scanner sc = new Scanner(System.in);
        String[] ins = sc.nextLine().split(" ");
        int n = Integer.parseInt(ins[0]);
        int d = Integer.parseInt(ins[1]);
        List<List<Integer>> locations = new ArrayList<>();
        for(int i = 0;i < n;i++){
            String[] locs = sc.nextLine().split(" ");
            List<Integer> loc1 = new ArrayList<>();
            for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            }
            locations.add(loc1);
        }
        int r = 0;
        for(int i = 0;i < locations.size();i++){
            for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            }
        }
        System.out.println(r);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] ins = sc.nextLine().split(" "); ins sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int n = Integer.parseInt(ins[0]); n Integer.parseInt(ins[0]) Integer.parseInt Integer ins[0] ins 0 int d = Integer.parseInt(ins[1]); d Integer.parseInt(ins[1]) Integer.parseInt Integer ins[1] ins 1 List<List<Integer>> locations = new ArrayList<>(); locations new ArrayList<>() for(int i = 0;i < n;i++){
            String[] locs = sc.nextLine().split(" ");
            List<Integer> loc1 = new ArrayList<>();
            for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            }
            locations.add(loc1);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            String[] locs = sc.nextLine().split(" ");
            List<Integer> loc1 = new ArrayList<>();
            for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            }
            locations.add(loc1);
        } {
            String[] locs = sc.nextLine().split(" ");
            List<Integer> loc1 = new ArrayList<>();
            for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            }
            locations.add(loc1);
        } String[] locs = sc.nextLine().split(" "); locs sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " List<Integer> loc1 = new ArrayList<>(); loc1 new ArrayList<>() for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            } String loc locs {
                loc1.add(Integer.parseInt(loc));
            } {
                loc1.add(Integer.parseInt(loc));
            } loc1.add(Integer.parseInt(loc)) loc1.add loc1 Integer.parseInt(loc) Integer.parseInt Integer loc locations.add(loc1) locations.add locations loc1 int r = 0; r 0 for(int i = 0;i < locations.size();i++){
            for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            }
        } int i = 0; int i = 0; i 0 i < locations.size() i locations.size() locations.size locations i++ i++ i {
            for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            }
        } {
            for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            }
        } for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            } int j = i; int j = i; j i j < locations.size() j locations.size() locations.size locations j++ j++ j {
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            } {
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            } double calc = 0; calc 0 for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                } {
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                } double o = locations.get(i).get(k) - locations.get(j).get(k); o locations.get(i).get(k) - locations.get(j).get(k) locations.get(i).get(k) locations.get(i).get locations.get(i) locations.get locations i k locations.get(j).get(k) locations.get(j).get locations.get(j) locations.get locations j k calc += o * o calc o * o o o calc = Math.sqrt(calc) calc Math.sqrt(calc) Math.sqrt Math calc if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                } (calc == Math.floor(calc)) && calc != 0 (calc == Math.floor(calc)) calc Math.floor(calc) Math.floor Math calc calc != 0 calc 0 {
                    r++;
                } r++ r System.out.println(r) System.out.println System.out System System.out r String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] ins = sc.nextLine().split(" ");
        int n = Integer.parseInt(ins[0]);
        int d = Integer.parseInt(ins[1]);
        List<List<Integer>> locations = new ArrayList<>();
        for(int i = 0;i < n;i++){
            String[] locs = sc.nextLine().split(" ");
            List<Integer> loc1 = new ArrayList<>();
            for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            }
            locations.add(loc1);
        }
        int r = 0;
        for(int i = 0;i < locations.size();i++){
            for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            }
        }
        System.out.println(r);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] ins = sc.nextLine().split(" ");
        int n = Integer.parseInt(ins[0]);
        int d = Integer.parseInt(ins[1]);
        List<List<Integer>> locations = new ArrayList<>();
        for(int i = 0;i < n;i++){
            String[] locs = sc.nextLine().split(" ");
            List<Integer> loc1 = new ArrayList<>();
            for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            }
            locations.add(loc1);
        }
        int r = 0;
        for(int i = 0;i < locations.size();i++){
            for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            }
        }
        System.out.println(r);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] ins = sc.nextLine().split(" ");
        int n = Integer.parseInt(ins[0]);
        int d = Integer.parseInt(ins[1]);
        List<List<Integer>> locations = new ArrayList<>();
        for(int i = 0;i < n;i++){
            String[] locs = sc.nextLine().split(" ");
            List<Integer> loc1 = new ArrayList<>();
            for(String loc : locs){
                loc1.add(Integer.parseInt(loc));
            }
            locations.add(loc1);
        }
        int r = 0;
        for(int i = 0;i < locations.size();i++){
            for(int j = i; j < locations.size();j++){
                double calc = 0;
                for(int k = 0;k < d;k++){
                    double o = locations.get(i).get(k) - locations.get(j).get(k);
                    calc += o * o;
                }
                calc = Math.sqrt(calc);
                if ((calc == Math.floor(calc)) && calc != 0) {
                    r++;
                }
            }
        }
        System.out.println(r);
    }
}